From 18bd8f5f32f4dcc288bf91951ec103f489f81d44 Mon Sep 17 00:00:00 2001 From: "D. Baum" Date: Tue, 20 Dec 2016 13:21:17 +0100 Subject: [PATCH 1/2] Fixing deegree bug #788: make the WPS client use URI instead of URL --- .../wps/client/input/BinaryInput.java | 18 +++--- .../wps/client/input/ExecutionInput.java | 8 +-- .../protocol/wps/client/input/XMLInput.java | 18 +++--- .../process/AbstractProcessExecution.java | 13 ++-- .../wps100/ExecuteRequest100Writer.java | 6 +- .../protocol/wps/client/WPSClientTest.java | 64 +++++++++++++++---- 6 files changed, 82 insertions(+), 45 deletions(-) diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/BinaryInput.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/BinaryInput.java index 0a7d0dd298..96f6a38186 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/BinaryInput.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/BinaryInput.java @@ -37,7 +37,7 @@ import java.io.IOException; import java.io.InputStream; -import java.net.URL; +import java.net.URI; import org.deegree.commons.tom.ows.CodeType; import org.deegree.protocol.wps.client.param.ComplexFormat; @@ -55,7 +55,7 @@ public class BinaryInput extends ExecutionInput { private ComplexFormat complexAttributes; - private URL url; + private URI uri; private InputStream inputStream; @@ -66,8 +66,8 @@ public class BinaryInput extends ExecutionInput { * * @param id * parameter identifier, must not be null - * @param url - * URL for accessing the binary resource, must not be null + * @param uri + * URI for accessing the binary resource, must not be null * @param isWebAccessible * if true, the data will be submitted to the process as reference, otherwise it will be encoded in the * request @@ -76,9 +76,9 @@ public class BinaryInput extends ExecutionInput { * @param encoding * encoding to be used for the binary data, may be null (unspecified) */ - public BinaryInput( CodeType id, URL url, boolean isWebAccessible, String mimeType, String encoding ) { + public BinaryInput( CodeType id, URI uri, boolean isWebAccessible, String mimeType, String encoding ) { super( id ); - this.url = url; + this.uri = uri; this.isWebAccessible = isWebAccessible; this.complexAttributes = new ComplexFormat( mimeType, encoding, null ); } @@ -122,11 +122,11 @@ public InputStream getAsBinaryStream() if ( inputStream != null ) { return inputStream; } - return url.openStream(); + return uri.toURL().openStream(); } @Override - public URL getWebAccessibleURL() { - return isWebAccessible ? url : null; + public URI getWebAccessibleURI() { + return isWebAccessible ? uri : null; } } diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/ExecutionInput.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/ExecutionInput.java index 0a0a013276..af35988337 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/ExecutionInput.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/ExecutionInput.java @@ -35,7 +35,7 @@ ----------------------------------------------------------------------------*/ package org.deegree.protocol.wps.client.input; -import java.net.URL; +import java.net.URI; import org.deegree.commons.tom.ows.CodeType; @@ -72,11 +72,11 @@ public CodeType getId() { } /** - * Returns the web-accessible URL for retrieving the input value. + * Returns the web-accessible URI for retrieving the input value. * - * @return web-accessible URL, can be null (not web-acessible) + * @return web-accessible URI, can be null (not web-acessible) */ - public URL getWebAccessibleURL() { + public URI getWebAccessibleURI() { return null; } } diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/XMLInput.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/XMLInput.java index edd9459605..471b968045 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/XMLInput.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/input/XMLInput.java @@ -38,7 +38,7 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import java.io.IOException; -import java.net.URL; +import java.net.URI; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; @@ -62,7 +62,7 @@ public class XMLInput extends ExecutionInput { private final ComplexFormat complexAttribs; - private URL url; + private URI uri; private XMLStreamReader reader; @@ -73,8 +73,8 @@ public class XMLInput extends ExecutionInput { * * @param id * parameter identifier, must not be null - * @param url - * URL for accessing the XML resource, must not be null + * @param uri + * URI for accessing the XML resource, must not be null * @param isWebAccessible * if true, the data will be submitted to the process as reference, otherwise it will be encoded in the * request @@ -85,9 +85,9 @@ public class XMLInput extends ExecutionInput { * @param schema * XML schema, may be null (unspecified) */ - public XMLInput( CodeType id, URL url, boolean isWebAccessible, String mimeType, String encoding, String schema ) { + public XMLInput( CodeType id, URI uri, boolean isWebAccessible, String mimeType, String encoding, String schema ) { super( id ); - this.url = url; + this.uri = uri; this.isWebAccessible = isWebAccessible; this.complexAttribs = new ComplexFormat( mimeType, encoding, schema ); @@ -139,7 +139,7 @@ public XMLStreamReader getAsXMLStream() throws XMLStreamException, IOException { if ( reader == null ) { XMLInputFactory inFactory = XMLInputFactory.newInstance(); - reader = inFactory.createXMLStreamReader( url.openStream() ); + reader = inFactory.createXMLStreamReader( uri.toURL().openStream() ); } if ( reader.getEventType() == XMLStreamConstants.START_DOCUMENT ) { XMLStreamUtils.nextElement( reader ); @@ -148,7 +148,7 @@ public XMLStreamReader getAsXMLStream() } @Override - public URL getWebAccessibleURL() { - return isWebAccessible ? url : null; + public URI getWebAccessibleURI() { + return isWebAccessible ? uri : null; } } diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/process/AbstractProcessExecution.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/process/AbstractProcessExecution.java index 18ec24f4a5..17b85b830a 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/process/AbstractProcessExecution.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/process/AbstractProcessExecution.java @@ -36,6 +36,7 @@ package org.deegree.protocol.wps.client.process; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -136,7 +137,7 @@ public void addBBoxInput( String id, String idCodeSpace, double[] lower, double[ * identifier of the input parameter, must not be null * @param idCodeSpace * codespace of the parameter identifier, may be null (for identifiers without codespace) - * @param url + * @param uri * {@link URL} reference to the xml resource, must not be null * @param byRef * if true, the parameter will be passed by reference to the server, otherwise it will be nested in the @@ -151,9 +152,9 @@ public void addBBoxInput( String id, String idCodeSpace, double[] lower, double[ * schema, may be null (indicates that the default schema from the parameter description * applies) */ - public void addXMLInput( String id, String idCodeSpace, URL url, boolean byRef, String mimeType, String encoding, + public void addXMLInput( String id, String idCodeSpace, URI uri, boolean byRef, String mimeType, String encoding, String schema ) { - inputs.add( new XMLInput( new CodeType( id, idCodeSpace ), url, byRef, mimeType, encoding, schema ) ); + inputs.add( new XMLInput( new CodeType( id, idCodeSpace ), uri, byRef, mimeType, encoding, schema ) ); } /** @@ -188,7 +189,7 @@ public void addXMLInput( String id, String idCodeSpace, XMLStreamReader reader, * identifier of the input parameter, must not be null * @param idCodeSpace * codespace of the parameter identifier, may be null (for identifiers without codespace) - * @param url + * @param uri * {@link URL} reference to the binary resource, must not be null (and must not be * web-accessible) * @param byRef @@ -201,8 +202,8 @@ public void addXMLInput( String id, String idCodeSpace, XMLStreamReader reader, * encoding, may be null (indicates that the default encoding from the parameter description * applies) */ - public void addBinaryInput( String id, String idCodeSpace, URL url, boolean byRef, String mimeType, String encoding ) { - inputs.add( new BinaryInput( new CodeType( id, idCodeSpace ), url, byRef, mimeType, encoding ) ); + public void addBinaryInput( String id, String idCodeSpace, URI uri, boolean byRef, String mimeType, String encoding ) { + inputs.add( new BinaryInput( new CodeType( id, idCodeSpace ), uri, byRef, mimeType, encoding ) ); } /** diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/wps100/ExecuteRequest100Writer.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/wps100/ExecuteRequest100Writer.java index 69b08d55e0..6608730320 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/wps100/ExecuteRequest100Writer.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/main/java/org/deegree/protocol/wps/client/wps100/ExecuteRequest100Writer.java @@ -41,7 +41,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.util.List; import javax.xml.stream.XMLStreamException; @@ -49,7 +48,6 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.axiom.util.base64.Base64EncodingOutputStream; -import org.apache.commons.codec.binary.Base64; import org.deegree.commons.tom.ows.CodeType; import org.deegree.commons.xml.XMLAdapter; import org.deegree.protocol.wps.client.input.BBoxInput; @@ -223,10 +221,10 @@ private void writeInputs( List inputList ) writer.writeStartElement( wpsPrefix, "Input", wpsNS ); writeIdentifier( dataInput.getId() ); - if ( dataInput.getWebAccessibleURL() != null ) { + if ( dataInput.getWebAccessibleURI() != null ) { writer.writeStartElement( wpsPrefix, "Reference", wpsNS ); writer.writeAttribute( XLINK_PREFIX, XLNNS, "href", - dataInput.getWebAccessibleURL().toExternalForm() ); + dataInput.getWebAccessibleURI().toASCIIString() ); if ( dataInput instanceof XMLInput ) { writeComplexAttributes( ( (XMLInput) dataInput ).getFormat() ); } diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/test/java/org/deegree/protocol/wps/client/WPSClientTest.java b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/test/java/org/deegree/protocol/wps/client/WPSClientTest.java index 645f8ca348..72bcc4a9fc 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/test/java/org/deegree/protocol/wps/client/WPSClientTest.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-commons/src/test/java/org/deegree/protocol/wps/client/WPSClientTest.java @@ -43,6 +43,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; @@ -318,7 +321,7 @@ public void testExecute_1() WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "Centroid", null ); ProcessExecution execution = proc.prepareExecution(); - execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); + execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addOutput( "Centroid", null, null, true, null, null, null ); ExecutionOutputs response = execution.execute(); assertEquals( ExecutionState.SUCCEEDED, execution.getState() ); @@ -348,7 +351,7 @@ public void testExecute_2() ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "BufferDistance", null, "0.1", "double", "unity" ); - execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); + execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addOutput( "BufferedGeometry", null, null, false, null, null, null ); ExecutionOutputs outputs = execution.execute(); @@ -373,8 +376,8 @@ public void testExecute_3() ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); - execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); - execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI().toURL(), false, "image/png", null ); + execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); + execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); ExecutionOutputs outputs = execution.execute(); LiteralOutput out1 = (LiteralOutput) outputs.get( 0 ); @@ -400,8 +403,8 @@ public void testExecute_4() ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); - execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); - execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI().toURL(), false, "image/png", null ); + execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); + execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); execution.addOutput( "BBOXOutput", null, null, false, null, null, null ); ExecutionOutputs outputs = execution.execute(); @@ -427,8 +430,8 @@ public void testExecuteRawOutput() RawProcessExecution execution = proc.prepareRawExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); - execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); - execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI().toURL(), false, "image/png", null ); + execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); + execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); ComplexOutput out = execution.executeComplexOutput( "BinaryOutput", null, "image/png", null, null ); InputStream stream = out.getAsBinaryStream(); @@ -444,7 +447,7 @@ public void testExecuteRawOutput() @Test public void testExecuteInputsByRef() - throws OWSExceptionReport, IOException, XMLStreamException { + throws OWSExceptionReport, IOException, XMLStreamException, URISyntaxException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); @@ -454,8 +457,8 @@ public void testExecuteInputsByRef() execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); // use the process's GetCapabilities document as XML input because we can be sure it's available - execution.addXMLInput( "XMLInput", null, new URL( demoWPSURL ), true, "text/xml", null, null ); - execution.addBinaryInput( "BinaryInput", null, new URL( REMOTE_BINARY_INPUT ), true, "image/png", null ); + execution.addXMLInput( "XMLInput", null, new URI( demoWPSURL ), true, "text/xml", null, null ); + execution.addBinaryInput( "BinaryInput", null, new URI( REMOTE_BINARY_INPUT ), true, "image/png", null ); ExecutionOutputs outputs = execution.execute(); LiteralOutput out1 = (LiteralOutput) outputs.get( 0 ); @@ -529,8 +532,8 @@ public void testExecuteAsync() ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "5", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); - execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI().toURL(), false, "text/xml", null, null ); - execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI().toURL(), false, "image/png", null ); + execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); + execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); execution.executeAsync(); Assert.assertNotSame( ExecutionState.SUCCEEDED, execution.getState() ); @@ -622,4 +625,39 @@ public void testFailedExecute_2() execution.executeAsync(); Assert.assertTrue(execution.getState() != ExecutionState.SUCCEEDED); // we shouldn't arrive here } + + @Test + public void testURIInput() + throws MalformedURLException, OWSExceptionReport, IOException, XMLStreamException, + InterruptedException, URISyntaxException { + + String demoWPSURL = TestProperties.getProperty( "demo_wps_authentication_url" ); + String demoWPSProcessName = TestProperties.getProperty( "demo_wps_authentication_process_name" ); + String demoWPSInputParam = TestProperties.getProperty( "demo_wps_input_uri" ); + + Assume.assumeNotNull( demoWPSURL ); + Assume.assumeNotNull( demoWPSProcessName ); + Assume.assumeNotNull( demoWPSInputParam ); + + URL serviceUrl = new URL( demoWPSURL ); + URI inputUri = new URI( demoWPSInputParam ); + + WPSClient wpsClient = new WPSClient( serviceUrl ); + + Process proc = wpsClient.getProcess( demoWPSProcessName, null ); + ProcessExecution execution = proc.prepareExecution(); + + execution.addBinaryInput( "infile", null, inputUri, true, null, null ); + + execution.execute(); + + while ( execution.getState() != ExecutionState.SUCCEEDED && execution.getState() != ExecutionState.FAILED ) { + System.out.println( String.format( "%s, %d, %s", execution.getState(), execution.getPercentCompleted(), + execution.getStatusLocation() ) ); + Thread.sleep( 500 ); + } + + ExecutionOutputs outputs = execution.getOutputs(); + Assert.assertTrue( outputs.getAll().length > 0 ); + } } From 823e44d504326fe10c587c3c03acadfc5a2aa3cb Mon Sep 17 00:00:00 2001 From: "D. Baum" Date: Tue, 20 Dec 2016 18:41:57 +0100 Subject: [PATCH 2/2] Fixing deegree bug #788, part 2: Adapting wps webclient --- .../org/deegree/wpsclient/controller/ProcessExecuter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deegree-client/deegree-wps-webclient/src/main/java/org/deegree/wpsclient/controller/ProcessExecuter.java b/deegree-client/deegree-wps-webclient/src/main/java/org/deegree/wpsclient/controller/ProcessExecuter.java index ff7cbc9329..c808eda2c6 100644 --- a/deegree-client/deegree-wps-webclient/src/main/java/org/deegree/wpsclient/controller/ProcessExecuter.java +++ b/deegree-client/deegree-wps-webclient/src/main/java/org/deegree/wpsclient/controller/ProcessExecuter.java @@ -39,7 +39,7 @@ import static org.slf4j.LoggerFactory.getLogger; import java.io.File; -import java.net.URL; +import java.net.URI; import java.util.List; import java.util.Map; @@ -157,7 +157,7 @@ public ExecutionOutput[] execute( Process processToExecute, Map 0 ) { execution.addXMLInput( input.getId().getCode(), input.getId().getCodeSpace(), - new URL( xmlRef ), true, mimeType, encoding, schema ); + new URI( xmlRef ), true, mimeType, encoding, schema ); } for ( String key : binaryInputs.keySet() ) { execution.addBinaryInput( input.getId().getCode(), input.getId().getCodeSpace(),