use of org.geotoolkit.wps.xml.v100.LegacyStatus 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;
}
}
}
}
Aggregations