diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-10-09 13:24:47 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-10-09 13:24:47 +1300 |
commit | 4f5f815f88e81000510ef2544e3e392fd7465d8e (patch) | |
tree | 3e36831dacd62eb36242973517ff41fa069b272a /src/org/traccar/http/WebServer.java | |
parent | 21d69f45cd5badf52e175fc234c5c7bd3c2aeb35 (diff) | |
download | trackermap-server-4f5f815f88e81000510ef2544e3e392fd7465d8e.tar.gz trackermap-server-4f5f815f88e81000510ef2544e3e392fd7465d8e.tar.bz2 trackermap-server-4f5f815f88e81000510ef2544e3e392fd7465d8e.zip |
Integrate c3p0 database library
Diffstat (limited to 'src/org/traccar/http/WebServer.java')
-rw-r--r-- | src/org/traccar/http/WebServer.java | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 2745cd7b8..9a7cb9e4e 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package org.traccar.http; -import java.io.File; import java.net.InetSocketAddress; -import java.net.URL; -import java.net.URLClassLoader; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; @@ -34,41 +31,7 @@ public class WebServer { private Server server; - private void initDataSource(Properties properties) { - try { - - Context context = new InitialContext(); - - String dataSourceClass = properties.getProperty("database.dataSource"); - if (dataSourceClass != null) { - - 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); - } - } - - } catch (Exception error) { - Log.warning(error); - } - } - - public WebServer(Properties properties) { + public WebServer(Properties properties, DataSource dataSource) { String address = properties.getProperty("http.address"); Integer port = Integer.valueOf(properties.getProperty("http.port", "8082")); if (address == null) { @@ -77,7 +40,12 @@ public class WebServer { server = new Server(new InetSocketAddress(address, port)); } - initDataSource(properties); + try { + Context context = new InitialContext(); + context.bind("java:/DefaultDS", dataSource); + } catch (Exception error) { + Log.warning(error); + } WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); |