run a process in wps

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

run a process in wps

soshi
Hi everyone,
I wanna test SimpleBuffer.xml and SimpleBufferRemoteWFSPost.xml in wps client.
I have org.n52.wps.server.algorithm.SimpleBufferAlgorithm in my source code and I need to add client process to maven project, so I created WPSClientExample with org.n52.wps.client.example package in 52n-wps-client-lib (maven project in eclipse).
when I open SimpleBuffer.xml, in this part:

<wps:Input>
      <ows:Identifier>data</ows:Identifier>
      <wps:Reference schema="http://schemas.opengis.net/gml/3.1.1/base/feature.xsd" xlink:href="http://localhost:8080/geoserver/wfs?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=GetFeature&amp;TYPENAME=topp:tasmania_roads&amp;SRS=EPSG:4326&amp;OUTPUTFORMAT=GML3" method="GET"/>
    </wps:Input>

I got error:

<?xml version="1.0" encoding="UTF-8"?>

-<ows:ExceptionReport version="1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1">


-<ows:Exception locator="identifier=org.n52.wps.server.algorithm.SimpleBufferAlgorithm" exceptionCode="InvalidParameterValue">

<ows:ExceptionText>Specified process identifier does not exist</ows:ExceptionText>

</ows:Exception>


-<ows:Exception exceptionCode="JAVA_StackTrace">

<ows:ExceptionText>org.n52.wps.server.ExceptionReport: Specified process identifier does not exist at org.n52.wps.server.request.ExecuteRequest.validate(ExecuteRequest.java:525) at org.n52.wps.server.request.ExecuteRequest.<init>(ExecuteRequest.java:125) at org.n52.wps.server.handler.RequestHandler.<init>(RequestHandler.java:253) at org.n52.wps.server.WebProcessingService.doPost(WebProcessingService.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.n52.wps.server.WebProcessingService.service(WebProcessingService.java:362) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:410) at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:169) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:169) at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:232) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1096) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)</ows:ExceptionText>

</ows:Exception>

<ows:Exception exceptionCode="JAVA_RootCause"/>

</ows:ExceptionReport>

what should I do?
please help me,
thanks in advance..


WPSClientExample class:

/**
 * Copyright (C) 2007 - 2016 52°North Initiative for Geospatial Open Source
 * Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.n52.wps.client.example;

import java.io.IOException;
import java.util.HashMap;

import net.opengis.wps.x100.CapabilitiesDocument;
import net.opengis.wps.x100.ExecuteDocument;
import net.opengis.wps.x100.ExecuteResponseDocument;
import net.opengis.wps.x100.InputDescriptionType;
import net.opengis.wps.x100.ProcessBriefType;
import net.opengis.wps.x100.ProcessDescriptionType;

import org.geotools.feature.FeatureCollection;
import org.n52.wps.client.ExecuteResponseAnalyser;
import org.n52.wps.client.WPSClientException;
import org.n52.wps.client.WPSClientSession;
import org.n52.wps.io.data.IData;
import org.n52.wps.io.data.binding.complex.GTVectorDataBinding;

public class WPSClientExample {

    public void testExecute() {

        String wpsURL = "http://localhost:8080/wps/WebProcessingService";

        String processID = "org.n52.wps.server.algorithm.SimpleBufferAlgorithm";

        try {
            ProcessDescriptionType describeProcessDocument = requestDescribeProcess(
                    wpsURL, processID);
            System.out.println(describeProcessDocument);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            CapabilitiesDocument capabilitiesDocument = requestGetCapabilities(wpsURL);
            ProcessDescriptionType describeProcessDocument = requestDescribeProcess(
                    wpsURL, processID);
            // define inputs
            HashMap<String, Object> inputs = new HashMap<String, Object>();
            // complex data by reference
            inputs.put(
                    "data",
                    "http://geoprocessing.demo.52north.org:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:tasmania_roads&outputFormat=GML3");
            // literal data
            inputs.put("width", "0.05");
            IData data = executeProcess(wpsURL, processID,
                    describeProcessDocument, inputs);

            if (data instanceof GTVectorDataBinding) {
                FeatureCollection featureCollection = ((GTVectorDataBinding) data)
                        .getPayload();
                System.out.println(featureCollection.size());
            }
        } catch (WPSClientException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public CapabilitiesDocument requestGetCapabilities(String url)
            throws WPSClientException {

        WPSClientSession wpsClient = WPSClientSession.getInstance();

        wpsClient.connect(url);

        CapabilitiesDocument capabilities = wpsClient.getWPSCaps(url);

        ProcessBriefType[] processList = capabilities.getCapabilities()
                .getProcessOfferings().getProcessArray();

        for (ProcessBriefType process : processList) {
            System.out.println(process.getIdentifier().getStringValue());
        }
        return capabilities;
    }

    public ProcessDescriptionType requestDescribeProcess(String url,
            String processID) throws IOException {

        WPSClientSession wpsClient = WPSClientSession.getInstance();

        ProcessDescriptionType processDescription = wpsClient
                .getProcessDescription(url, processID);

        InputDescriptionType[] inputList = processDescription.getDataInputs()
                .getInputArray();

        for (InputDescriptionType input : inputList) {
            System.out.println(input.getIdentifier().getStringValue());
        }
        return processDescription;
    }

    public IData executeProcess(String url, String processID,
            ProcessDescriptionType processDescription,
            HashMap<String, Object> inputs) throws Exception {
        org.n52.wps.client.ExecuteRequestBuilder executeBuilder = new org.n52.wps.client.ExecuteRequestBuilder(
                processDescription);

        for (InputDescriptionType input : processDescription.getDataInputs()
                .getInputArray()) {
            String inputName = input.getIdentifier().getStringValue();
            Object inputValue = inputs.get(inputName);
            if (input.getLiteralData() != null) {
                if (inputValue instanceof String) {
                    executeBuilder.addLiteralData(inputName,
                            (String) inputValue);
                }
            } else if (input.getComplexData() != null) {
                // Complexdata by value
                if (inputValue instanceof FeatureCollection) {
                    IData data = new GTVectorDataBinding(
                            (FeatureCollection) inputValue);
                    executeBuilder
                            .addComplexData(
                                    inputName,
                                    data,
                                    "http://schemas.opengis.net/gml/3.1.1/base/feature.xsd",
                                    null, "text/xml");
                }
                // Complexdata Reference
                if (inputValue instanceof String) {
                    executeBuilder
                            .addComplexDataReference(
                                    inputName,
                                    (String) inputValue,
                                    "http://schemas.opengis.net/gml/3.1.1/base/feature.xsd",
                                    null, "text/xml");
                }

                if (inputValue == null && input.getMinOccurs().intValue() > 0) {
                    throw new IOException("Property not set, but mandatory: "
                            + inputName);
                }
            }
        }
        executeBuilder.setMimeTypeForOutput("text/xml", "result");
        executeBuilder.setSchemaForOutput(
                "http://schemas.opengis.net/gml/3.1.1/base/feature.xsd",
                "result");
        ExecuteDocument execute = executeBuilder.getExecute();
        execute.getExecute().setService("WPS");
        WPSClientSession wpsClient = WPSClientSession.getInstance();
        Object responseObject = wpsClient.execute(url, execute);
        if (responseObject instanceof ExecuteResponseDocument) {
            ExecuteResponseDocument response = (ExecuteResponseDocument) responseObject;
            ExecuteResponseAnalyser analyser = new ExecuteResponseAnalyser(
                    execute, response, processDescription);
            IData data = (IData) analyser.getComplexDataByIndex(0,
                    GTVectorDataBinding.class);
            return data;
        }
        throw new Exception("Exception: " + responseObject.toString());
    }

    public static void main(String[] args) {
        WPSClientExample client = new WPSClientExample();
        client.testExecute();
    }

}
Reply | Threaded
Open this post in threaded view
|

Re: run a process in wps

BenjaminPross
Hi,

It seems that the process is not available in the WPS. Could you attach the Capabilities of the WPS? You should be able to get them using the following URL:

http://localhost:8080/wps/WebProcessingService?Request=GetCapabilities&Service=WPS

Further questions: Where did you get the WPS from? Did you compile it yourself?

Cheers,

Benjamin

Reply | Threaded
Open this post in threaded view
|

Re: run a process in wps

soshi
Hi dear,
yes, you're right. there isn't the process in Getcapabilities response.
I got wps source code from github (version:3.6.2) and import it as maven project in eclipse and then compile it. how can I sovle this problem? any solution..
I'm newbie in this subject,
please help me,
thanks in advance...

GetCapabilities response:


<?xml version="1.0" encoding="UTF-8"?>

-<wps:Capabilities xml:lang="en-US" updateSequence="1" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd" version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink">


-<ows:ServiceIdentification>

<ows:Title>52°North WPS 3.6.2-SNAPSHOT</ows:Title>

<ows:Abstract>Service based on the 52°North implementation of WPS 1.0.0</ows:Abstract>


-<ows:Keywords>

<ows:Keyword>WPS</ows:Keyword>

<ows:Keyword>geospatial</ows:Keyword>

<ows:Keyword>geoprocessing</ows:Keyword>

</ows:Keywords>

<ows:ServiceType>WPS</ows:ServiceType>

<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>

<ows:Fees>NONE</ows:Fees>

<ows:AccessConstraints>NONE</ows:AccessConstraints>

</ows:ServiceIdentification>


-<ows:ServiceProvider>

<ows:ProviderName>52North</ows:ProviderName>

<ows:ProviderSite xlink:href="http://www.52north.org/"/>


-<ows:ServiceContact>

<ows:IndividualName>Your name</ows:IndividualName>

<ows:PositionName>Your position</ows:PositionName>


-<ows:ContactInfo>


-<ows:Phone>

<ows:Voice/>

<ows:Facsimile/>

</ows:Phone>


-<ows:Address>

<ows:DeliveryPoint/>

<ows:City/>

<ows:AdministrativeArea/>

<ows:PostalCode/>

<ows:Country/>

<ows:ElectronicMailAddress/>

</ows:Address>

</ows:ContactInfo>

</ows:ServiceContact>

</ows:ServiceProvider>


-<ows:OperationsMetadata>


-<ows:Operation name="GetCapabilities">


-<ows:DCP>


-<ows:HTTP>

<ows:Get xlink:href="http://localhost:8080/wps/WebProcessingService?"/>

<ows:Post xlink:href="http://localhost:8080/wps/WebProcessingService"/>

</ows:HTTP>

</ows:DCP>

</ows:Operation>


-<ows:Operation name="DescribeProcess">


-<ows:DCP>


-<ows:HTTP>

<ows:Get xlink:href="http://localhost:8080/wps/WebProcessingService?"/>

<ows:Post xlink:href="http://localhost:8080/wps/WebProcessingService"/>

</ows:HTTP>

</ows:DCP>

</ows:Operation>


-<ows:Operation name="Execute">


-<ows:DCP>


-<ows:HTTP>

<ows:Get xlink:href="http://localhost:8080/wps/WebProcessingService?"/>

<ows:Post xlink:href="http://localhost:8080/wps/WebProcessingService"/>

</ows:HTTP>

</ows:DCP>

</ows:Operation>

</ows:OperationsMetadata>


-<wps:ProcessOfferings>


-<wps:Process wps:processVersion="1.1.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.MultiReferenceInputAlgorithm</ows:Identifier>

<ows:Title>for testing multiple inputs by reference</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.EchoProcess</ows:Identifier>

<ows:Title>Echo process</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.process.ExtensionAlgorithm</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.process.ExtensionAlgorithm</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.1.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.MultiReferenceBinaryInputAlgorithm</ows:Identifier>

<ows:Title>for testing multiple binary inputs by reference</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.LongRunningDummyTestClass</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.test.LongRunningDummyTestClass</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.1.0">

<ows:Identifier>org.n52.wps.server.algorithm.JTSConvexHullAlgorithm</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.JTSConvexHullAlgorithm</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.test.MultipleComplexInAndOutputsDummyTestClass</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.process.JTSBufferAlgorithm</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.process.JTSBufferAlgorithm</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.demo.ImageInhance</ows:Identifier>

<ows:Title>org.n52.wps.demo.ImageInhance</ows:Title>

</wps:Process>


-<wps:Process wps:processVersion="1.0.0">

<ows:Identifier>org.n52.wps.server.algorithm.test.DummyTestClass</ows:Identifier>

<ows:Title>org.n52.wps.server.algorithm.test.DummyTestClass</ows:Title>

</wps:Process>

</wps:ProcessOfferings>


-<wps:Languages>


-<wps:Default>

<ows:Language>en-US</ows:Language>

</wps:Default>


-<wps:Supported>

<ows:Language>en-US</ows:Language>

</wps:Supported>

</wps:Languages>

</wps:Capabilities>