lib/logstash/plugin_mixins/jdbc/jdbc.rb in logstash-input-jdbc-4.3.17 vs lib/logstash/plugin_mixins/jdbc/jdbc.rb in logstash-input-jdbc-4.3.18
- old
+ new
@@ -138,33 +138,23 @@
end
end
private
- def load_drivers
- return if @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
-
- driver_jars = @jdbc_driver_library.split(",")
-
- # Needed for JDK 11 as the DriverManager has a different ClassLoader than Logstash
- urls = java.net.URL[driver_jars.length].new
-
- driver_jars.each_with_index do |driver, idx|
- urls[idx] = java.io.File.new(driver).toURI().toURL()
+ def load_driver_jars
+ unless @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
+ @jdbc_driver_library.split(",").each do |driver_jar|
+ begin
+ @logger.debug("loading #{driver_jar}")
+ # Use https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files to make classes from jar
+ # available
+ require driver_jar
+ rescue LoadError => e
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
+ end
+ end
end
- ucl = java.net.URLClassLoader.new_instance(urls)
- begin
- klass = java.lang.Class.forName(@jdbc_driver_class.to_java(:string), true, ucl);
- rescue Java::JavaLang::ClassNotFoundException => e
- raise LogStash::Error, "Unable to find driver class via URLClassLoader in given driver jars: #{@jdbc_driver_class}"
- end
- begin
- driver = klass.getConstructor().newInstance();
- java.sql.DriverManager.register_driver(WrappedDriver.new(driver.to_java(java.sql.Driver)).to_java(java.sql.Driver))
- rescue Java::JavaSql::SQLException => e
- raise LogStash::Error, "Unable to register driver with java.sql.DriverManager using WrappedDriver: #{@jdbc_driver_class}"
- end
end
private
def open_jdbc_connection
require "java"
@@ -172,10 +162,10 @@
require "sequel/adapters/jdbc"
Sequel.application_timezone = @plugin_timezone.to_sym
if @drivers_loaded.false?
begin
- load_drivers
+ load_driver_jars
Sequel::JDBC.load_driver(@jdbc_driver_class)
rescue LogStash::Error => e
# raised in load_drivers, e.cause should be the caught Java exceptions
raise LogStash::PluginLoadingError, "#{e.message} and #{e.cause.message}"
rescue Sequel::AdapterNotFound => e