Search in sources :

Example 1 with LegacyStatus

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;
            }
        }
    }
}
Also used : ProcessFailed(org.geotoolkit.wps.xml.v100.ProcessFailed) ExceptionReport(org.geotoolkit.ows.xml.v200.ExceptionReport) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) URL(java.net.URL) LegacyStatus(org.geotoolkit.wps.xml.v100.LegacyStatus) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) UnmarshalException(javax.xml.bind.UnmarshalException) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 JAXBElement (javax.xml.bind.JAXBElement)1 UnmarshalException (javax.xml.bind.UnmarshalException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ExceptionReport (org.geotoolkit.ows.xml.v200.ExceptionReport)1 DismissProcessException (org.geotoolkit.process.DismissProcessException)1 ProcessException (org.geotoolkit.process.ProcessException)1 LegacyStatus (org.geotoolkit.wps.xml.v100.LegacyStatus)1 ProcessFailed (org.geotoolkit.wps.xml.v100.ProcessFailed)1