Skip to content

Commit

Permalink
Merge pull request #795 from awst-baum/wps_client_uris_stable
Browse files Browse the repository at this point in the history
Stable version: Make the WPS client use URI instead of URL
  • Loading branch information
copierrj authored Feb 2, 2018
2 parents e3c056f + 823e44d commit d66d52d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -157,7 +157,7 @@ public ExecutionOutput[] execute( Process processToExecute, Map<String, StringPa
encoding, schema );
} else if ( xmlRef != null && xmlRef.trim().length() > 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,7 +55,7 @@ public class BinaryInput extends ExecutionInput {

private ComplexFormat complexAttributes;

private URL url;
private URI uri;

private InputStream inputStream;

Expand All @@ -66,8 +66,8 @@ public class BinaryInput extends ExecutionInput {
*
* @param id
* parameter identifier, must not be <code>null</code>
* @param url
* URL for accessing the binary resource, must not be <code>null</code>
* @param uri
* URI for accessing the binary resource, must not be <code>null</code>
* @param isWebAccessible
* if true, the data will be submitted to the process as reference, otherwise it will be encoded in the
* request
Expand All @@ -76,9 +76,9 @@ public class BinaryInput extends ExecutionInput {
* @param encoding
* encoding to be used for the binary data, may be <code>null</code> (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 );
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <code>null</code> (not web-acessible)
* @return web-accessible URI, can be <code>null</code> (not web-acessible)
*/
public URL getWebAccessibleURL() {
public URI getWebAccessibleURI() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,7 +62,7 @@ public class XMLInput extends ExecutionInput {

private final ComplexFormat complexAttribs;

private URL url;
private URI uri;

private XMLStreamReader reader;

Expand All @@ -73,8 +73,8 @@ public class XMLInput extends ExecutionInput {
*
* @param id
* parameter identifier, must not be <code>null</code>
* @param url
* URL for accessing the XML resource, must not be <code>null</code>
* @param uri
* URI for accessing the XML resource, must not be <code>null</code>
* @param isWebAccessible
* if true, the data will be submitted to the process as reference, otherwise it will be encoded in the
* request
Expand All @@ -85,9 +85,9 @@ public class XMLInput extends ExecutionInput {
* @param schema
* XML schema, may be <code>null</code> (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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -148,7 +148,7 @@ public XMLStreamReader getAsXMLStream()
}

@Override
public URL getWebAccessibleURL() {
return isWebAccessible ? url : null;
public URI getWebAccessibleURI() {
return isWebAccessible ? uri : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void addBBoxInput( String id, String idCodeSpace, double[] lower, double[
* identifier of the input parameter, must not be <code>null</code>
* @param idCodeSpace
* codespace of the parameter identifier, may be <code>null</code> (for identifiers without codespace)
* @param url
* @param uri
* {@link URL} reference to the xml resource, must not be <code>null</code>
* @param byRef
* if true, the parameter will be passed by reference to the server, otherwise it will be nested in the
Expand All @@ -151,9 +152,9 @@ public void addBBoxInput( String id, String idCodeSpace, double[] lower, double[
* schema, may be <code>null</code> (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 ) );
}

/**
Expand Down Expand Up @@ -188,7 +189,7 @@ public void addXMLInput( String id, String idCodeSpace, XMLStreamReader reader,
* identifier of the input parameter, must not be <code>null</code>
* @param idCodeSpace
* codespace of the parameter identifier, may be <code>null</code> (for identifiers without codespace)
* @param url
* @param uri
* {@link URL} reference to the binary resource, must not be <code>null</code> (and must not be
* web-accessible)
* @param byRef
Expand All @@ -201,8 +202,8 @@ public void addXMLInput( String id, String idCodeSpace, XMLStreamReader reader,
* encoding, may be <code>null</code> (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 ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@
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;
import javax.xml.stream.XMLStreamReader;
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;
Expand Down Expand Up @@ -223,10 +221,10 @@ private void writeInputs( List<ExecutionInput> 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() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();

Expand All @@ -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 );
Expand All @@ -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();

Expand All @@ -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();
Expand All @@ -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 ) );
Expand All @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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 );
}
}

0 comments on commit d66d52d

Please sign in to comment.