Search in sources :

Example 1 with WebProcessingClient

use of org.geotoolkit.wps.client.WebProcessingClient in project geotoolkit by Geomatys.

the class WPSClientDemo method main.

public static void main(String[] args) throws Exception {
    // force loading all image readers/writers
    ImageIO.scanForPlugins();
    // global initialization
    Setup.initialize(null);
    // Instantiate client :
    final URL wpsURL = new URL(SERVICE_URL);
    final WebProcessingClient wpsClient = new WebProcessingClient(wpsURL, WPSVersion.v100.getCode());
    // Once initialized, we can ask a description of wanted process, using its id.
    final WPSProcessingRegistry registry = new WPSProcessingRegistry(wpsClient);
    ProcessDescriptor desc = registry.getDescriptor(PROCESS_ID);
    // We can check process input & output.
    ParameterDescriptorGroup inputDesc = desc.getInputDescriptor();
    ParameterDescriptorGroup outputDesc = desc.getOutputDescriptor();
    // Iterate on wanted parameters. If one is missing, an exception is raised.
    LOGGER.log(Level.INFO, "INPUT : \n");
    for (INPUT in : INPUT.values()) {
        final GeneralParameterDescriptor current = inputDesc.descriptor(in.name);
        LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
    }
    LOGGER.log(Level.INFO, "OUTPUT : \n");
    for (OUTPUT out : OUTPUT.values()) {
        final GeneralParameterDescriptor current = outputDesc.descriptor(out.name);
        LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
    }
    GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
    Geometry geometry = factory.toGeometry(new Envelope(1.0, 2.0, 43.3, 43.9));
    geometry.setUserData(CommonCRS.WGS84.geographic());
    final double bufDistance = 0.5;
    // Instantiate inputs. Those objects get the same behaviour that the descriptors. If we cannot find a specific
    // parameter, an exception is thrown.
    ParameterValueGroup input = inputDesc.createValue();
    input.parameter(INPUT.geom.name).setValue(geometry);
    input.parameter(INPUT.distance.name).setValue(bufDistance);
    // Process execution. It's synchronous here (talking only of client side, WPS can execute asynchronous process).
    // For asynchronous execution, we must execute it in a thread, using a process listener to get process state.
    org.geotoolkit.process.Process toExecute = desc.createProcess(input);
    toExecute.addListener(new NullProgressListener());
    ParameterValueGroup output = toExecute.call();
    // Get output values :
    for (OUTPUT out : OUTPUT.values()) {
        LOGGER.log(Level.INFO, String.format("%s parameter value : %s", out.name(), output.parameter(out.name).getValue()));
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) Envelope(org.locationtech.jts.geom.Envelope) URL(java.net.URL) WPSProcessingRegistry(org.geotoolkit.wps.client.process.WPSProcessingRegistry) Geometry(org.locationtech.jts.geom.Geometry) NullProgressListener(org.geotoolkit.util.NullProgressListener) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Example 2 with WebProcessingClient

use of org.geotoolkit.wps.client.WebProcessingClient in project geotoolkit by Geomatys.

the class GetCapabilitiesTest method testGetCapabilities110.

/**
 * Ensures the {@link GetCapabilities110#getURL()} method returns a well-built url,
 * with the parameters given.
 */
@Test
public void testGetCapabilities110() throws MalformedURLException {
    final WebProcessingClient client = new WebProcessingClient(new URL("http://test.com"), null, WPSVersion.v100);
    final URL url;
    try {
        url = client.createGetCapabilities().getURL();
    } catch (MalformedURLException ex) {
        fail(ex.getLocalizedMessage());
        return;
    }
    final String expectedURL = "http://test.com?SERVICE=WPS&ACCEPTVERSIONS=1.0.0&REQUEST=GetCapabilities";
    new URLComparator(expectedURL, url).compare();
}
Also used : MalformedURLException(java.net.MalformedURLException) URLComparator(org.geotoolkit.test.URLComparator) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) URL(java.net.URL) Test(org.junit.Test)

Example 3 with WebProcessingClient

use of org.geotoolkit.wps.client.WebProcessingClient in project geotoolkit by Geomatys.

the class DescribeProcessTest method testRequestAndMarshall.

@Test
public void testRequestAndMarshall() throws Exception {
    final WebProcessingClient client = new WebProcessingClient(new URL("http://test.com"), null, WPSVersion.v100);
    final DescribeProcessRequest request = client.createDescribeProcess();
    final DescribeProcess content = request.getContent();
    content.setIdentifier(Arrays.asList("identifier1", "identifier2", "identifier3"));
    final StringWriter stringWriter = new StringWriter();
    final Marshaller marshaller = WPSMarshallerPool.getInstance().acquireMarshaller();
    marshaller.marshal(content, stringWriter);
    String result = stringWriter.toString();
    final String expectedMarshalledRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<wps:DescribeProcess version=\"1.0.0\" service=\"WPS\"" + " xmlns:wps=\"http://www.opengis.net/wps/1.0.0\"" + " xmlns:ows=\"http://www.opengis.net/ows/1.1\">\n" + "    <ows:Identifier>identifier1</ows:Identifier>\n" + "    <ows:Identifier>identifier2</ows:Identifier>\n" + "    <ows:Identifier>identifier3</ows:Identifier>\n" + "</wps:DescribeProcess>\n";
    assertXmlEquals(expectedMarshalledRequest, result, "xmlns:*");
    WPSMarshallerPool.getInstance().recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) DescribeProcess(org.geotoolkit.wps.xml.v200.DescribeProcess) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) DescribeProcessRequest(org.geotoolkit.wps.client.DescribeProcessRequest) URL(java.net.URL) Test(org.junit.Test)

Example 4 with WebProcessingClient

use of org.geotoolkit.wps.client.WebProcessingClient in project geotoolkit by Geomatys.

the class DescribeProcessTest method testDescribeProcess110.

/**
 * Ensures the {@link DescribeProcess#getURL()} method returns a well-built url,
 * with the parameters given.
 */
@Test
public void testDescribeProcess110() throws MalformedURLException {
    final WebProcessingClient client = new WebProcessingClient(new URL("http://test.com"), null, WPSVersion.v100);
    final DescribeProcessRequest request = client.createDescribeProcess();
    final DescribeProcess content = request.getContent();
    content.setIdentifier(Arrays.asList("identifier1", "identifier2", "identifier3"));
    final URL url;
    try {
        url = request.getURL();
    } catch (MalformedURLException ex) {
        fail(ex.getLocalizedMessage());
        return;
    }
    final String strUrl = url.toString();
    // final String expectedURL = "http://test.com?VERSION=1.0.0&SERVICE=WPS&REQUEST=DescribeProcess&IDENTIFIER=identifier1,identifier2,identifier3";
    assertTrue(strUrl.contains("VERSION=1.0.0"));
    assertTrue(strUrl.contains("SERVICE=WPS"));
    assertTrue(strUrl.contains("REQUEST=DescribeProcess"));
    assertTrue(strUrl.contains("IDENTIFIER=identifier1%2Cidentifier2%2Cidentifier3"));
}
Also used : MalformedURLException(java.net.MalformedURLException) DescribeProcess(org.geotoolkit.wps.xml.v200.DescribeProcess) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) DescribeProcessRequest(org.geotoolkit.wps.client.DescribeProcessRequest) URL(java.net.URL) Test(org.junit.Test)

Example 5 with WebProcessingClient

use of org.geotoolkit.wps.client.WebProcessingClient in project geotoolkit by Geomatys.

the class ExecuteTest method testRequestAndMarshall.

@Test
public void testRequestAndMarshall() throws Exception {
    final WebProcessingClient client = new WebProcessingClient(new URL("http://test.com"), null, WPSVersion.v100);
    final ExecuteRequest request = client.createExecute();
    final Execute execute = request.getContent();
    final GeographicCRS epsg4326 = CommonCRS.WGS84.geographic();
    final GeneralEnvelope env = new GeneralEnvelope(epsg4326);
    env.setRange(0, 10, 10);
    env.setRange(1, 10, 10);
    execute.setIdentifier("identifier");
    final List<DataInput> inputs = execute.getInput();
    inputs.add(new DataInput("literal", new Data(new LiteralValue("10", null, null))));
    inputs.add(new DataInput("bbox", new Data(new BoundingBoxType(env))));
    inputs.add(new DataInput("complex", new Data(new Format("UTF-8", WPSMimeType.APP_GML.val(), WPSSchema.OGC_GML_3_1_1.getValue(), null), new PointType(new DirectPosition2D(epsg4326, 0, 0)))));
    inputs.add(new DataInput("reference", new Reference("http://link.to/reference/", null, null)));
    execute.getOutput().add(new OutputDefinition("output", false));
    assertEquals("WPS", execute.getService());
    assertEquals("1.0.0", execute.getVersion().toString());
    assertEquals(execute.getIdentifier().getValue(), "identifier");
    final StringWriter stringWriter = new StringWriter();
    final Marshaller marshaller = WPSMarshallerPool.getInstance().acquireMarshaller();
    marshaller.marshal(execute, stringWriter);
    String result = stringWriter.toString();
    try (final InputStream expected = expectedRequest()) {
        assertXmlEquals(expected, result, "xmlns:*", "crs", "srsName");
    }
    WPSMarshallerPool.getInstance().recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) Execute(org.geotoolkit.wps.xml.v200.Execute) Reference(org.geotoolkit.wps.xml.v200.Reference) InputStream(java.io.InputStream) Data(org.geotoolkit.wps.xml.v200.Data) LiteralValue(org.geotoolkit.wps.xml.v200.LiteralValue) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) URL(java.net.URL) DataInput(org.geotoolkit.wps.xml.v200.DataInput) BoundingBoxType(org.geotoolkit.ows.xml.v200.BoundingBoxType) ExecuteRequest(org.geotoolkit.wps.client.ExecuteRequest) Format(org.geotoolkit.wps.xml.v200.Format) StringWriter(java.io.StringWriter) PointType(org.geotoolkit.gml.xml.v321.PointType) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) OutputDefinition(org.geotoolkit.wps.xml.v200.OutputDefinition) Test(org.junit.Test)

Aggregations

URL (java.net.URL)6 WebProcessingClient (org.geotoolkit.wps.client.WebProcessingClient)6 Test (org.junit.Test)5 StringWriter (java.io.StringWriter)3 Marshaller (javax.xml.bind.Marshaller)3 MalformedURLException (java.net.MalformedURLException)2 DescribeProcessRequest (org.geotoolkit.wps.client.DescribeProcessRequest)2 DescribeProcess (org.geotoolkit.wps.xml.v200.DescribeProcess)2 InputStream (java.io.InputStream)1 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 PointType (org.geotoolkit.gml.xml.v321.PointType)1 BoundingBoxType (org.geotoolkit.ows.xml.v200.BoundingBoxType)1 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)1 URLComparator (org.geotoolkit.test.URLComparator)1 NullProgressListener (org.geotoolkit.util.NullProgressListener)1 ExecuteRequest (org.geotoolkit.wps.client.ExecuteRequest)1 GetCapabilitiesRequest (org.geotoolkit.wps.client.GetCapabilitiesRequest)1 WPSProcessingRegistry (org.geotoolkit.wps.client.process.WPSProcessingRegistry)1