use of org.geotoolkit.wps.xml.v200.Execute in project geotoolkit by Geomatys.
the class WPS2Process method execute.
@Override
protected void execute() throws ProcessException {
final Result result;
try {
if (jobId != null) {
try {
// It's an already running process we've got here. All we have to do
// is checking its status, to ensure/wait its completion.
result = checkResult(getStatus());
} catch (JAXBException | IOException ex) {
throw new ProcessException("Cannot get process status", this, ex);
}
} else {
final ExecuteRequest exec = createRequest();
exec.setDebug(debug);
exec.setClientSecurity(security);
result = sendExecuteRequest(exec);
}
} catch (InterruptedException e) {
throw new DismissProcessException("Process interrupted while executing", this, e);
}
if (!isDimissed()) {
fillOutputs(result);
}
}
use of org.geotoolkit.wps.xml.v200.Execute 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);
}
use of org.geotoolkit.wps.xml.v200.Execute in project geotoolkit by Geomatys.
the class WebProcessingClient method createExecute.
/**
* Create an execute request
*
* @return Execute : execute request.
*/
public ExecuteRequest createExecute() {
final WPSVersion version = ensureVersionSet();
final Execute content = new Execute();
content.setService("WPS");
content.setVersion(version.getCode());
return new ExecuteRequest(content, serverURL.toString(), getClientSecurity(), getTimeOutValue());
}
use of org.geotoolkit.wps.xml.v200.Execute in project geotoolkit by Geomatys.
the class WPS2Process method checkResult.
/**
* A Function to ensure response object is success or failure. Otherwise, we request continually status until
* we reach a result.
*
* @param response The execute response given by service.
*/
private Result checkResult(Object response) throws IOException, JAXBException, InterruptedException, ProcessException {
if (response instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) response;
throw new ProcessException("Exception when executing the process.", this, report.toException());
} else if (response instanceof StatusInfo) {
final StatusInfo statusInfo = (StatusInfo) response;
Status status = statusInfo.getStatus();
jobId = statusInfo.getJobID();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else if (Status.ACCEPTED.equals(status)) {
// Initial status
fireProgressing("Process accepted: " + jobId, 0, false);
} else {
// Running
final Integer progress = statusInfo.getPercentCompleted();
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
fireProgressing(message, progress == null ? Float.NaN : progress, false);
}
// loop until we have an answer
Object tmpResponse;
// TODO : make timelapse configurable
int timeLapse = 3000;
// we tolerate a few unmarshalling or IO errors, the servers behave differentely
// and may not offer the result file right from the start
int failCount = 0;
while (true) {
stopIfDismissed();
synchronized (this) {
wait(timeLapse);
}
try {
tmpResponse = getStatus();
failCount = 0;
} catch (UnmarshalException | IOException ex) {
if (failCount < 5 && !isDimissed()) {
failCount++;
continue;
} else if (isDimissed()) {
throw new DismissProcessException("WPS remote process has been canceled", this);
} else {
// happenning so we consider the process failed
throw ex;
}
}
if (tmpResponse instanceof StatusInfo) {
final StatusInfo statInfo = (StatusInfo) tmpResponse;
status = statInfo.getStatus();
if (Status.SUCCEEDED.equals(status)) {
fireProgressing("WPS remote process has been successfully executed", 100f, false);
return null;
} else if (Status.FAILED.equals(status)) {
throw new ProcessException("Process failed", this);
} else if (Status.DISMISS.equals(status)) {
throw new DismissProcessException("WPS remote process has been canceled", this);
}
// Not in the standard
String message = statusInfo.getMessage();
if (message == null || (message = message.trim()).isEmpty()) {
message = status.name();
}
final Integer percentCompleted = statInfo.getPercentCompleted();
if (!Objects.equals(message, lastMessage) || !Objects.equals(percentCompleted, lastProgress)) {
lastMessage = message;
lastProgress = percentCompleted;
fireProgressing(lastMessage, lastProgress, false);
}
} else if (tmpResponse instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) tmpResponse;
throw new ProcessException("Exception when executing the process.", this, report.toException());
}
}
} else if (response instanceof Result) {
final Result result = checkLegacyResult((Result) response);
if (result.getJobID() != null) {
jobId = result.getJobID();
}
return result;
} else {
throw new ProcessException("Unexpected response " + response, this);
}
}
use of org.geotoolkit.wps.xml.v200.Execute in project geotoolkit by Geomatys.
the class WPS2Process method createRequest.
/**
* Make a WPS Execute request from {@link ParameterValueGroup values}.
*/
private ExecuteRequest createRequest() throws ProcessException {
try {
final ParameterValueGroup inputs = getInput();
final List<GeneralParameterDescriptor> inputParamDesc = inputs.getDescriptor().descriptors();
final List<GeneralParameterDescriptor> outputParamDesc = descriptor.getOutputDescriptor().descriptors();
final List<DataInput> wpsIN = new ArrayList<>();
final List<OutputDefinition> wpsOUT = new ArrayList<>();
final String processId = descriptor.getIdentifier().getCode();
for (final GeneralParameterValue inputValue : inputs.values()) {
GeneralParameterDescriptor inputGeneDesc = inputValue.getDescriptor();
if (inputGeneDesc instanceof ParameterDescriptor) {
final ParameterDescriptor inputDesc = (ParameterDescriptor) inputGeneDesc;
final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) inputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
final Object value = ((ParameterValue) inputValue).getValue();
if (value == null)
continue;
final DataInput dataInput;
if (adaptor instanceof LiteralAdaptor) {
dataInput = ((LiteralAdaptor) adaptor).toWPS2Input(value, rawLiteralData);
} else {
dataInput = adaptor.toWPS2Input(value);
}
dataInput.setId(inputDesc.getName().getCode());
wpsIN.add(dataInput);
}
}
/*
* OUTPUTS
*/
for (final GeneralParameterDescriptor outputGeneDesc : outputParamDesc) {
if (outputGeneDesc instanceof ParameterDescriptor) {
final ParameterDescriptor outputDesc = (ParameterDescriptor) outputGeneDesc;
final DataAdaptor adaptor = (DataAdaptor) ((ExtendedParameterDescriptor) outputDesc).getUserObject().get(DataAdaptor.USE_ADAPTOR);
final String outputIdentifier = outputDesc.getName().getCode();
String mime = null;
String encoding = null;
String schema = null;
if (adaptor instanceof ComplexAdaptor) {
final ComplexAdaptor cadaptor = (ComplexAdaptor) adaptor;
mime = cadaptor.getMimeType();
encoding = cadaptor.getEncoding();
schema = cadaptor.getSchema();
}
final OutputDefinition out = new OutputDefinition(outputIdentifier, asReference);
out.setEncoding(encoding);
out.setMimeType(mime);
out.setSchema(schema);
wpsOUT.add(out);
} else if (outputGeneDesc instanceof ParameterDescriptorGroup) {
final ParameterDescriptorGroup outputDesc = (ParameterDescriptorGroup) outputGeneDesc;
final OutputDefinition out = new OutputDefinition(outputDesc.getName().getCode(), asReference);
wpsOUT.add(out);
}
}
final ExecuteRequest request = registry.getClient().createExecute();
request.setClientSecurity(security);
final Execute execute = request.getContent();
execute.setIdentifier(processId);
final Execute.Mode mode = executionMode == null ? Execute.Mode.auto : executionMode;
execute.setMode(mode);
execute.setResponse(rawOutput ? Execute.Response.raw : Execute.Response.document);
execute.getInput().addAll(wpsIN);
execute.getOutput().addAll(wpsOUT);
WPSProcessingRegistry.LOGGER.log(Level.FINER, "Execute request created for {0} in {1} mode.", new Object[] { processId, mode });
return request;
} catch (UnconvertibleObjectException ex) {
throw new ProcessException("Error during conversion step.", null, ex);
}
}
Aggregations