diff --git a/WebContent/conf/Spiracle.properties b/WebContent/conf/Spiracle.properties index 0c74292..b4e00bf 100644 --- a/WebContent/conf/Spiracle.properties +++ b/WebContent/conf/Spiracle.properties @@ -9,14 +9,23 @@ java.url=jdbc:oracle:thin:@localhost:1521:XE java.username=test java.password=test +jdbc.fetchsize=25 + spring.path=/path/to/spring-context.xml application.loggingEnabled=True -# Log4j Configuration ## +#Log4j Configuration ## log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=[%p] [%d{ISO8601}] [%F:%L] [%m]%n \ No newline at end of file +log4j.appender.stdout.layout.ConversionPattern=[%p] [%d{ISO8601}] [%F:%L] [%m]%n + +#log4j.rootLogger=DEBUG, FILE +# +#log4j.appender.FILE=org.apache.log4j.FileAppender +#log4j.appender.FILE.File=/tmp/spiracle.log +#log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +#log4j.appender.FILE.layout.ConversionPattern=[%p] [%d{ISO8601}] [%F:%L] [%m]%n \ No newline at end of file diff --git a/src/com/waratek/spiracle/file/FileServlet.java b/src/com/waratek/spiracle/file/FileServlet.java index 2d7ecbe..022507b 100644 --- a/src/com/waratek/spiracle/file/FileServlet.java +++ b/src/com/waratek/spiracle/file/FileServlet.java @@ -36,79 +36,90 @@ @WebServlet("/FileServlet") public class FileServlet extends HttpServlet { private static final Logger logger = Logger.getLogger(FileServlet.class); - private static final long serialVersionUID = 1L; - - /** - * @see HttpServlet#HttpServlet() - */ - public FileServlet() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } - - private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { - HttpSession session = request.getSession(); - - String method = request.getParameter("fileArg"); - String path = request.getParameter("filePath"); - String textData = request.getParameter("fileText"); - - if(method.equals("read")) { - session.setAttribute("fileContents", readFile(path)); - - } else if(method.equals("write")) { - File f = new File(path); - FileWriter fw = new FileWriter(f); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(textData); - bw.close(); - fw.close(); - - session.setAttribute("fileContents", readFile(path)); - - } else if(method.equals("delete")) { - File f = new File(path); - f.delete(); - session.setAttribute("fileContents", ""); - } + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public FileServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } + + private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + + String method = request.getParameter("fileArg"); + String path = request.getParameter("filePath"); + String textData = request.getParameter("fileText"); + + if(method.equals("read")) { + read(session, path); + } else if(method.equals("write")) { + write(session, path, textData); + } else if(method.equals("delete")) { + delete(session, path); + } logger.info(method + " " + path + " " + textData); - response.sendRedirect("file.jsp"); - } - - private String readFile(String pathname) { - try { - File file = new File(pathname); - StringBuilder fileContents = new StringBuilder((int)file.length()); - Scanner scanner = new Scanner(file); - String lineSeparator = System.getProperty("line.separator"); - - try { - while(scanner.hasNextLine()) { - fileContents.append(scanner.nextLine() + lineSeparator); - } - return fileContents.toString(); - } finally { - scanner.close(); - } - } catch (IOException e) { - e.printStackTrace(); - return e.getMessage(); - } - } + response.sendRedirect("file.jsp"); + } + + private void delete(HttpSession session, String path) { + File f = new File(path); + f.delete(); + session.setAttribute("fileContents", ""); + } + + private void read(HttpSession session, String path) { + session.setAttribute("fileContents", readFile(path)); + } + + private void write(HttpSession session, String path, String textData) + throws IOException { + File f = new File(path); + FileWriter fw = new FileWriter(f); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(textData); + bw.close(); + fw.close(); + + read(session, path); + } + + private String readFile(String pathname) { + try { + File file = new File(pathname); + StringBuilder fileContents = new StringBuilder((int)file.length()); + Scanner scanner = new Scanner(file); + String lineSeparator = System.getProperty("line.separator"); + + try { + while(scanner.hasNextLine()) { + fileContents.append(scanner.nextLine() + lineSeparator); + } + return fileContents.toString(); + } finally { + scanner.close(); + } + } catch (IOException e) { + e.printStackTrace(); + return e.getMessage(); + } + } } diff --git a/src/com/waratek/spiracle/init/SpiracleInit.java b/src/com/waratek/spiracle/init/SpiracleInit.java index a54b248..008088f 100644 --- a/src/com/waratek/spiracle/init/SpiracleInit.java +++ b/src/com/waratek/spiracle/init/SpiracleInit.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Properties; - import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -48,8 +47,10 @@ public void contextInitialized(ServletContextEvent arg0) { ServletContext application = arg0.getServletContext(); Properties props = loadProperties(application); loadLog4jConfig(props); + logServerInfo(application); ComboPooledDataSource ds = getConnectionPool(props); setConnectionPool(application, ds); + setFetchSize(application, props); } private Properties loadProperties(ServletContext application) { @@ -113,4 +114,20 @@ private ComboPooledDataSource getConnectionPool(Properties props) { ds.setMaxPoolSize(maxPoolSize); return ds; } + + private void setFetchSize(ServletContext application, Properties props) { + int fetchSize = 0; + try { + fetchSize = Integer.parseInt(props.getProperty("jdbc.fetchsize")); + application.setAttribute("fetchSize", fetchSize); + logger.info("Set jdbc.fetchsize to (" + fetchSize + ")"); + } catch (NumberFormatException e) { + logger.error("jdbc.fetchsize not specified, default value set(10)."); + } + } + + void logServerInfo(ServletContext application) { + logger.info("Application Server Name: " + application.getServerInfo()); + logger.info("Application Context Path:" + application.getRealPath("")); + } } diff --git a/src/com/waratek/spiracle/network/ServerSocketServlet.java b/src/com/waratek/spiracle/network/ServerSocketServlet.java index 205e86d..5d8d12b 100644 --- a/src/com/waratek/spiracle/network/ServerSocketServlet.java +++ b/src/com/waratek/spiracle/network/ServerSocketServlet.java @@ -32,62 +32,62 @@ */ @WebServlet("/ServerSocketServlet") public class ServerSocketServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - private static ServerSocket ss; - private static Socket s; - - /** - * @see HttpServlet#HttpServlet() - */ - public ServerSocketServlet() { - super(); - // TODO Auto-generated constructor stub - } + private static final long serialVersionUID = 1L; + private static ServerSocket ss; + private static Socket s; - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } + /** + * @see HttpServlet#HttpServlet() + */ + public ServerSocketServlet() { + super(); + // TODO Auto-generated constructor stub + } - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } - private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { - if(ss != null && s != null) { - ss.close(); - s.close(); - } - - HttpSession session = request.getSession(); - try { - String addr = request.getParameter("hostname"); - int port = Integer.parseInt(request.getParameter("port")); - if(addr == null) { - ss = new ServerSocket(port); - } else { - ss = new ServerSocket(); - ss.bind(new InetSocketAddress(addr, port)); - } - ss.setSoTimeout(20000); - s = ss.accept(); - session.setAttribute("serverSocketInfo", ss.toString()); - response.sendRedirect("network.jsp"); - - } catch (Throwable e) { - if(ss != null) { - ss.close(); - s.close(); - } - e.printStackTrace(); - session.setAttribute("serverSocketInfo", e.getMessage()); - response.sendRedirect("network.jsp"); - } - } + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } + + private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + if(ss != null && s != null) { + ss.close(); + s.close(); + } + + HttpSession session = request.getSession(); + try { + String addr = request.getParameter("hostname"); + int port = Integer.parseInt(request.getParameter("port")); + if(addr == null) { + ss = new ServerSocket(port); + } else { + ss = new ServerSocket(); + ss.bind(new InetSocketAddress(addr, port)); + } + ss.setSoTimeout(20000); + s = ss.accept(); + session.setAttribute("serverSocketInfo", ss.toString()); + response.sendRedirect("network.jsp"); + + } catch (Throwable e) { + if(ss != null) { + ss.close(); + s.close(); + } + e.printStackTrace(); + session.setAttribute("serverSocketInfo", e.getMessage()); + response.sendRedirect("network.jsp"); + } + } } diff --git a/src/com/waratek/spiracle/network/ServerSocketThread.java b/src/com/waratek/spiracle/network/ServerSocketThread.java index c284066..9ada953 100644 --- a/src/com/waratek/spiracle/network/ServerSocketThread.java +++ b/src/com/waratek/spiracle/network/ServerSocketThread.java @@ -21,34 +21,34 @@ public class ServerSocketThread extends Thread { - private ServerSocket s; - public ServerSocketThread(int port) throws IOException { - super(); - s = new ServerSocket(port); - } + private ServerSocket s; + public ServerSocketThread(int port) throws IOException { + super(); + s = new ServerSocket(port); + } - public String toString() { - return s.toString(); - } + public String toString() { + return s.toString(); + } - public void run() { - Socket sock = null; - do { - try { - sock = s.accept(); - while(!this.isInterrupted()) { - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } while(!this.isInterrupted()); - try { - sock.close(); - s.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void run() { + Socket sock = null; + do { + try { + sock = s.accept(); + while(!this.isInterrupted()) { + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } while(!this.isInterrupted()); + try { + sock.close(); + s.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/src/com/waratek/spiracle/network/SocketServlet.java b/src/com/waratek/spiracle/network/SocketServlet.java index a4829c8..e49803a 100644 --- a/src/com/waratek/spiracle/network/SocketServlet.java +++ b/src/com/waratek/spiracle/network/SocketServlet.java @@ -31,78 +31,78 @@ */ @WebServlet("/SocketServlet") public class SocketServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - private static Socket s; - - /** - * @see HttpServlet#HttpServlet() - */ - public SocketServlet() { - super(); - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } - - /** - * @throws IOException - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } - - private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { - if(s != null) { - s.close(); - } - - HttpSession session = request.getSession(); - try { - String bindHost = request.getParameter("bindHost"); - String remoteHost = request.getParameter("remoteHost"); - - Integer bindPort = 0; - Integer remotePort = 0; - - String bindPortRaw = request.getParameter("bindPort"); - String remotePortRaw = request.getParameter("remotePort"); - - if(bindPortRaw.length() > 0) { - bindPort = Integer.parseInt((String)bindPortRaw); - } else { - bindPort = null; - } - if(remotePortRaw.length() > 0) { - remotePort = Integer.parseInt((String)remotePortRaw); - } else { - remotePort = null; - } - - s = new Socket(); - if(bindHost.length() == 0 || bindHost.length() == 0) { - s.bind(null); - } else { - s.bind(new InetSocketAddress(bindHost, bindPort.intValue())); - } - - s.connect(new InetSocketAddress(remoteHost, remotePort.intValue())); - session.setAttribute("socketInfo", s.toString()); - - response.sendRedirect("network.jsp"); - } catch (Throwable e) { - if(s != null) { - s.close(); - } - e.printStackTrace(); - session.setAttribute("socketInfo", e.getMessage()); - response.sendRedirect("network.jsp"); - - } - } + private static final long serialVersionUID = 1L; + private static Socket s; + + /** + * @see HttpServlet#HttpServlet() + */ + public SocketServlet() { + super(); + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } + + /** + * @throws IOException + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } + + private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + if(s != null) { + s.close(); + } + + HttpSession session = request.getSession(); + try { + String bindHost = request.getParameter("bindHost"); + String remoteHost = request.getParameter("remoteHost"); + + Integer bindPort = 0; + Integer remotePort = 0; + + String bindPortRaw = request.getParameter("bindPort"); + String remotePortRaw = request.getParameter("remotePort"); + + if(bindPortRaw.length() > 0) { + bindPort = Integer.parseInt((String)bindPortRaw); + } else { + bindPort = null; + } + if(remotePortRaw.length() > 0) { + remotePort = Integer.parseInt((String)remotePortRaw); + } else { + remotePort = null; + } + + s = new Socket(); + if(bindHost.length() == 0 || bindHost.length() == 0) { + s.bind(null); + } else { + s.bind(new InetSocketAddress(bindHost, bindPort.intValue())); + } + + s.connect(new InetSocketAddress(remoteHost, remotePort.intValue())); + session.setAttribute("socketInfo", s.toString()); + + response.sendRedirect("network.jsp"); + } catch (Throwable e) { + if(s != null) { + s.close(); + } + e.printStackTrace(); + session.setAttribute("socketInfo", e.getMessage()); + response.sendRedirect("network.jsp"); + + } + } } diff --git a/src/com/waratek/spiracle/network/UrlServlet.java b/src/com/waratek/spiracle/network/UrlServlet.java index cd60fc5..8d14057 100644 --- a/src/com/waratek/spiracle/network/UrlServlet.java +++ b/src/com/waratek/spiracle/network/UrlServlet.java @@ -34,61 +34,60 @@ */ @WebServlet("/UrlServlet") public class UrlServlet extends HttpServlet { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * @see HttpServlet#HttpServlet() - */ - public UrlServlet() { - super(); - // TODO Auto-generated constructor stub - } + /** + * @see HttpServlet#HttpServlet() + */ + public UrlServlet() { + super(); + // TODO Auto-generated constructor stub + } - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - executeRequest(request, response); - } + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + executeRequest(request, response); + } - private void executeRequest(HttpServletRequest request, - HttpServletResponse response) throws IOException { - HttpSession session = request.getSession(); - String urlPath = request.getParameter("urlPath"); + private void executeRequest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + String urlPath = request.getParameter("urlPath"); - session.setAttribute("urlContents", readUrl(urlPath)); - response.sendRedirect("network.jsp"); - } + session.setAttribute("urlContents", readUrl(urlPath)); + response.sendRedirect("network.jsp"); + } - private String readUrl(String pathname) throws IOException { - try { - URLConnection con = new URL(pathname).openConnection(); - Scanner scanner = new Scanner(con.getInputStream()); - StringBuilder fileContents = new StringBuilder(); - String lineSeparator = System.getProperty("line.separator"); + private String readUrl(String pathname) throws IOException { + try { + URLConnection con = new URL(pathname).openConnection(); + Scanner scanner = new Scanner(con.getInputStream()); + StringBuilder fileContents = new StringBuilder(); + String lineSeparator = System.getProperty("line.separator"); - try { - while(scanner.hasNextLine()) { - fileContents.append(scanner.nextLine() + lineSeparator); - } - return fileContents.toString(); - } finally { - scanner.close(); - } - } catch (MalformedURLException e) { - e.printStackTrace(); - return "Please enter a valid URL"; - } catch (UnknownHostException e) { - e.printStackTrace(); - return "Please enter a valid URL"; - } - - } + try { + while(scanner.hasNextLine()) { + fileContents.append(scanner.nextLine() + lineSeparator); + } + return fileContents.toString(); + } finally { + scanner.close(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + return "Please enter a valid URL"; + } catch (UnknownHostException e) { + e.printStackTrace(); + return "Please enter a valid URL"; + } + } } diff --git a/src/com/waratek/spiracle/sql/c3p0/CreateC3p0Connection.java b/src/com/waratek/spiracle/sql/c3p0/CreateC3p0Connection.java index dd869e6..f8439b8 100644 --- a/src/com/waratek/spiracle/sql/c3p0/CreateC3p0Connection.java +++ b/src/com/waratek/spiracle/sql/c3p0/CreateC3p0Connection.java @@ -36,96 +36,95 @@ */ @WebServlet("/CreateC3p0Connection") public class CreateC3p0Connection extends HttpServlet { - private static final long serialVersionUID = 1L; - - private String jdbcDriver; - private String url; - private String username; - private String password; - private int maxPoolSize; - - /** - * @see HttpServlet#HttpServlet() - */ - public CreateC3p0Connection() { - super(); - // TODO Auto-generated constructor stub - } - - public void init() { - ServletContext application = this.getServletConfig().getServletContext(); - InputStream propStream = application.getResourceAsStream("conf/Spiracle.properties"); - Properties prop = new Properties(); - try { - prop.load(propStream); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - jdbcDriver = prop.getProperty("c3p0.classname"); - url = prop.getProperty("c3p0.url"); - username = prop.getProperty("c3p0.username"); - password = prop.getProperty("c3p0.password"); - try { - maxPoolSize = Integer.parseInt(prop.getProperty("c3p0.maxPoolSize")); - } catch (NumberFormatException e) { - maxPoolSize = 25; - } - - } - - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - setupConnectionPool(request, response); - } - - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - setupConnectionPool(request, response); - } - - private void setupConnectionPool(HttpServletRequest request, HttpServletResponse response) throws IOException { - HttpSession session = request.getSession(); - if(request.getParameter("connectionUrl") == null || request.getParameter("username") == null || request.getParameter("password") == null) { - - } else { - url = request.getParameter("connectionUrl"); - username = request.getParameter("username"); - password = request.getParameter("password"); - } - - try { - ComboPooledDataSource ds = createConnectionPool(); - - ServletContext application = this.getServletConfig().getServletContext(); - application.setAttribute("connectionPool", ds); - application.setAttribute("connectionData", ds.toString()); - response.sendRedirect("sql.jsp"); - } catch (PropertyVetoException e) { - e.printStackTrace(); - session.setAttribute("error", e.getMessage()); - response.sendRedirect("sql.jsp"); - } - } - - private ComboPooledDataSource createConnectionPool() throws PropertyVetoException { - ComboPooledDataSource ds = new ComboPooledDataSource(); - - ds.setDriverClass(jdbcDriver); - ds.setJdbcUrl(url); - ds.setUser(username); - ds.setPassword(password); - ds.setMinPoolSize(5); - ds.setAcquireIncrement(5); - ds.setMaxPoolSize(maxPoolSize); - - return ds; - } + private static final long serialVersionUID = 1L; + + private String jdbcDriver; + private String url; + private String username; + private String password; + private int maxPoolSize; + + /** + * @see HttpServlet#HttpServlet() + */ + public CreateC3p0Connection() { + super(); + // TODO Auto-generated constructor stub + } + + public void init() { + ServletContext application = this.getServletConfig().getServletContext(); + InputStream propStream = application.getResourceAsStream("conf/Spiracle.properties"); + Properties prop = new Properties(); + try { + prop.load(propStream); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + jdbcDriver = prop.getProperty("c3p0.classname"); + url = prop.getProperty("c3p0.url"); + username = prop.getProperty("c3p0.username"); + password = prop.getProperty("c3p0.password"); + try { + maxPoolSize = Integer.parseInt(prop.getProperty("c3p0.maxPoolSize")); + } catch (NumberFormatException e) { + maxPoolSize = 25; + } + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + setupConnectionPool(request, response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + setupConnectionPool(request, response); + } + + private void setupConnectionPool(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + if(request.getParameter("connectionUrl") == null || request.getParameter("username") == null || request.getParameter("password") == null) { + + } else { + url = request.getParameter("connectionUrl"); + username = request.getParameter("username"); + password = request.getParameter("password"); + } + + try { + ComboPooledDataSource ds = createConnectionPool(); + + ServletContext application = this.getServletConfig().getServletContext(); + application.setAttribute("connectionPool", ds); + application.setAttribute("connectionData", ds.toString()); + response.sendRedirect("sql.jsp"); + } catch (PropertyVetoException e) { + e.printStackTrace(); + session.setAttribute("error", e.getMessage()); + response.sendRedirect("sql.jsp"); + } + } + + private ComboPooledDataSource createConnectionPool() throws PropertyVetoException { + ComboPooledDataSource ds = new ComboPooledDataSource(); + + ds.setDriverClass(jdbcDriver); + ds.setJdbcUrl(url); + ds.setUser(username); + ds.setPassword(password); + ds.setMinPoolSize(5); + ds.setAcquireIncrement(5); + ds.setMaxPoolSize(maxPoolSize); + + return ds; + } } diff --git a/src/com/waratek/spiracle/sql/java/CreateJavaConnection.java b/src/com/waratek/spiracle/sql/java/CreateJavaConnection.java index 56c380a..81c7d73 100644 --- a/src/com/waratek/spiracle/sql/java/CreateJavaConnection.java +++ b/src/com/waratek/spiracle/sql/java/CreateJavaConnection.java @@ -36,82 +36,83 @@ */ @WebServlet("/CreateJavaConnection") public class CreateJavaConnection extends HttpServlet { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private String jdbcDriver; - private String url; - private String username; - private String password; - /** - * @see HttpServlet#HttpServlet() - */ - public CreateJavaConnection() { - super(); - // TODO Auto-generated constructor stub - } - - public void init() { - ServletContext application = this.getServletConfig().getServletContext(); - InputStream propStream = application.getResourceAsStream("conf/Spriacle.properties"); - Properties prop = new Properties(); - try { - prop.load(propStream); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - jdbcDriver = prop.getProperty("java.classname"); - url = prop.getProperty("java.url"); - username = prop.getProperty("java.username"); - password = prop.getProperty("java.password"); - } + private String jdbcDriver; + private String url; + private String username; + private String password; - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - createConnection(request, response); - } + /** + * @see HttpServlet#HttpServlet() + */ + public CreateJavaConnection() { + super(); + // TODO Auto-generated constructor stub + } - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - createConnection(request, response); - } + public void init() { + ServletContext application = this.getServletConfig().getServletContext(); + InputStream propStream = application.getResourceAsStream("conf/Spriacle.properties"); + Properties prop = new Properties(); + try { + prop.load(propStream); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + jdbcDriver = prop.getProperty("java.classname"); + url = prop.getProperty("java.url"); + username = prop.getProperty("java.username"); + password = prop.getProperty("java.password"); + } - private void createConnection(HttpServletRequest request, HttpServletResponse response) throws IOException { - HttpSession session = request.getSession(); - if(request.getParameter("connectionUrl") == null || request.getParameter("username") == null || request.getParameter("password") == null) { - - } else { - url = request.getParameter("connectionUrl"); - username = request.getParameter("username"); - password = request.getParameter("password"); - } - try { - Connection con = createJavaConnection(); - ServletContext application = this.getServletConfig().getServletContext(); - application.setAttribute("unpooledConnection", con); - session.setAttribute("connectionDataJava", con.toString()); - response.sendRedirect("sql.jsp"); - } catch(ClassNotFoundException e) { - e.printStackTrace(); - session.setAttribute("errorJava", e.getMessage()); - response.sendRedirect("sql.jsp"); - } catch(SQLException e) { - e.printStackTrace(); - session.setAttribute("errorJava", e.getMessage()); - response.sendRedirect("sql.jsp"); - } - } + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + createConnection(request, response); + } - private Connection createJavaConnection() throws ClassNotFoundException, SQLException { - Class.forName(jdbcDriver); - Connection con = DriverManager.getConnection(url, username, password); - return con; - } + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + createConnection(request, response); + } + + private void createConnection(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + if(request.getParameter("connectionUrl") == null || request.getParameter("username") == null || request.getParameter("password") == null) { + + } else { + url = request.getParameter("connectionUrl"); + username = request.getParameter("username"); + password = request.getParameter("password"); + } + try { + Connection con = createJavaConnection(); + ServletContext application = this.getServletConfig().getServletContext(); + application.setAttribute("unpooledConnection", con); + session.setAttribute("connectionDataJava", con.toString()); + response.sendRedirect("sql.jsp"); + } catch(ClassNotFoundException e) { + e.printStackTrace(); + session.setAttribute("errorJava", e.getMessage()); + response.sendRedirect("sql.jsp"); + } catch(SQLException e) { + e.printStackTrace(); + session.setAttribute("errorJava", e.getMessage()); + response.sendRedirect("sql.jsp"); + } + } + + private Connection createJavaConnection() throws ClassNotFoundException, SQLException { + Class.forName(jdbcDriver); + Connection con = DriverManager.getConnection(url, username, password); + return con; + } } diff --git a/src/com/waratek/spiracle/sql/servlet/Delete_User.java b/src/com/waratek/spiracle/sql/servlet/oracle/Delete_User.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Delete_User.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Delete_User.java index 8acedd2..0330c76 100644 --- a/src/com/waratek/spiracle/sql/servlet/Delete_User.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Delete_User.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_Full_Outer_Join.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Full_Outer_Join.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_Full_Outer_Join.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_Full_Outer_Join.java index eefabed..591ca96 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_Full_Outer_Join.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Full_Outer_Join.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_Implicit_Join.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Implicit_Join.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_Implicit_Join.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_Implicit_Join.java index 6b8ded1..a2d44a5 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_Implicit_Join.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Implicit_Join.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_Union.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Union.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_Union.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_Union.java index de53961..deed032 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_Union.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_Union.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int.java index 5d70871..193dbdc 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_groupby.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_groupby.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_groupby.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_groupby.java index 0ec3cdf..435d59a 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_groupby.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_groupby.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_having.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_having.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_having.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_having.java index 7e66898..2f1c7f3 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_having.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_having.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_inline.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_inline.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_inline.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_inline.java index 2bba4fd..77afb02 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_inline.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_inline.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_no_quote.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_no_quote.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_no_quote.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_no_quote.java index df71610..67be8cf 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_no_quote.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_no_quote.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_nooutput.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_nooutput.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_nooutput.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_nooutput.java index 76a3257..3309912 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_nooutput.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_nooutput.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_orderby.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_orderby.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_orderby.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_orderby.java index cca73d5..2fb93dc 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_orderby.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_orderby.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_int_partialunion.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_partialunion.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_int_partialunion.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_int_partialunion.java index 3c73301..288130d 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_int_partialunion.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_int_partialunion.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_string.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_string.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_string.java index e3a3f96..c7a0d34 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_string.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_string_constructor.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_constructor.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Get_string_constructor.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_string_constructor.java index 25f823c..9d18c7d 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_string_constructor.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_constructor.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_string_no_quote.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Get_string_no_quote.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote.java index bbb684d..a0a8fab 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_string_no_quote.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_string_no_quote_sanitised.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote_sanitised.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Get_string_no_quote_sanitised.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote_sanitised.java index fe9f4d7..9466c9e 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_string_no_quote_sanitised.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_no_quote_sanitised.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Get_string_sanitised.java b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_sanitised.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Get_string_sanitised.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Get_string_sanitised.java index d647b61..48cd47d 100644 --- a/src/com/waratek/spiracle/sql/servlet/Get_string_sanitised.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Get_string_sanitised.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Implicit_Join_Namespace.java b/src/com/waratek/spiracle/sql/servlet/oracle/Implicit_Join_Namespace.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Implicit_Join_Namespace.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Implicit_Join_Namespace.java index 5e40084..770bf08 100644 --- a/src/com/waratek/spiracle/sql/servlet/Implicit_Join_Namespace.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Implicit_Join_Namespace.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text.java b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text.java index 3b73b27..bfa465b 100644 --- a/src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text_Sanitised.java b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text_Sanitised.java similarity index 97% rename from src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text_Sanitised.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text_Sanitised.java index 0dd2279..8c71cf6 100644 --- a/src/com/waratek/spiracle/sql/servlet/Insert_Raw_Text_Sanitised.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_Raw_Text_Sanitised.java @@ -1,4 +1,4 @@ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Insert_User.java b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_User.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Insert_User.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Insert_User.java index 504b614..46954df 100644 --- a/src/com/waratek/spiracle/sql/servlet/Insert_User.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Insert_User.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/Update_User.java b/src/com/waratek/spiracle/sql/servlet/oracle/Update_User.java similarity index 98% rename from src/com/waratek/spiracle/sql/servlet/Update_User.java rename to src/com/waratek/spiracle/sql/servlet/oracle/Update_User.java index b12b3dd..7319c01 100644 --- a/src/com/waratek/spiracle/sql/servlet/Update_User.java +++ b/src/com/waratek/spiracle/sql/servlet/oracle/Update_User.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.waratek.spiracle.sql.servlet; +package com.waratek.spiracle.sql.servlet.oracle; import java.io.IOException; import java.util.ArrayList; diff --git a/src/com/waratek/spiracle/sql/servlet/util/ParameterNullFix.java b/src/com/waratek/spiracle/sql/servlet/util/ParameterNullFix.java index 5313104..ee26ddc 100644 --- a/src/com/waratek/spiracle/sql/servlet/util/ParameterNullFix.java +++ b/src/com/waratek/spiracle/sql/servlet/util/ParameterNullFix.java @@ -25,18 +25,18 @@ public class ParameterNullFix { private static final Logger logger = Logger.getLogger(ParameterNullFix.class); - - public static Map sanitizeNull(List inputList, HttpServletRequest request) { - Map outputMap= new HashMap(); - for(String item : inputList) { - String val = request.getParameter(item); - if(val == null) { - logger.info("Expected parameter [" + item + "] is null"); - outputMap.put(item, ""); - } else { - outputMap.put(item, val); - } - } - return outputMap; - } + + public static Map sanitizeNull(List inputList, HttpServletRequest request) { + Map outputMap= new HashMap(); + for(String item : inputList) { + String val = request.getParameter(item); + if(val == null) { + logger.info("Expected parameter {" + item + "} is null"); + outputMap.put(item, ""); + } else { + outputMap.put(item, val); + } + } + return outputMap; + } } diff --git a/src/com/waratek/spiracle/sql/spring/CreateSpringContext.java b/src/com/waratek/spiracle/sql/spring/CreateSpringContext.java index b1b505b..bd9c980 100644 --- a/src/com/waratek/spiracle/sql/spring/CreateSpringContext.java +++ b/src/com/waratek/spiracle/sql/spring/CreateSpringContext.java @@ -36,60 +36,58 @@ */ @WebServlet("/CreateSpringContext") public class CreateSpringContext extends HttpServlet { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private String springContextPath; + private String springContextPath; - /** - * @see HttpServlet#HttpServlet() - */ - public CreateSpringContext() { - super(); - // TODO Auto-generated constructor stub - } + /** + * @see HttpServlet#HttpServlet() + */ + public CreateSpringContext() { + super(); + // TODO Auto-generated constructor stub + } - public void init() { - ServletContext application = this.getServletConfig().getServletContext(); - InputStream propStream = application.getResourceAsStream("conf/Spiracle.properties"); - Properties prop = new Properties(); - try { - prop.load(propStream); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - springContextPath = prop.getProperty("spring.path"); - } + public void init() { + ServletContext application = this.getServletConfig().getServletContext(); + InputStream propStream = application.getResourceAsStream("conf/Spiracle.properties"); + Properties prop = new Properties(); + try { + prop.load(propStream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + springContextPath = prop.getProperty("spring.path"); + } - /** - * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - createSpringContext(request, response); - } + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + createSpringContext(request, response); + } - /** - * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - createSpringContext(request, response); - } + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + createSpringContext(request, response); + } - private void createSpringContext(HttpServletRequest request, HttpServletResponse response) throws IOException { - HttpSession session = request.getSession(); - if(request.getParameter("filePath") == null) { - - } else { - springContextPath = request.getParameter("filePath").toString(); - } - ServletContext application = this.getServletConfig().getServletContext(); - ApplicationContext context = new FileSystemXmlApplicationContext("file:" + springContextPath); + private void createSpringContext(HttpServletRequest request, HttpServletResponse response) throws IOException { + HttpSession session = request.getSession(); + if(request.getParameter("filePath") == null) { - application.setAttribute("springContext", context); - session.setAttribute("springContextData", context.toString()); - response.sendRedirect("sql.jsp"); - } + } else { + springContextPath = request.getParameter("filePath").toString(); + } + ServletContext application = this.getServletConfig().getServletContext(); + ApplicationContext context = new FileSystemXmlApplicationContext("file:" + springContextPath); + + application.setAttribute("springContext", context); + session.setAttribute("springContextData", context.toString()); + response.sendRedirect("sql.jsp"); + } } diff --git a/src/com/waratek/spiracle/sql/util/ConnectionUtil.java b/src/com/waratek/spiracle/sql/util/ConnectionUtil.java index 588e78f..94081a2 100644 --- a/src/com/waratek/spiracle/sql/util/ConnectionUtil.java +++ b/src/com/waratek/spiracle/sql/util/ConnectionUtil.java @@ -30,21 +30,21 @@ public class ConnectionUtil { private static final Logger logger = Logger.getLogger(ParameterNullFix.class); - public static Connection getConnection(ServletContext application, String connectionType) throws SQLException { - Connection con = null; - logger.info("Connection Type: " + connectionType); - if(connectionType.equals("c3p0")) { - ComboPooledDataSource ds = (ComboPooledDataSource)application.getAttribute("connectionPool"); - con = ds.getConnection(); - } else if(connectionType.equals("java")) { - con = (Connection)application.getAttribute("connection"); - } else if(connectionType.equals("spring")) { - FileSystemXmlApplicationContext context = (FileSystemXmlApplicationContext)application.getAttribute("springContext"); - DriverManagerDataSource dmds = (DriverManagerDataSource)context.getBean("dataSource"); - con = dmds.getConnection(); - } - - logger.info("Returning connection: " + con.toString()); - return con; - } + public static Connection getConnection(ServletContext application, String connectionType) throws SQLException { + Connection con = null; + logger.info("Connection Type: " + connectionType); + if(connectionType.equals("c3p0")) { + ComboPooledDataSource ds = (ComboPooledDataSource)application.getAttribute("connectionPool"); + con = ds.getConnection(); + } else if(connectionType.equals("java")) { + con = (Connection)application.getAttribute("connection"); + } else if(connectionType.equals("spring")) { + FileSystemXmlApplicationContext context = (FileSystemXmlApplicationContext)application.getAttribute("springContext"); + DriverManagerDataSource dmds = (DriverManagerDataSource)context.getBean("dataSource"); + con = dmds.getConnection(); + } + + logger.info("Returning connection: " + con.toString()); + return con; + } } diff --git a/src/com/waratek/spiracle/sql/util/SelectUtil.java b/src/com/waratek/spiracle/sql/util/SelectUtil.java index 957b092..9eb0f58 100644 --- a/src/com/waratek/spiracle/sql/util/SelectUtil.java +++ b/src/com/waratek/spiracle/sql/util/SelectUtil.java @@ -38,6 +38,10 @@ public static void executeQuery(String sql, ServletContext application, HttpServ ServletOutputStream out = response.getOutputStream(); String connectionType = null; Connection con = null; + int fetchSize = (Integer) application.getAttribute("fetchSize"); + + PreparedStatement stmt = null; + ResultSet rs = null; TagUtil.printPageHead(out); TagUtil.printPageNavbar(out); @@ -50,7 +54,7 @@ public static void executeQuery(String sql, ServletContext application, HttpServ } else { connectionType = request.getParameter("connectionType"); } - con = ConnectionUtil.getConnection(application, connectionType); + con = ConnectionUtil.getConnection(application, connectionType); out.println("
"); out.println("

SQL Query:

"); out.println("
");
@@ -59,14 +63,13 @@ public static void executeQuery(String sql, ServletContext application, HttpServ
 
 			logger.info(sql);
 
-			PreparedStatement stmt = con.prepareStatement(sql);
-			ResultSet rs = stmt.executeQuery();
+			stmt = con.prepareStatement(sql);
+			logger.info("Created PreparedStatement: " + sql);
+			stmt.setFetchSize(fetchSize);
+			rs = stmt.executeQuery();
+			logger.info("Executed: " + sql);
 
 			writeToResponse(allResults, showOutput, out, rs);
-			out.close();
-			rs.close();
-			stmt.close();
-			con.close();
 		} catch(SQLException e) {
 			if(e.getMessage().equals("Attempted to execute a query with one or more bad parameters.")) {
 				response.setStatus(550);
@@ -83,20 +86,49 @@ public static void executeQuery(String sql, ServletContext application, HttpServ
 			while((e = e.getNextException()) != null) {
 				out.println(e.getMessage() + "
"); } + } finally { try { - con.rollback(); - con.close(); - } catch (SQLException e1) { + if(rs != null) { + logger.info("Closing ResultSet " + rs); + rs.close(); + logger.info("Closed ResultSet " + rs); + } + } catch (SQLException rsCloseException) { if(logger.isDebugEnabled()) { - logger.debug(e.getMessage(), e); + logger.debug(rsCloseException.getMessage(), rsCloseException); } else { - logger.error(e); + logger.error(rsCloseException); + } + } + try { + if(stmt != null) { + logger.info("Closing PreparedStatement " + stmt); + stmt.close(); + logger.info("Closed PreparedStatement " + stmt); + } + } catch (SQLException stmtCloseException) { + if(logger.isDebugEnabled()) { + logger.debug(stmtCloseException.getMessage(), stmtCloseException); + } else { + logger.error(stmtCloseException); + } + } + try { + if(con != null) { + logger.info("Closing Connection " + con); + con.close(); + logger.info("Closed Connection " + con); + } + } catch (SQLException conCloseException) { + if(logger.isDebugEnabled()) { + logger.debug(conCloseException.getMessage(), conCloseException); + } else { + logger.error(conCloseException); } } - TagUtil.printPageFooter(out); + out.close(); } - } private static void writeToResponse(Boolean allResults, Boolean showOutput, ServletOutputStream out, ResultSet rs) throws SQLException, IOException { @@ -130,7 +162,7 @@ private static void writeToResponse(Boolean allResults, Boolean showOutput, Serv private static void writeRow(ServletOutputStream out, ResultSet rs, ResultSetMetaData metaData) throws IOException, SQLException { out.println(""); - for(int i = 1; i <= metaData.getColumnCount(); i++) { + for(int i = 1; i <= metaData.getColumnCount(); i++) { Object content = rs.getObject(i); if(content != null) { out.println("" + content.toString() + ""); diff --git a/src/com/waratek/spiracle/sql/util/TagUtil.java b/src/com/waratek/spiracle/sql/util/TagUtil.java index 3f560fb..da33196 100644 --- a/src/com/waratek/spiracle/sql/util/TagUtil.java +++ b/src/com/waratek/spiracle/sql/util/TagUtil.java @@ -21,19 +21,19 @@ public class TagUtil { static void printPageHead(ServletOutputStream out) throws IOException { - out.println(""); - out.println(""); - out.println(""); - out.println(""); - out.println(""); - out.println(""); - out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); + out.println(""); - out.println("Spiracle - SQL"); - out.println(""); - out.println(""); + out.println("Spiracle - SQL"); + out.println(""); + out.println(""); } - + static void printPageNavbar(ServletOutputStream out) throws IOException { out.println("
"); out.println("
"); @@ -57,16 +57,16 @@ static void printPageNavbar(ServletOutputStream out) throws IOException { out.println("
"); out.println("
"); } - + static void printContentDiv(ServletOutputStream out) throws IOException { out.println("
"); } - + static void printPageFooter(ServletOutputStream out) throws IOException { out.println("
"); out.println("
"); - out.println(""); - out.println(""); - out.println(""); + out.println(""); + out.println(""); + out.println(""); } } diff --git a/src/com/waratek/spiracle/sql/util/UpdateUtil.java b/src/com/waratek/spiracle/sql/util/UpdateUtil.java index 6f6f182..2d82b88 100644 --- a/src/com/waratek/spiracle/sql/util/UpdateUtil.java +++ b/src/com/waratek/spiracle/sql/util/UpdateUtil.java @@ -27,74 +27,92 @@ import org.apache.log4j.Logger; -import com.waratek.spiracle.init.SpiracleInit; - public class UpdateUtil { private static final Logger logger = Logger.getLogger(UpdateUtil.class); - public static void executeUpdate(String sql, ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException{ - response.setHeader("Content-Type", "text/html;charset=UTF-8"); - ServletOutputStream out = response.getOutputStream(); - String connectionType = null; - Connection con = null; + public static void executeUpdate(String sql, ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException{ + response.setHeader("Content-Type", "text/html;charset=UTF-8"); + ServletOutputStream out = response.getOutputStream(); + String connectionType = null; + Connection con = null; + + PreparedStatement stmt = null; - TagUtil.printPageHead(out); - TagUtil.printPageNavbar(out); - TagUtil.printContentDiv(out); - - try { - //Checking if connectionType is not, defaulting it to c3p0 if not set. - if(request.getParameter("connectionType") == null) { - connectionType = "c3p0"; - } else { - connectionType = request.getParameter("connectionType"); - } - con = ConnectionUtil.getConnection(application, connectionType); - out.println("
"); - out.println("

SQL Query:

"); - out.println("
");
-            out.println(sql);
-            out.println("
"); + TagUtil.printPageHead(out); + TagUtil.printPageNavbar(out); + TagUtil.printContentDiv(out); - logger.info(sql); + try { + //Checking if connectionType is not, defaulting it to c3p0 if not set. + if(request.getParameter("connectionType") == null) { + connectionType = "c3p0"; + } else { + connectionType = request.getParameter("connectionType"); + } + con = ConnectionUtil.getConnection(application, connectionType); + out.println("
"); + out.println("

SQL Query:

"); + out.println("
");
+			out.println(sql);
+			out.println("
"); - PreparedStatement stmt = con.prepareStatement(sql); - int result = stmt.executeUpdate(); - out.println("

Altered Rows:

"); - out.print("
" + result + "
"); - TagUtil.printPageFooter(out); - out.close(); - stmt.close(); - con.close(); - - } catch(SQLException e) { - if(e.getMessage().equals("Attempted to execute a query with one or more bad parameters.")) { - response.setStatus(550); - } else { - response.setStatus(500); - } - out.println("
"); - out.println("SQLException: " + e.getMessage() + "
"); + logger.info(sql); + + stmt = con.prepareStatement(sql); + logger.info("Created PreparedStatement: " + sql); + int result = stmt.executeUpdate(); + logger.info("Executed: " + sql); + + out.println("

Altered Rows:

"); + out.print("
" + result + "
"); + TagUtil.printPageFooter(out); + } catch(SQLException e) { + if(e.getMessage().equals("Attempted to execute a query with one or more bad parameters.")) { + response.setStatus(550); + } else { + response.setStatus(500); + } + out.println("
"); + out.println("SQLException: " + e.getMessage() + "
"); if(logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } else { logger.error(e); } - while((e = e.getNextException()) != null) { - out.println(e.getMessage() + "
"); - } - try { - con.rollback(); - con.close(); - } catch (SQLException e1) { - if(logger.isDebugEnabled()) { - logger.debug(e.getMessage(), e); - } else { - logger.error(e); - } - } - out.println("
"); - TagUtil.printPageFooter(out); - } - } + while((e = e.getNextException()) != null) { + out.println(e.getMessage() + "
"); + } + } finally { + try { + if(stmt != null) { + logger.info("Closing PreparedStatement " + stmt); + stmt.close(); + logger.info("Closed PreparedStatement " + stmt); + } + } catch (SQLException stmtCloseException) { + if(logger.isDebugEnabled()) { + logger.debug(stmtCloseException.getMessage(), stmtCloseException); + } else { + logger.error(stmtCloseException); + } + } + try { + if(con != null) { + logger.info("Closing Connection " + con); + con.close(); + logger.info("Closed Connection " + con); + } + } catch (SQLException conCloseException) { + if(logger.isDebugEnabled()) { + logger.debug(conCloseException.getMessage(), conCloseException); + } else { + logger.error(conCloseException); + } + } + + out.println("
"); + TagUtil.printPageFooter(out); + out.close(); + } + } }