Search in sources :

Example 1 with ServiceExceptionReport

use of ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport in project ddf by codice.

the class WfsResponseExceptionMapper method convertToWfsException.

private WfsException convertToWfsException(ServiceExceptionReport report) {
    WfsException wfsException = null;
    List<ServiceExceptionType> list = new ArrayList<ServiceExceptionType>(report.getServiceException());
    if (list.size() > 0) {
        Collections.reverse(list);
        StringBuilder exceptionMsg = new StringBuilder();
        for (ServiceExceptionType serviceException : list) {
            exceptionMsg.append(serviceException.getValue());
        }
        wfsException = new WfsException(exceptionMsg.toString());
    }
    if (null == wfsException) {
        wfsException = new WfsException("Empty Service Exception Report (version = " + report.getVersion() + ")");
    }
    return wfsException;
}
Also used : WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) ArrayList(java.util.ArrayList) ServiceExceptionType(ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionType)

Example 2 with ServiceExceptionReport

use of ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport 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<ServiceExceptionReport> provider = new JAXBElementProvider<ServiceExceptionReport>();
                    Unmarshaller um = provider.getJAXBContext(ServiceExceptionReport.class, ServiceExceptionReport.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));
                    ServiceExceptionReport report = (ServiceExceptionReport) 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());
        }
        if (wfsEx != null) {
            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) JAXBException(javax.xml.bind.JAXBException) ServiceExceptionReport(ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport) 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)

Aggregations

WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 ServiceExceptionReport (ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport)1 ServiceExceptionType (ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionType)1 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)1