aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-09-09 23:23:39 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-09-09 23:23:39 +1200
commitc45a87a86e0a0a0551ebcec5e11fed37b7200074 (patch)
tree87dfb8f42fae0c2d516d22dcf595fe1b97659df9 /src/org/traccar/http
parenta4564a4071ccd258d7db6c3693c25f85600fa450 (diff)
downloadtraccar-server-c45a87a86e0a0a0551ebcec5e11fed37b7200074.tar.gz
traccar-server-c45a87a86e0a0a0551ebcec5e11fed37b7200074.tar.bz2
traccar-server-c45a87a86e0a0a0551ebcec5e11fed37b7200074.zip
Load DataSource from jar
Diffstat (limited to 'src/org/traccar/http')
-rw-r--r--src/org/traccar/http/WebServer.java45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java
index 4afd4ed7a..0fd5b952e 100644
--- a/src/org/traccar/http/WebServer.java
+++ b/src/org/traccar/http/WebServer.java
@@ -15,29 +15,17 @@
*/
package org.traccar.http;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
+import java.io.File;
import java.net.InetSocketAddress;
-import java.util.Iterator;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
-import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.webapp.WebAppContext;
import org.traccar.helper.Log;
-import org.traccar.model.DataManager;
-import org.traccar.model.Device;
-import org.traccar.model.Position;
/**
* Integrated HTTP server
@@ -51,14 +39,29 @@ public class WebServer {
Context context = new InitialContext();
- Class clazz = Class.forName(properties.getProperty("database.dataSource"));
+ String dataSourceClass = properties.getProperty("database.dataSource");
+ if (dataSourceClass != null) {
- DataSource ds = (DataSource) clazz.newInstance();
- clazz.getMethod("setURL", String.class).invoke(ds, properties.getProperty("database.url"));
- clazz.getMethod("setUser", String.class).invoke(ds, properties.getProperty("database.user"));
- clazz.getMethod("setPassword", String.class).invoke(ds, properties.getProperty("database.password"));
+ Class clazz;
+
+ String driverFile = properties.getProperty("database.driverFile");
+ if (driverFile != null) {
+ URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/");
+ URLClassLoader cl = new URLClassLoader(new URL[] { url });
+ clazz = Class.forName(dataSourceClass, true, cl);
+ } else {
+ clazz = Class.forName(dataSourceClass);
+ }
+
+ if (clazz != null) {
+ DataSource ds = (DataSource) clazz.newInstance();
+ clazz.getMethod("setUrl", String.class).invoke(ds, properties.getProperty("database.url"));
+ clazz.getMethod("setUser", String.class).invoke(ds, properties.getProperty("database.user"));
+ clazz.getMethod("setPassword", String.class).invoke(ds, properties.getProperty("database.password"));
- context.bind("java:/DefaultDS", ds);
+ context.bind("java:/DefaultDS", ds);
+ }
+ }
} catch (Exception error) {
Log.warning(error);