Search in sources :

Example 16 with WfsException

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException 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)

Example 17 with WfsException

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException in project ddf by codice.

the class TestWfsResponseExceptionMapper method testInvalidWfsException.

@Test
public void testInvalidWfsException() {
    String serviceExceptionReportXml = "<?xml version='1.0'?>\r\n" + "<ServiceExceptionReport version='1.2.0'\r\n" + "    xmlns='http://www.opengis.net/ogc'\r\n" + "    xsi:schemaLocation='http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd'\r\n" + "    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" + "    <INVALID_TAG code='GeneralException'>Schema\r\n" + "        does not exist.</ServiceException>\r\n" + "</ServiceExceptionReport>";
    WfsException wfsException = createWfsException(serviceExceptionReportXml);
    assertThat(wfsException.getMessage(), containsString("Error parsing Response"));
}
Also used : WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 18 with WfsException

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException in project ddf by codice.

the class TestWfsResponseExceptionMapper method testWfsExceptionWithMultipleServiceExceptions.

@Test
public void testWfsExceptionWithMultipleServiceExceptions() {
    String serviceExceptionReportXml = "<?xml version='1.0'?>\r\n" + "<ServiceExceptionReport version='1.2.0'\r\n" + "    xmlns='http://www.opengis.net/ogc'\r\n" + "    xsi:schemaLocation='http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd'\r\n" + "    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n" + "    <ServiceException code='GeneralException'>First exception text</ServiceException>\r\n" + "    <ServiceException code='GeneralException'>Second exception text</ServiceException>\r\n" + "</ServiceExceptionReport>";
    WfsException wfsException = createWfsException(serviceExceptionReportXml);
    assertThat(wfsException.getMessage(), containsString("First exception text"));
    assertThat(wfsException.getMessage(), containsString("Second exception text"));
}
Also used : WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)18 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 JAXBException (javax.xml.bind.JAXBException)6 Test (org.junit.Test)5 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)4 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 SecurityServiceException (ddf.security.service.SecurityServiceException)4 ConnectException (java.net.ConnectException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 Metacard (ddf.catalog.data.Metacard)3 Response (javax.ws.rs.core.Response)3 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 Wfs (org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs)3 Wfs (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs)3