Strabon
changeset 567:f0e942e210e0
added ChangeConnectionBean.java. Now, one can change the connection details by hitting the servlet "ChangeConnection"
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Thu Sep 27 20:39:23 2012 +0300 (2012-09-27) |
parents | 81ac0fc6733e |
children | e77af8806201 |
files | endpoint/WebContent/WEB-INF/web.xml endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ChangeConnectionBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java |
line diff
1.1 --- a/endpoint/WebContent/WEB-INF/web.xml Thu Sep 27 19:57:02 2012 +0300 1.2 +++ b/endpoint/WebContent/WEB-INF/web.xml Thu Sep 27 20:39:23 2012 +0300 1.3 @@ -70,6 +70,17 @@ 1.4 </servlet-mapping> 1.5 1.6 <servlet> 1.7 + <display-name>ChangeConnection</display-name> 1.8 + <servlet-name>ChangeConnection</servlet-name> 1.9 + <servlet-class>eu.earthobservatory.org.StrabonEndpoint.ChangeConnectionBean</servlet-class> 1.10 + <load-on-startup>1</load-on-startup> 1.11 + </servlet> 1.12 + <servlet-mapping> 1.13 + <servlet-name>ChangeConnection</servlet-name> 1.14 + <url-pattern>/ChangeConnection</url-pattern> 1.15 + </servlet-mapping> 1.16 + 1.17 + <servlet> 1.18 <servlet-name>query.jsp</servlet-name> 1.19 <jsp-file>/query.jsp</jsp-file> 1.20 </servlet>
2.1 --- a/endpoint/WebContent/query.jsp Thu Sep 27 19:57:02 2012 +0300 2.2 +++ b/endpoint/WebContent/query.jsp Thu Sep 27 20:39:23 2012 +0300 2.3 @@ -133,6 +133,10 @@ 2.4 2.5 } 2.6 2.7 + if ("null".equals(query)) { 2.8 + query = ""; 2.9 + } 2.10 + 2.11 // get format parameter or attribute (the attribute comes from ConnectionBean) 2.12 String selFormat = ""; 2.13 if (request.getParameter("format") != null) {
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ChangeConnectionBean.java Thu Sep 27 20:39:23 2012 +0300 3.3 @@ -0,0 +1,84 @@ 3.4 +/** 3.5 + * This Source Code Form is subject to the terms of the Mozilla Public 3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 3.8 + * 3.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 3.10 + * 3.11 + * http://www.strabon.di.uoa.gr/ 3.12 + */ 3.13 +package eu.earthobservatory.org.StrabonEndpoint; 3.14 + 3.15 +import java.io.IOException; 3.16 + 3.17 +import javax.servlet.RequestDispatcher; 3.18 +import javax.servlet.ServletConfig; 3.19 +import javax.servlet.ServletContext; 3.20 +import javax.servlet.ServletException; 3.21 +import javax.servlet.http.HttpServlet; 3.22 +import javax.servlet.http.HttpServletRequest; 3.23 +import javax.servlet.http.HttpServletResponse; 3.24 + 3.25 +import org.springframework.web.context.WebApplicationContext; 3.26 +import org.springframework.web.context.support.WebApplicationContextUtils; 3.27 + 3.28 +/** 3.29 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 3.30 + * 3.31 + */ 3.32 +public class ChangeConnectionBean extends HttpServlet { 3.33 + 3.34 + private static final long serialVersionUID = 2175155067582174020L; 3.35 + 3.36 + /** 3.37 + * The context of the servlet 3.38 + */ 3.39 + private ServletContext context; 3.40 + 3.41 + /** 3.42 + * Wrapper over Strabon 3.43 + */ 3.44 + private StrabonBeanWrapper strabonWrapper; 3.45 + 3.46 + 3.47 + public void init(ServletConfig servletConfig) throws ServletException { 3.48 + super.init(servletConfig); 3.49 + 3.50 + // get the context of the servlet 3.51 + context = getServletContext(); 3.52 + 3.53 + // get the context of the application 3.54 + WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 3.55 + 3.56 + // the the strabon wrapper 3.57 + strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean"); 3.58 + } 3.59 + 3.60 + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 3.61 + doPost(request, response); 3.62 + } 3.63 + 3.64 + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 3.65 + request.setCharacterEncoding("UTF-8"); 3.66 + RequestDispatcher dispatcher = request.getRequestDispatcher("/connection.jsp"); 3.67 + 3.68 + // pass the current details of the connection 3.69 + request.setAttribute("username", strabonWrapper.getUsername()); 3.70 + request.setAttribute("password", strabonWrapper.getPassword()); 3.71 + request.setAttribute("dbname", strabonWrapper.getDatabaseName()); 3.72 + request.setAttribute("hostname", strabonWrapper.getHostName()); 3.73 + request.setAttribute("port", strabonWrapper.getPort()); 3.74 + request.setAttribute("dbengine", strabonWrapper.getDBEngine()); 3.75 + 3.76 + // pass the other parameters as well 3.77 + request.setAttribute("query", request.getParameter("query")); 3.78 + request.setAttribute("format", request.getParameter("format")); 3.79 + request.setAttribute("handle", request.getParameter("handle")); 3.80 + 3.81 + // close the currently active connection 3.82 + strabonWrapper.closeConnection(); 3.83 + 3.84 + // forward the request 3.85 + dispatcher.forward(request, response); 3.86 + } 3.87 +}
4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Thu Sep 27 19:57:02 2012 +0300 4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Thu Sep 27 20:39:23 2012 +0300 4.3 @@ -146,6 +146,13 @@ 4.4 this.strabon = strabon; 4.5 } 4.6 4.7 + public void closeConnection() { 4.8 + if (strabon != null) { 4.9 + strabon.close(); 4.10 + strabon = null; 4.11 + } 4.12 + } 4.13 + 4.14 public void destroy() throws Exception { 4.15 if (strabon != null) { 4.16 strabon.close();