use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class CachedPatternSymbolizer method computeOld.
private Geometry[] computeOld(GridCoverage coverage, Map<NumberRange, List<Symbolizer>> styles) throws IOException {
final ProcessDescriptor descriptor = CoverageToVectorDescriptor.INSTANCE;
final Integer band = (Integer) styleElement.getChannel().apply(null);
final ParameterValueGroup input = descriptor.getInputDescriptor().createValue();
input.parameter(CoverageToVectorDescriptor.COVERAGE.getName().getCode()).setValue(coverage);
final Set<NumberRange> nrs = styles.keySet();
input.parameter(CoverageToVectorDescriptor.RANGES.getName().getCode()).setValue(nrs.toArray(new NumberRange[nrs.size()]));
input.parameter(CoverageToVectorDescriptor.BAND.getName().getCode()).setValue(band);
final Process process = descriptor.createProcess(input);
final Geometry[] polygons;
try {
polygons = (Geometry[]) process.call().parameter(CoverageToVectorDescriptor.GEOMETRIES.getName().getCode()).getValue();
} catch (ProcessException ex) {
Logger.getLogger("org.geotoolkit.display2d.ext.pattern").log(Level.WARNING, null, ex);
throw new IOException(ex.getMessage(), ex);
}
return polygons;
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class WPS2Process method fillOutputs.
/**
* Fill {@link ParameterValueGroup parameters} of the process using the WPS
* {@link ExecuteResponse response}.
*
* @throws ProcessException if data conversion fails.
*/
private void fillOutputs(Object response) throws ProcessException {
try {
if (response == null) {
// request the result from the server
final GetResultRequest request = registry.getClient().createGetResult(jobId);
request.setDebug(debug);
request.setClientSecurity(security);
response = request.getResponse();
}
if (response instanceof Result) {
final Result result = (Result) response;
for (DataOutput out : result.getOutput()) {
fillOutputs(outputParameters, out);
}
} else if (response instanceof ExceptionResponse) {
final ExceptionResponse report = (ExceptionResponse) response;
throw new ProcessException("Exception when getting process result.", this, report.toException());
}
} catch (JAXBException ex) {
Logger.getLogger(WPS2Process.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(WPS2Process.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class WPS2Process method checkLegacyResult.
private Result checkLegacyResult(Result r) throws ProcessException, JAXBException, IOException, InterruptedException {
LegacyStatus legacyStatus = r.getStatus();
if (legacyStatus == null) {
return r;
}
// WPS 1 case
ProcessFailed failure = legacyStatus.getProcessFailed();
if (failure != null) {
ExceptionReport error = failure.getExceptionReport();
throw new ProcessException("Exception when executing the process.", this, error != null ? error.toException() : new RuntimeException("No exception report attached"));
}
if (legacyStatus.getProcessSucceeded() != null) {
return r;
}
final Integer currentProgress = legacyStatus.getPercentCompleted();
final String currentMessage = legacyStatus.getMessage();
if (!Objects.equals(lastProgress, currentProgress) || !Objects.equals(lastMessage, currentMessage)) {
lastProgress = currentProgress;
lastMessage = currentMessage;
fireProgressing(lastMessage, lastProgress, false);
}
registry.getClient().getLogger().log(Level.INFO, "WPS 1 Response is neither a succes nor a fail. Start querying statusLocation.");
legacyStatus.getPercentCompleted();
final Unmarshaller unmarshaller = WPSMarshallerPool.getInstance().acquireUnmarshaller();
String brutLocation = r.getStatusLocation();
if (brutLocation == null || (brutLocation = brutLocation.trim()).isEmpty()) {
throw new ProcessException("Received response is neither a success nor a fail, but no status location can be found.", this);
}
final URL statusLocation = security.secure(new URL(brutLocation));
Object tmpResponse;
// TODO: make 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) {
synchronized (this) {
wait(timeLapse);
}
try {
tmpResponse = unmarshaller.unmarshal(security.decrypt(statusLocation.openStream()));
if (tmpResponse instanceof JAXBElement) {
tmpResponse = ((JAXBElement) tmpResponse).getValue();
}
return checkResult(tmpResponse);
} catch (UnmarshalException | IOException ex) {
if (failCount < 5) {
failCount++;
} else {
// happenning so we consider the process failed
throw ex;
}
}
}
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class WPS2Process method dismissProcess.
/**
* Request to stop the process.<br>
* This request has no effect if the process has not start or is already finished or canceled.
*/
@Override
public void dismissProcess() {
if (isDimissed() || jobId == null)
return;
super.dismissProcess();
// send a stop request
final DismissRequest request = registry.getClient().createDismiss(jobId);
request.setDebug(debug);
request.setClientSecurity(security);
try {
checkResult(request.getResponse());
} catch (JAXBException ex) {
registry.getClient().getLogger().log(Level.WARNING, ex.getMessage(), ex);
} catch (IOException ex) {
registry.getClient().getLogger().log(Level.WARNING, ex.getMessage(), ex);
} catch (InterruptedException ex) {
registry.getClient().getLogger().log(Level.WARNING, ex.getMessage(), ex);
} catch (DismissProcessException ex) {
// do nothing, normal behaviour
} catch (ProcessException ex) {
registry.getClient().getLogger().log(Level.WARNING, ex.getMessage(), ex);
}
}
use of org.geotoolkit.process.ProcessException 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);
}
}
Aggregations