summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrei Aiordachioaie <a.aiordachioaie@jacobs-university.de>2010-02-27 15:19:28 +0100
committerAndrei Aiordachioaie <a.aiordachioaie@jacobs-university.de>2010-02-27 15:19:28 +0100
commite9f0983d7bcd4eb770acaf159e2c9451f12c368b (patch)
treee5ae763524d073ad925eea06ca5d00c1d2e9496b /src
parent1e1f7d348d70a5ae7d2bfdffbb66020205852334 (diff)
Updated Petascope interface.
Petascope can now accept raw XML requests, with or without URL encoding (mimetypes application/x-url-encoded and text/xml), with or without parameter "request".
Diffstat (limited to 'src')
-rw-r--r--src/petascope/ConfigManager.java11
-rw-r--r--src/petascope/PetascopeInterface.java85
2 files changed, 86 insertions, 10 deletions
diff --git a/src/petascope/ConfigManager.java b/src/petascope/ConfigManager.java
index 0a4985c..e369498 100644
--- a/src/petascope/ConfigManager.java
+++ b/src/petascope/ConfigManager.java
@@ -51,7 +51,7 @@ public class ConfigManager {
v3 adds WGS84 handling in WCPS requests. */
private final static String MINOR = "3";
/* Bug-fix count. We have a hack: every WCPS response is written to disk. */
- private final static String BUGFIX = "3-hack";
+ private final static String BUGFIX = "4-hack";
/* Petascope 1.2.0 contains WCS 1.1.0, WCS 2.0, WCS-T 1.0.0 and WCPS 1.0.0 */
public final static String PETASCOPE_VERSION = MAJOR + "." + MINOR + "." + BUGFIX;
@@ -186,6 +186,9 @@ public class ConfigManager {
}
LOG.info("---------------------------");
+ if (CCIP_HACK)
+ LOG.info("-----------CCIP------------");
+ LOG.info("---------------------------");
// log("Print Log: " + PRINT_LOG);
LOG.info(" *** PETASCOPE *** ");
@@ -202,9 +205,9 @@ public class ConfigManager {
LOG.info("WCS-T Default Null Resistance: " + WCST_DEFAULT_NULL_RESISTANCE);
LOG.info("WCS-T Default Datatype: " + WCST_DEFAULT_DATATYPE);
LOG.info(" *** WCS 2.0 *** ");
- LOG.debug("Get Capabilities Template: " + WCS2_GET_CAPABILITIES_TEMPLATE);
- LOG.debug("Describe Coverage Template: " + WCS2_DESCRIBE_COVERAGE_TEMPLATE);
- LOG.debug("Get Capabilities Template: " + WCS2_GET_COVERAGE_TEMPLATE);
+ LOG.trace("Get Capabilities Template: " + WCS2_GET_CAPABILITIES_TEMPLATE.substring(0, 100));
+ LOG.trace("Describe Coverage Template: " + WCS2_DESCRIBE_COVERAGE_TEMPLATE.substring(0, 100));
+ LOG.trace("Get Capabilities Template: " + WCS2_GET_COVERAGE_TEMPLATE.substring(0, 100));
LOG.info("---------------------------");
}
diff --git a/src/petascope/PetascopeInterface.java b/src/petascope/PetascopeInterface.java
index 9cf4c54..67d8d4d 100644
--- a/src/petascope/PetascopeInterface.java
+++ b/src/petascope/PetascopeInterface.java
@@ -28,7 +28,12 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.lang.String;
+import java.net.URLDecoder;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -212,6 +217,41 @@ public class PetascopeInterface extends HttpServlet
LOG.info("-----------------------------------------------");
}
+ /* Build a dictionary of parameter names and values, given a request string */
+ private Map<String,String> buildParameterDictionary(String request)
+ {
+ HashMap<String,String> map = new HashMap<String,String>(3);
+ if (request == null)
+ return map;
+
+ String[] pairs = request.split("&");
+ String key = null, val = null;
+ int pos = -1;
+ for (int i=0; i < pairs.length; i++)
+ {
+ pos = pairs[i].indexOf("=");
+ if (pos != -1)
+ {
+ key = pairs[i].substring(0, pos);
+ val = pairs[i].substring(pos+1, pairs[i].length());
+ map.put(key, val);
+ }
+ }
+
+ return map;
+ }
+
+ /* URL-decode a string, if needed */
+ private String urldecode(String encodedText, String contentType) throws UnsupportedEncodingException
+ {
+ if (encodedText == null)
+ return null;
+ String decoded = encodedText;
+ if (contentType != null && contentType.equals("application/x-www-form-urlencoded"))
+ decoded = URLDecoder.decode(encodedText, "UTF-8");
+ return decoded;
+ }
+
/* Respond to Post requests just like in the case of Get requests */
@Override
public void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@@ -228,35 +268,68 @@ public class PetascopeInterface extends HttpServlet
@Override
public void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
{
+ String request = null, requestBody = null;
+
/* Init the Petascope URL automatically, for GetCapabilities response */
if (ConfigManager.PETASCOPE_SERVLET_URL == null)
ConfigManager.PETASCOPE_SERVLET_URL = httpRequest.getRequestURL().toString();
- /* List all available coverages */
+ /* List all available coverages, to make sure metadata is available */
try {LOG.debug("PetaScope coverages: " + metadataSource.coverages());}
catch (ResourceException e){}
/* Process the request */
- String request = httpRequest.getParameter("request");
- String service = httpRequest.getParameter("service");
-
+
try
{
try
{
+ requestBody = IOUtils.toString(httpRequest.getReader());
+ LOG.trace("POST Request length: " + httpRequest.getContentLength());
+ LOG.trace("POST request body: \n------START REQUEST--------\n" +
+ requestBody + "\n------END REQUEST------\n");
+
+ Map<String,String> params = buildParameterDictionary(requestBody);
+ LOG.trace("Request parameters: {}", params);
+ request = urldecode(params.get("request"), httpRequest.getContentType());
+
// Quick hack to preserve compatibility with previous client versions
- String request2 = httpRequest.getParameter("query");
+ // (GET requests with parameter "query")
+ String request2 = null;
+ if (params.containsKey("query"))
+ request2 = params.get("query");
+ else
+ request2 = httpRequest.getParameter("query");
if (request2 != null)
+ {
+ LOG.debug("Received Abstract Syntax Request via GET: \n\t\t{}", request2);
request2 = ProcessCoveragesRequest.abstractQueryToXmlQuery(request2);
+ }
if (request == null && request2 != null)
request = request2;
- if (request == null)
+ // Empty request ?
+ if (request == null && (requestBody == null || requestBody.length() == 0))
{
printUsage(httpResponse, request);
return;
}
+ // No parameters, just XML in the request body
+ if (request == null && requestBody != null && requestBody.length() > 0)
+ {
+ request = urldecode(requestBody, httpRequest.getContentType());
+
+// if (request.matches(" *<.*") == false)
+// {
+// handleUnknownRequest(request, httpResponse);
+// return;
+// }
+ }
+
+ LOG.debug("Petascope Request: \n------START REQUEST--------\n" +
+ request + "\n------END REQUEST------\n");
+
Document doc = builder.parse(IOUtils.toInputStream(request));
Element rootElem = doc.getDocumentElement();
String root = rootElem.getTagName();