Author: aaime Date: 2012-03-19 09:19:55 -0700 (Mon, 19 Mar 2012) New Revision: 38637 Removed: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/AbstractGetExecutionStatusRequest.java trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/GetExecutionStatusRequest.java trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/GetExecutionStatusResponse.java Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/ows/AbstractWPS.java trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPS1_0_0.java trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPSSpecification.java trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WebProcessingService.java trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java Log: [GEOT-4084] GeoTools WPS client support for asynch requests is GeoServer specific Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/ows/AbstractWPS.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/ows/AbstractWPS.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/ows/AbstractWPS.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -53,7 +53,7 @@ { private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geotools.data.ows"); - private HTTPClient httpClient; + protected HTTPClient httpClient; protected final URL serverURL; protected C capabilities; protected ServiceInfo info; Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPS1_0_0.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPS1_0_0.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPS1_0_0.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -39,13 +39,10 @@ import org.geotools.data.ows.Response; import org.geotools.data.wps.request.AbstractDescribeProcessRequest; import org.geotools.data.wps.request.AbstractExecuteProcessRequest; -import org.geotools.data.wps.request.AbstractGetExecutionStatusRequest; import org.geotools.data.wps.request.DescribeProcessRequest; import org.geotools.data.wps.request.ExecuteProcessRequest; -import org.geotools.data.wps.request.GetExecutionStatusRequest; import org.geotools.data.wps.response.DescribeProcessResponse; import org.geotools.data.wps.response.ExecuteProcessResponse; -import org.geotools.data.wps.response.GetExecutionStatusResponse; import org.geotools.data.wps.response.WPSGetCapabilitiesResponse; import org.geotools.ows.ServiceException; @@ -118,13 +115,6 @@ } @Override - public GetExecutionStatusRequest createGetExecutionStatusRequest(URL onlineResource) - throws UnsupportedOperationException - { - return new InternalGetExecutionStatusRequest(onlineResource, null); - } - - @Override public DataType createLiteralInputValue(String literalValue) { DataType literalInputValue = wpsFactory.createDataType(); @@ -291,27 +281,4 @@ } - public static class InternalGetExecutionStatusRequest extends AbstractGetExecutionStatusRequest - { - - /** - * @param onlineResource - * @param properties - */ - public InternalGetExecutionStatusRequest(URL onlineResource, Properties properties) - { - super(onlineResource, properties); - } - - protected void initVersion() - { - setProperty(VERSION, "1.0.0"); - } - - public Response createResponse(HTTPResponse httpResponse) throws ServiceException, IOException - { - return new GetExecutionStatusResponse(httpResponse); - } - } - } Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPSSpecification.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPSSpecification.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WPSSpecification.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -27,7 +27,6 @@ import org.geotools.data.ows.Specification; import org.geotools.data.wps.request.DescribeProcessRequest; import org.geotools.data.wps.request.ExecuteProcessRequest; -import org.geotools.data.wps.request.GetExecutionStatusRequest; /** @@ -60,9 +59,6 @@ public abstract ExecuteProcessRequest createExecuteProcessRequest(URL onlineResource) throws UnsupportedOperationException; - public abstract GetExecutionStatusRequest createGetExecutionStatusRequest(URL onlineResource) - throws UnsupportedOperationException; - public abstract DataType createLiteralInputValue(String literalValue); public abstract DataType createBoundingBoxInputValue(String crs, int dimensions, List<Double> lowerCorner, Modified: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WebProcessingService.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WebProcessingService.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/WebProcessingService.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -16,7 +16,10 @@ */ package org.geotools.data.wps; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -43,13 +46,13 @@ import org.geotools.data.ows.AbstractWPSGetCapabilitiesResponse; import org.geotools.data.ows.GetCapabilitiesRequest; import org.geotools.data.ows.HTTPClient; +import org.geotools.data.ows.HTTPResponse; +import org.geotools.data.ows.Response; import org.geotools.data.ows.Specification; import org.geotools.data.wps.request.DescribeProcessRequest; import org.geotools.data.wps.request.ExecuteProcessRequest; -import org.geotools.data.wps.request.GetExecutionStatusRequest; import org.geotools.data.wps.response.DescribeProcessResponse; import org.geotools.data.wps.response.ExecuteProcessResponse; -import org.geotools.data.wps.response.GetExecutionStatusResponse; import org.geotools.ows.ServiceException; import org.geotools.wps.WPS; @@ -227,11 +230,15 @@ { return (ExecuteProcessResponse) internalIssueRequest(request); } - - public GetExecutionStatusResponse issueRequest(GetExecutionStatusRequest request) throws IOException, - ServiceException + + public ExecuteProcessResponse issueStatusRequest(URL statusURL) throws IOException, ServiceException { - return (GetExecutionStatusResponse) internalIssueRequest(request); + final HTTPResponse httpResponse; + + httpResponse = httpClient.get(statusURL); + + // a request with status can never use raw requests + return new ExecuteProcessResponse(httpResponse, false); } /** @@ -285,26 +292,6 @@ return request; } - public GetExecutionStatusRequest createGetExecutionStatusRequest() throws UnsupportedOperationException - { - ProcessOfferingsType processOfferings = getCapabilities().getProcessOfferings(); - if ((processOfferings == null) || !processOfferings.eAllContents().hasNext()) - { - throw new UnsupportedOperationException( - "Server does not specify a GetExecutionStatus operation. Cannot be performed."); - } - - URL onlineResource = getOperationURL("getexecutionstatus", capabilities, true); - if (onlineResource == null) - { - onlineResource = serverURL; - } - - GetExecutionStatusRequest request = getSpecification().createGetExecutionStatusRequest(onlineResource); - - return request; - } - private WPSSpecification getSpecification() { return (WPSSpecification) specification; Deleted: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/AbstractGetExecutionStatusRequest.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/AbstractGetExecutionStatusRequest.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/AbstractGetExecutionStatusRequest.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -1,59 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library 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; - * version 2.1 of the License. - * - * This library 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. - */ -package org.geotools.data.wps.request; - -import java.net.URL; -import java.util.Properties; - - -/** - * Describes an abstract GetExecutionStatus request. Provides everything except - * the versioning info, which subclasses must implement. - * - * @author afabiani - * - * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/AbstractGetExecutionStatusRequest $ - */ -public abstract class AbstractGetExecutionStatusRequest extends AbstractWPSRequest implements GetExecutionStatusRequest -{ - - /** - * Constructs a basic GetExecutionStatusRequest, without versioning info. - * - * @param onlineResource the location of the request - * @param properties a set of properties to use. Can be null. - */ - public AbstractGetExecutionStatusRequest(URL onlineResource, Properties properties) - { - super(onlineResource, properties); - } - - protected void initRequest() - { - setProperty(REQUEST, "GetExecutionStatus"); - } - - /** - * @see org.geotools.data.wps.request.GetExecutionStatusRequest#setIdentifier(java.lang.String) - */ - public void setIdentifier(String identifiers) - { - setProperty(IDENTIFIER, identifiers); - } - - protected abstract void initVersion(); -} Deleted: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/GetExecutionStatusRequest.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/GetExecutionStatusRequest.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/GetExecutionStatusRequest.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -1,45 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library 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; - * version 2.1 of the License. - * - * This library 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. - */ -package org.geotools.data.wps.request; - -import org.geotools.data.ows.Request; - - -/** - * Retrieves information about the given execution on - * the WPS Server. - * - * The only parameter it takes is a process which it uses to - * return the information about. - * - * @author afabiani - * - * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/request/GetExecutionStatusRequest.java $ - */ -public interface GetExecutionStatusRequest extends Request -{ - - /** Represents the PROCESS parameter */ - public static final String IDENTIFIER = "IDENTIFIER"; // $NON-NLS-1$ - - /** - * Sets the name of the process to look up - * - * @param processname A comma-delimited list of unique process names - */ - public void setIdentifier(String processnames); -} Deleted: trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/GetExecutionStatusResponse.java =================================================================== --- trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/GetExecutionStatusResponse.java 2012-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/GetExecutionStatusResponse.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -1,118 +0,0 @@ -/* - * GeoTools - The Open Source Java GIS Toolkit - * http://geotools.org - * - * (C) 2004-2008, Open Source Geospatial Foundation (OSGeo) - * - * This library 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; - * version 2.1 of the License. - * - * This library 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. - */ -package org.geotools.data.wps.response; - -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.parsers.ParserConfigurationException; - -import net.opengis.ows11.ExceptionReportType; -import net.opengis.wps10.ExecuteResponseType; - -import org.geotools.data.ows.HTTPResponse; -import org.geotools.data.ows.Response; -import org.geotools.ows.ServiceException; -import org.geotools.wps.WPSConfiguration; -import org.geotools.xml.Configuration; -import org.geotools.xml.Parser; -import org.xml.sax.SAXException; - - -/** - * Represents the response from a server after a DescribeProcess request - * has been issued. - * - * @author gdavis - * - * @source $URL: http://svn.osgeo.org/geotools/trunk/modules/unsupported/wps/src/main/java/org/geotools/data/wps/response/DescribeProcessResponse.java $ - */ -public class GetExecutionStatusResponse extends Response -{ - - private ExecuteResponseType exeResponse; - private ExceptionReportType excepResponse; - - /** - * @param contentType - * @param inputStream - * @throws ServiceException - * @throws SAXException - */ - public GetExecutionStatusResponse(HTTPResponse httpResponse) throws IOException, ServiceException - { - super(httpResponse); - - InputStream inputStream = null; - try - { - inputStream = httpResponse.getResponseStream(); - - // Map hints = new HashMap(); - // hints.put(DocumentHandler.DEFAULT_NAMESPACE_HINT_KEY, WPSSchema.getInstance()); - Configuration config = new WPSConfiguration(); - Parser parser = new Parser(config); - - Object object; - exeResponse = null; - excepResponse = null; - try - { - // object = DocumentFactory.getInstance(inputStream, hints, Level.WARNING); - object = parser.parse(inputStream); - } - catch (SAXException e) - { - throw (IOException) new IOException().initCause(e); - } - catch (ParserConfigurationException e) - { - throw (IOException) new IOException().initCause(e); - } - - // try casting the response - if (object instanceof ExecuteResponseType) - { - exeResponse = (ExecuteResponseType) object; - } - // exception caught on server and returned - else if (object instanceof ExceptionReportType) - { - excepResponse = (ExceptionReportType) object; - } - - } - finally - { - if (inputStream != null) - { - inputStream.close(); - } - } - } - - public ExecuteResponseType getExecuteResponse() - { - return exeResponse; - } - - public ExceptionReportType getExceptionResponse() - { - return excepResponse; - } - -} 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-03-19 14:36:02 UTC (rev 38636) +++ trunk/modules/unsupported/wps/src/test/java/org/geotools/data/wps/OnlineWPSManualRequestTest.java 2012-03-19 16:19:55 UTC (rev 38637) @@ -27,6 +27,7 @@ import net.opengis.ows11.ExceptionReportType; import net.opengis.wps10.DataType; +import net.opengis.wps10.DocumentOutputDefinitionType; import net.opengis.wps10.ExecuteResponseType; import net.opengis.wps10.InputDescriptionType; import net.opengis.wps10.LiteralDataType; @@ -36,6 +37,7 @@ import net.opengis.wps10.ProcessDescriptionType; import net.opengis.wps10.ProcessDescriptionsType; import net.opengis.wps10.ProcessOfferingsType; +import net.opengis.wps10.ResponseDocumentType; import net.opengis.wps10.ResponseFormType; import net.opengis.wps10.WPSCapabilitiesType; @@ -730,6 +732,7 @@ while((line = reader.readLine()) != null) { sb.append(line).append("\n"); } + reader.close(); String arcgrid = sb.toString(); String expectedHeader = "NCOLS 2\n" + "NROWS 1\n" + @@ -815,4 +818,119 @@ assertNotNull(executeResponse.getStatus().getProcessFailed()); assertNotNull( executeResponse.getStatus().getProcessFailed().getExceptionReport()); } + + /** + * Try to get an area grid with output in asynchronous mode + * + * @throws ServiceException + * @throws IOException + * @throws ParseException + */ + public void testExecuteAsynchAreaGrid() 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); + exeRequest.addInput("envelope", Arrays.asList(wps.createBoundingBoxInputValue("EPSG:4326", 2, Arrays.asList(-180d, -90d), Arrays.asList(180d, 90d)))); + exeRequest.addInput("width", Arrays.asList(wps.createLiteralInputValue("100"))); + exeRequest.addInput("height", Arrays.asList(wps.createLiteralInputValue("50"))); + 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 a raw response, no exception, no response document + ExecuteResponseType executeResponse = response.getExecuteResponse(); + assertNotNull(executeResponse); + + // loop and wait for the process to be complete + while(executeResponse.getStatus().getProcessFailed() == null + && executeResponse.getStatus().getProcessSucceeded() == null) { + + String location = executeResponse.getStatusLocation(); + URL url = new URL(location); + response = wps.issueStatusRequest(url); + + executeResponse = response.getExecuteResponse(); + assertNotNull(executeResponse); + } + + // check result correctness + assertEquals(1, executeResponse.getProcessOutputs().getOutput().size()); + OutputDataType output = (OutputDataType) executeResponse.getProcessOutputs().getOutput().get(0); + + assertEquals("result", output.getIdentifier().getValue()); + assertEquals("application/arcgrid", output.getReference().getMimeType()); + assertNotNull(output.getReference().getHref()); + + URL dataURL = new URL(output.getReference().getHref()); + BufferedReader reader = new BufferedReader(new InputStreamReader(dataURL.openStream())); + StringBuilder sb = new StringBuilder(); + String line = null; + int count = 0; + while((line = reader.readLine()) != null && count <= 5) { + sb.append(line).append("\n"); + count++; + } + reader.close(); + String arcgrid = sb.toString(); + String expectedHeader = "NCOLS 100\n" + + "NROWS 50\n" + + "XLLCORNER -180.0\n" + + "YLLCORNER -90.0\n" + + "CELLSIZE 3.6\n" + + "NODATA_VALUE -9999"; + System.out.println(arcgrid); + assertTrue(arcgrid.startsWith(expectedHeader)); + } } |