Search in sources :

Example 21 with ProcessException

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;
}
Also used : NumberRange(org.apache.sis.measure.NumberRange) Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) Process(org.geotoolkit.process.Process) IOException(java.io.IOException)

Example 22 with ProcessException

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);
    }
}
Also used : DataOutput(org.geotoolkit.wps.xml.v200.DataOutput) GetResultRequest(org.geotoolkit.wps.client.GetResultRequest) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) ExceptionResponse(org.geotoolkit.ows.xml.ExceptionResponse) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) Result(org.geotoolkit.wps.xml.v200.Result)

Example 23 with ProcessException

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;
            }
        }
    }
}
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)

Example 24 with ProcessException

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);
    }
}
Also used : ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) DismissRequest(org.geotoolkit.wps.client.DismissRequest) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) DismissProcessException(org.geotoolkit.process.DismissProcessException)

Example 25 with ProcessException

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);
    }
}
Also used : ExecuteRequest(org.geotoolkit.wps.client.ExecuteRequest) ProcessException(org.geotoolkit.process.ProcessException) DismissProcessException(org.geotoolkit.process.DismissProcessException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) DismissProcessException(org.geotoolkit.process.DismissProcessException) Result(org.geotoolkit.wps.xml.v200.Result)

Aggregations

ProcessException (org.geotoolkit.process.ProcessException)70 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)27 Geometry (org.locationtech.jts.geom.Geometry)26 FactoryException (org.opengis.util.FactoryException)24 TransformException (org.opengis.referencing.operation.TransformException)21 RenderedImage (java.awt.image.RenderedImage)15 DataStoreException (org.apache.sis.storage.DataStoreException)13 IOException (java.io.IOException)12 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)12 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)11 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)11 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 BufferedImage (java.awt.image.BufferedImage)10 ArrayList (java.util.ArrayList)10 PixelIterator (org.apache.sis.image.PixelIterator)9 List (java.util.List)8 Parameters (org.apache.sis.parameter.Parameters)8 DismissProcessException (org.geotoolkit.process.DismissProcessException)8 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)7 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)7