Search in sources :

Example 11 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.

the class CswExceptionMapper method createServiceException.

private ExceptionReport createServiceException(CswException cswException) {
    ExceptionReport exceptionReport = new ExceptionReport();
    exceptionReport.setVersion(SERVICE_EXCEPTION_REPORT_VERSION);
    ExceptionType exception = new ExceptionType();
    exception.setExceptionCode(cswException.getExceptionCode());
    exception.setLocator(cswException.getLocator());
    exception.getExceptionText().add(cswException.getMessage());
    exceptionReport.getException().add(exception);
    return exceptionReport;
}
Also used : ExceptionType(net.opengis.ows.v_1_0_0.ExceptionType) ExceptionReport(net.opengis.ows.v_1_0_0.ExceptionReport)

Example 12 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.

the class TestCswExceptionMapper 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)

Example 13 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.

the class TestCswExceptionMapper method testCswExceptionToServiceExceptionReport.

@Test
public void testCswExceptionToServiceExceptionReport() {
    CswException exception = new CswException(SERVICE_EXCEPTION_MSG, Status.BAD_REQUEST.getStatusCode());
    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(exceptionReport.getException().get(0).getExceptionCode(), nullValue());
    assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
}
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)

Example 14 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.

the class TestCswExceptionMapper method testThrowableExceptionToServiceExceptionReport.

@Test
public void testThrowableExceptionToServiceExceptionReport() {
    NullPointerException npe = new NullPointerException();
    ExceptionMapper<Throwable> exceptionMapper = new CswExceptionMapper();
    Response response = exceptionMapper.toResponse(npe);
    assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
    ExceptionReport exceptionReport = (ExceptionReport) response.getEntity();
    assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
    assertThat(XML_PARSE_FAIL_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
    assertThat(CswConstants.MISSING_PARAMETER_VALUE, is(exceptionReport.getException().get(0).getExceptionCode()));
    assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
    IllegalArgumentException iae = new IllegalArgumentException();
    exceptionMapper = new CswExceptionMapper();
    response = exceptionMapper.toResponse(iae);
    assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
    exceptionReport = (ExceptionReport) response.getEntity();
    assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
    assertThat(XML_PARSE_FAIL_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
    assertThat(CswConstants.MISSING_PARAMETER_VALUE, is(exceptionReport.getException().get(0).getExceptionCode()));
    assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
}
Also used : Response(javax.ws.rs.core.Response) ExceptionReport(net.opengis.ows.v_1_0_0.ExceptionReport) Test(org.junit.Test)

Example 15 with ExceptionReport

use of org.geotoolkit.ows.xml.v100.ExceptionReport in project geotoolkit by Geomatys.

the class OWSXmlBindingTest method exceptionMarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void exceptionMarshalingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    /*
         * Test marshalling exception report 110
         */
    ExceptionReport report = new ExceptionReport("some error", OWSExceptionCode.INVALID_CRS.name(), "parameter1", "1.1.0");
    StringWriter sw = new StringWriter();
    marshaller.marshal(report, sw);
    String result = sw.toString();
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ns2:ExceptionReport version=\"1.1.0\" xmlns:ns2=\"http://www.opengis.net/ows/1.1\">" + '\n' + "    <ns2:Exception locator=\"parameter1\" exceptionCode=\"InvalidCRS\">" + '\n' + "        <ns2:ExceptionText>some error</ns2:ExceptionText>" + '\n' + "    </ns2:Exception>" + '\n' + "</ns2:ExceptionReport>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : StringWriter(java.io.StringWriter) ExceptionReport(org.geotoolkit.ows.xml.v110.ExceptionReport)

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