|
From: <svn...@os...> - 2012-05-04 15:22:16
|
Author: aaime
Date: 2012-05-04 08:22:05 -0700 (Fri, 04 May 2012)
New Revision: 38702
Modified:
trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/ExecuteProcessResponse.java
trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java
Log:
[GEOT-4127] WPS client won't report exceptions in case a raw response has been demanded by the client
Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/ExecuteProcessResponse.java
===================================================================
--- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/ExecuteProcessResponse.java 2012-05-03 13:01:36 UTC (rev 38701)
+++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/ExecuteProcessResponse.java 2012-05-04 15:22:05 UTC (rev 38702)
@@ -76,7 +76,7 @@
// could be gml or other stuff, not necessarily a service exception, we need to check if it's an exception or not
rawContentType = httpResponse.getContentType();
- if(rawContentType.startsWith("text/xml")) {
+ if(rawContentType.matches(".*/xml.*")) {
// make sure we don't throw away info
inputStream = new BufferedInputStream(httpResponse.getResponseStream());
inputStream.mark(8192);
@@ -89,9 +89,8 @@
// get the first tag name
String name = parser.getName();
- String namespace = parser.getNamespace();
inputStream.reset();
- if("ServiceException".equals(name) || "ExecuteResponse".equals(name)) {
+ if("ServiceException".equals(name) || "ExceptionReport".equals(name) || "ExecuteResponse".equals(name)) {
parseDocumentResponse(inputStream);
return;
}
@@ -143,6 +142,10 @@
if (object instanceof ExecuteResponseType)
{
exeResponse = (ExecuteResponseType) object;
+ // in case of exceptions let's be explicit about them
+ if(exeResponse.getStatus() != null && exeResponse.getStatus().getProcessFailed() != null) {
+ excepResponse = exeResponse.getStatus().getProcessFailed().getExceptionReport();
+ }
}
// exception caught on server and returned
else if (object instanceof ExceptionReportType)
Modified: trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java
===================================================================
--- trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java 2012-05-03 13:01:36 UTC (rev 38701)
+++ trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java 2012-05-04 15:22:05 UTC (rev 38702)
@@ -26,6 +26,7 @@
import java.util.List;
import net.opengis.ows11.ExceptionReportType;
+import net.opengis.ows11.ExceptionType;
import net.opengis.wps10.DataType;
import net.opengis.wps10.DocumentOutputDefinitionType;
import net.opengis.wps10.ExecuteResponseType;
@@ -933,4 +934,152 @@
System.out.println(arcgrid);
assertTrue(arcgrid.startsWith(expectedHeader));
}
+
+ /**
+ * Test exception parsing on invalid process request
+ *
+ * @throws ServiceException
+ * @throws IOException
+ * @throws ParseException
+ */
+ public void testInvalidProcess() throws ServiceException, IOException, ParseException
+ {
+
+ // don't run the test if the server is not up
+ if (fixture == null)
+ {
+ return;
+ }
+
+ if (DISABLE)
+ {
+ return;
+ }
+
+ String processIdenLocal = "gs:InvalidProcessName";
+
+ WPSCapabilitiesType capabilities = wps.getCapabilities();
+
+ // get the first process and execute it
+ ProcessOfferingsType processOfferings = capabilities.getProcessOfferings();
+ EList processes = processOfferings.getProcess();
+ // ProcessBriefType process = (ProcessBriefType) processes.get(0);
+
+ // does the server contain the specific process I want
+ boolean found = false;
+ Iterator iterator = processes.iterator();
+ while (iterator.hasNext())
+ {
+ ProcessBriefType process = (ProcessBriefType) iterator.next();
+ if (process.getIdentifier().getValue().equalsIgnoreCase(processIdenLocal))
+ {
+ found = true;
+
+ break;
+ }
+ }
+
+ // exit test if my process doesn't exist on server
+ if (found)
+ {
+ System.out.println("Skipping, gs:InvalidProcessName has been found!");
+ return;
+ }
+
+ // setup a fake call to fake process
+ ExecuteProcessRequest exeRequest = wps.createExecuteProcessRequest();
+ exeRequest.setIdentifier(processIdenLocal);
+ ResponseDocumentType doc = wps.createResponseDocumentType(false, true, true, "result");
+ DocumentOutputDefinitionType odt = (DocumentOutputDefinitionType) doc.getOutput().get(0);
+ odt.setMimeType("application/arcgrid");
+ odt.setAsReference(true);
+ ResponseFormType responseForm = wps.createResponseForm(doc, null);
+ exeRequest.setResponseForm(responseForm);
+
+ // send the request
+ ExecuteProcessResponse response = wps.issueRequest(exeRequest);
+
+ // response should not be null and no exception should occur.
+ assertNotNull(response);
+
+ // we should get an exception
+ ExceptionReportType report = response.getExceptionResponse();
+ assertNotNull(report);
+ ExceptionType exception = (ExceptionType) report.getException().get(0);
+ String errorMessage = exception.getExceptionText().get(0).toString();
+ assertTrue(errorMessage.contains(processIdenLocal));
+ }
+
+ /**
+ * Make sure we get the proper exception report
+ *
+ * @throws ServiceException
+ * @throws IOException
+ * @throws ParseException
+ */
+ public void testInvalidParamsRawOutput() throws ServiceException, IOException, ParseException
+ {
+
+ // don't run the test if the server is not up
+ if (fixture == null)
+ {
+ return;
+ }
+
+ if (DISABLE)
+ {
+ return;
+ }
+
+ String processIdenLocal = "gs:AreaGrid";
+
+ WPSCapabilitiesType capabilities = wps.getCapabilities();
+
+ // get the first process and execute it
+ ProcessOfferingsType processOfferings = capabilities.getProcessOfferings();
+ EList processes = processOfferings.getProcess();
+ // ProcessBriefType process = (ProcessBriefType) processes.get(0);
+
+ // does the server contain the specific process I want
+ boolean found = false;
+ Iterator iterator = processes.iterator();
+ while (iterator.hasNext())
+ {
+ ProcessBriefType process = (ProcessBriefType) iterator.next();
+ if (process.getIdentifier().getValue().equalsIgnoreCase(processIdenLocal))
+ {
+ found = true;
+
+ break;
+ }
+ }
+
+ // exit test if my process doesn't exist on server
+ if (!found)
+ {
+ System.out.println("Skipping, gs:AreaGrid not found!");
+ return;
+ }
+
+ // based on the describeprocess, setup the execute
+ ExecuteProcessRequest exeRequest = wps.createExecuteProcessRequest();
+ exeRequest.setIdentifier(processIdenLocal);
+ // don't send over the inputs
+ OutputDefinitionType rawOutput = wps.createOutputDefinitionType("result");
+ rawOutput.setMimeType("application/arcgrid");
+ ResponseFormType responseForm = wps.createResponseForm(null, rawOutput);
+ exeRequest.setResponseForm(responseForm);
+
+ // send the request
+ ExecuteProcessResponse response = wps.issueRequest(exeRequest);
+
+ // response should not be null and no exception should occur.
+ assertNotNull(response);
+
+ // we should get an exception here too
+ ExceptionReportType report = response.getExceptionResponse();
+ assertNotNull(report);
+ }
+
+
}
|