summaryrefslogtreecommitdiffstats
path: root/petascope/src/petascope/wcst/server/servlet
diff options
context:
space:
mode:
authorConstantin <jucovschi@gmail.com>2010-06-02 20:09:42 +0200
committerConstantin <jucovschi@gmail.com>2010-06-02 20:09:42 +0200
commit40e12c6af9d05c3413efaf535c35c625b736cbb9 (patch)
tree6a9f6b86b55724e659ca270171496d82362de9cc /petascope/src/petascope/wcst/server/servlet
parentfcda34adb1c78d0929778e1324c873552d21ee1d (diff)
downloadrasdaman-upstream-40e12c6af9d05c3413efaf535c35c625b736cbb9.tar.gz
rasdaman-upstream-40e12c6af9d05c3413efaf535c35c625b736cbb9.tar.xz
rasdaman-upstream-40e12c6af9d05c3413efaf535c35c625b736cbb9.zip
preparing for joining with rasdaman open source
Diffstat (limited to 'petascope/src/petascope/wcst/server/servlet')
-rw-r--r--petascope/src/petascope/wcst/server/servlet/wcstServlet.java161
1 files changed, 161 insertions, 0 deletions
diff --git a/petascope/src/petascope/wcst/server/servlet/wcstServlet.java b/petascope/src/petascope/wcst/server/servlet/wcstServlet.java
new file mode 100644
index 0000000..51f11d3
--- /dev/null
+++ b/petascope/src/petascope/wcst/server/servlet/wcstServlet.java
@@ -0,0 +1,161 @@
+/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+package petascope.wcst.server.servlet;
+
+//~--- non-JDK imports --------------------------------------------------------
+import petascope.wcst.server.*;
+import petascope.ConfigManager;
+import org.apache.commons.io.FileUtils;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import petascope.wcps.server.core.DbMetadataSource;
+import petascope.wcs.server.exceptions.WCSException;
+
+/** Servlet interface for the WCS-Transactional server.
+ *
+ * @author Andrei Aiordachioaie
+ */
+public class wcstServlet extends HttpServlet {
+
+ private String defaultHtmlResponse;
+ private String relativeServletHtmlPath = "/templates/wcst-servlet.html";
+ private String servletHtmlPath;
+ private String relativeSettingsPath = "/settings.properties";
+ private WcstServer server;
+ private DbMetadataSource metadataSource;
+
+ @Override
+ public void init() throws ServletException {
+ // Initialize the configuration manager. Now all classes can read the settings.
+ String settingsPath = getServletContext().getRealPath(relativeSettingsPath);
+ ConfigManager config = ConfigManager.getInstance(settingsPath, getServletContext().getRealPath("/"));
+
+ try {
+ metadataSource = new DbMetadataSource(
+ ConfigManager.METADATA_DRIVER, ConfigManager.METADATA_URL,
+ ConfigManager.METADATA_USER, ConfigManager.METADATA_PASS, false);
+ } catch (Exception e) {
+ throw new ServletException("Metadata Database Error.", e);
+ }
+
+ // Initialize the WCS-T server with proper metadata
+ try {
+ server = new WcstServer(metadataSource);
+ } catch (WCSException e) {
+ throw new ServletException(e);
+ }
+
+ // Load the servlet HTML response
+ servletHtmlPath = getServletContext().getRealPath(relativeServletHtmlPath);
+ try {
+ defaultHtmlResponse = FileUtils.readFileToString(new File(servletHtmlPath));
+ } catch (IOException e) {
+ throw new ServletException(e);
+ }
+ }
+
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ * @param request wcstServlet request
+ * @param response wcstServlet response
+ * @throws ServletException if a wcstServlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ System.out.println("WCS-T: invoked with GET");
+ printUsage(response);
+ }
+
+ /**
+ * Handles the HTTP <code>POST</code> method.
+ * @param request wcstServlet request
+ * @param response wcstServlet response
+ * @throws ServletException if a wcstServlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ // Select the operation
+ int op = -1;
+
+ if (request.getParameter("TransactionXML") != null) {
+ op = 4;
+ }
+
+ // Convert the WCS request into a WCPS request
+ try {
+ // initialize WebService operation arguments here
+ String inputXml, outputXml;
+ PrintWriter out;
+
+ switch (op) {
+ case 4:
+ inputXml = request.getParameter("TransactionXML");
+ outputXml = server.Transaction(inputXml);
+ out = new PrintWriter(response.getOutputStream());
+ out.write(outputXml);
+ out.flush();
+
+ break;
+ default:
+ throw new Exception("No valid operation specified !");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ throw new ServletException("WCS-T servlet error !", e);
+ }
+ }
+
+ /**
+ * Returns a short description of the wcstServlet.
+ * @return a String containing wcstServlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "WCS-T Extension. Petascope version " + ConfigManager.PETASCOPE_VERSION;
+ }
+
+ private void printUsage(HttpServletResponse response) throws IOException {
+ System.out.println("WCS-T: returning usage message");
+ response.setContentType("text/html; charset=utf-8");
+ PrintWriter out = new PrintWriter(response.getOutputStream());
+
+ out.println(defaultHtmlResponse);
+
+ out.close();
+ System.out.println("WCS-T: done nothing");
+
+ }
+}