Search in sources :

Example 6 with ExceptionReport

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

the class WfsResponseExceptionMapper method fromResponse.

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) {
                wfsEx = new WfsException("Error reading Response" + (msg != null ? ": " + msg : ""), e);
            }
            if (msg != null) {
                try {
                    JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<ExceptionReport>();
                    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, 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 7 with ExceptionReport

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

the class WfsResponseExceptionMapper method convertToWfsException.

private WfsException convertToWfsException(ExceptionReport report) {
    WfsException wfsException = null;
    List<ExceptionType> list = new ArrayList<ExceptionType>(report.getException());
    if (list.size() > 0) {
        Collections.reverse(list);
        for (ExceptionType exceptionType : list) {
            String exceptionCode = exceptionType.getExceptionCode();
            String locator = exceptionType.getLocator();
            List<String> exceptionText = exceptionType.getExceptionText();
            StringBuilder exceptionMsg = new StringBuilder();
            // Exception code is required per CSW schema, but check it anyway
            if (StringUtils.isNotBlank(exceptionCode)) {
                exceptionMsg.append("exceptionCode = " + exceptionCode + "\n");
            } else {
                exceptionMsg.append("exceptionCode = UNSPECIFIED");
            }
            // Locator and exception text(s) are both optional
            if (StringUtils.isNotBlank(locator)) {
                exceptionMsg.append("locator = " + locator + "\n");
            }
            if (!CollectionUtils.isEmpty(exceptionText)) {
                for (String text : exceptionText) {
                    exceptionMsg.append(text);
                }
            }
            wfsException = new WfsException(exceptionMsg.toString());
        }
        if (null == wfsException) {
            wfsException = new WfsException("Empty Service Exception Report (version = " + report.getVersion() + ")");
        }
    } else {
        wfsException = new WfsException("Empty Service Exception Report (version = " + report.getVersion() + ")");
    }
    return wfsException;
}
Also used : ExceptionType(net.opengis.ows.v_1_1_0.ExceptionType) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) ArrayList(java.util.ArrayList)

Aggregations

ExceptionReport (net.opengis.ows.v_1_0_0.ExceptionReport)5 Response (javax.ws.rs.core.Response)3 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)2 ArrayList (java.util.ArrayList)1 ExceptionType (net.opengis.ows.v_1_0_0.ExceptionType)1 ExceptionReport (net.opengis.ows.v_1_1_0.ExceptionReport)1 ExceptionType (net.opengis.ows.v_1_1_0.ExceptionType)1