Search in sources :

Example 6 with ExceptionReport

use of net.opengis.ows._1.ExceptionReport 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 7 with ExceptionReport

use of net.opengis.ows._1.ExceptionReport in project web-feature-service by 3dcitydb.

the class WFSExceptionReportHandler method getExceptionReport.

public ExceptionReport getExceptionReport(WFSException wfsException, String operationName, HttpServletRequest request, boolean writeToLog) {
    preprocessWFSException(wfsException, operationName);
    ExceptionReport exceptionReport = owsFactory.createExceptionReport();
    exceptionReport.setLang(wfsException.getLanguage());
    exceptionReport.setVersion(wfsException.getVersion());
    for (WFSExceptionMessage message : wfsException.getExceptionMessages()) {
        ExceptionType exceptionType = owsFactory.createExceptionType();
        exceptionType.setExceptionCode(message.getExceptionCode().getValue());
        exceptionType.setLocator(message.getLocator());
        for (String text : message.getExceptionTexts()) {
            exceptionType.getExceptionText().add(text);
            if (writeToLog) {
                StringBuilder logMessage = new StringBuilder().append('[').append(message.getExceptionCode().getValue()).append(", ").append(request.getRemoteAddr());
                if (message.getLocator() != null)
                    logMessage.append(", ").append(message.getLocator());
                logMessage.append("] ").append(text);
                log.error(logMessage.toString());
            }
        }
        exceptionReport.getException().add(exceptionType);
    }
    return exceptionReport;
}
Also used : ExceptionType(net.opengis.ows._1.ExceptionType) ExceptionReport(net.opengis.ows._1.ExceptionReport)

Example 8 with ExceptionReport

use of net.opengis.ows._1.ExceptionReport in project web-feature-service by 3dcitydb.

the class WFSExceptionReportHandler method sendErrorResponse.

public synchronized void sendErrorResponse(WFSException wfsException, String operationName, HttpServletRequest request, HttpServletResponse response) throws IOException {
    ExceptionReport exceptionReport = getExceptionReport(wfsException, operationName, request, true);
    response.setContentType("text/xml");
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());
    response.setStatus(wfsException.getFirstExceptionMessage().getExceptionCode().getHttpStatusCode());
    // prepare SAXWriter
    SAXWriter saxWriter = new SAXWriter();
    saxWriter.setWriteEncoding(true);
    saxWriter.setIndentString("  ");
    saxWriter.setPrefix(Constants.OWS_NAMESPACE_PREFIX, Constants.OWS_NAMESPACE_URI);
    saxWriter.setSchemaLocation(Constants.OWS_NAMESPACE_URI, Constants.OWS_SCHEMA_LOCATION);
    // marshall JAXB object
    try {
        saxWriter.setOutput(response.getWriter());
        Marshaller marshaller = cityGMLBuilder.getJAXBContext().createMarshaller();
        marshaller.marshal(exceptionReport, saxWriter);
    } catch (JAXBException | IOException e) {
        if (!response.isCommitted())
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) SAXWriter(org.citygml4j.util.xml.SAXWriter) ExceptionReport(net.opengis.ows._1.ExceptionReport) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 9 with ExceptionReport

use of net.opengis.ows._1.ExceptionReport in project ddf by codice.

the class WfsResponseExceptionMapper method fromResponse.

@Override
public WfsException fromResponse(Response response) {
    WfsException wfsEx = null;
    if (response != null) {
        if (response.getEntity() instanceof InputStream) {
            String msg = null;
            try {
                InputStream is = (InputStream) response.getEntity();
                is.reset();
                msg = IOUtils.toString(is);
            } catch (IOException e) {
                LOGGER.info("Unable to parse exception report: {}", e.getMessage());
                LOGGER.debug("Unable to parse exception report", e);
            }
            if (msg != null) {
                try {
                    JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
                    Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.class).createUnmarshaller();
                    XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
                    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
                    xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
                    xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
                    XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(msg));
                    ExceptionReport report = (ExceptionReport) um.unmarshal(xmlStreamReader);
                    wfsEx = convertToWfsException(report);
                } catch (JAXBException | XMLStreamException e) {
                    wfsEx = new WfsException("Error parsing Response: " + msg, e);
                }
            } else {
                wfsEx = new WfsException("Error reading Response");
            }
        } else {
            wfsEx = new WfsException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
        }
        wfsEx.setHttpStatus(response.getStatus());
    } else {
        wfsEx = new WfsException("Error handling response, response is null");
    }
    return wfsEx;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) ExceptionReport(net.opengis.ows.v_1_1_0.ExceptionReport) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) XMLStreamException(javax.xml.stream.XMLStreamException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 10 with ExceptionReport

use of net.opengis.ows._1.ExceptionReport in project ddf by codice.

the class CswExceptionMapperTest method testCswExceptionToServiceExceptionReportWithLocatorAndCode.

@Test
public void testCswExceptionToServiceExceptionReportWithLocatorAndCode() {
    CswException exception = new CswException(SERVICE_EXCEPTION_MSG, Status.BAD_REQUEST.getStatusCode(), EXCEPTION_CODE, LOCATOR);
    ExceptionMapper<Throwable> exceptionMapper = new CswExceptionMapper();
    Response response = exceptionMapper.toResponse(exception);
    assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
    ExceptionReport exceptionReport = (ExceptionReport) response.getEntity();
    assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
    assertThat(SERVICE_EXCEPTION_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
    assertThat(EXCEPTION_CODE, is(exceptionReport.getException().get(0).getExceptionCode()));
    assertThat(LOCATOR, is(exceptionReport.getException().get(0).getLocator()));
}
Also used : Response(javax.ws.rs.core.Response) ExceptionReport(net.opengis.ows.v_1_0_0.ExceptionReport) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Test(org.junit.Test)

Aggregations

ExceptionReport (net.opengis.ows.v_1_0_0.ExceptionReport)9 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)5 IOException (java.io.IOException)4 StringReader (java.io.StringReader)4 JAXBException (javax.xml.bind.JAXBException)4 ExceptionReport (net.opengis.ows._1.ExceptionReport)4 InputStream (java.io.InputStream)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)3 URL (java.net.URL)2 TruncatedResponse (net.opengis.wfs._2.TruncatedResponse)2 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)2 ExceptionReport (org.geotoolkit.ows.xml.v110.ExceptionReport)2 WFSExceptionReportHandler (vcs.citydb.wfs.exception.WFSExceptionReportHandler)2 StringWriter (java.io.StringWriter)1