Search in sources :

Example 11 with WfsException

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

the class WfsSource method handleWebApplicationException.

private String handleWebApplicationException(WebApplicationException wae) {
    Response response = wae.getResponse();
    WfsException wfsException = new WfsResponseExceptionMapper().fromResponse(response);
    return "Error received from WFS Server " + getId() + "\n" + wfsException.getMessage();
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)

Example 12 with WfsException

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

the class TestWfsResponseExceptionMapper method testWfsExceptionWithInvalidEntityType.

@Test
public void testWfsExceptionWithInvalidEntityType() {
    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'>Schema\r\n" + "        does not exist.</ServiceException>\r\n" + "</ServiceExceptionReport>";
    ResponseBuilder responseBuilder = Response.ok(serviceExceptionReportXml);
    responseBuilder.type("text/xml");
    Response response = responseBuilder.build();
    WfsException wfsException = new WfsResponseExceptionMapper().fromResponse(response);
    assertThat(wfsException.getMessage(), equalTo("Error reading response, entity type not understood: java.lang.String"));
}
Also used : Response(javax.ws.rs.core.Response) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) Matchers.containsString(org.hamcrest.Matchers.containsString) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Test(org.junit.Test)

Example 13 with WfsException

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

the class TestWfsResponseExceptionMapper method testEmptyWfsException.

@Test
public void testEmptyWfsException() {
    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" + "</ServiceExceptionReport>";
    WfsException wfsException = createWfsException(serviceExceptionReportXml);
    assertThat(wfsException.getMessage(), containsString("Empty Service Exception Report (version ="));
}
Also used : WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with WfsException

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

the class WfsSource method buildFeatureFilters.

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, List<String> supportedGeo) throws SecurityServiceException {
    // Use local Map for metacardtype registrations and once they are populated with latest
    // MetacardTypes, then do actual registration
    Map<String, MetacardTypeRegistration> mcTypeRegs = new HashMap<String, MetacardTypeRegistration>();
    Wfs wfs = factory.getClient();
    for (FeatureTypeType featureTypeType : featureTypes) {
        String ftName = featureTypeType.getName().getLocalPart();
        if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftName)) {
            continue;
        }
        if (mcTypeRegs.containsKey(ftName)) {
            LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftName);
            continue;
        }
        LOGGER.debug("ftName: {}", ftName);
        try {
            XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
            if ((schema != null)) {
                FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.asList(nonQueryableProperties) : new ArrayList<String>(), Wfs10Constants.GML_NAMESPACE);
                Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Metacard.CONTENT_TYPE, new String[] { ftName });
                LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);
                // Update local map with enough info to create actual MetacardType registrations
                // later
                mcTypeRegs.put(ftName, new MetacardTypeRegistration(ftMetacard, props, featureTypeType.getSRS()));
                FeatureConverter featureConverter = null;
                if (!CollectionUtils.isEmpty(featureConverterFactories)) {
                    for (FeatureConverterFactory factory : featureConverterFactories) {
                        if (ftName.equalsIgnoreCase(factory.getFeatureType())) {
                            featureConverter = factory.createConverter();
                            LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}", getId(), ftName, featureConverter.getClass().getSimpleName());
                            break;
                        }
                    }
                    if (featureConverter == null) {
                        LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                        featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                    }
                } else {
                    LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                    featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                }
                featureConverter.setSourceId(getId());
                featureConverter.setMetacardType(ftMetacard);
                featureConverter.setWfsUrl(wfsUrl);
                // Add the Feature Type name as an alias for xstream
                featureCollectionReader.registerConverter(featureConverter);
            }
        } catch (WfsException | IllegalArgumentException wfse) {
            LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        } catch (WebApplicationException wae) {
            LOGGER.debug(handleWebApplicationException(wae), wae);
        }
    }
    // Unregister all MetacardType services - the DescribeFeatureTypeRequest should
    // have returned all of the most current metacard types that will now be registered.
    // As Source(s) are added/removed from this instance or to other Source(s)
    // that this instance is federated to, the list of metacard types will change.
    // This is done here vs. inside the above loop so that minimal time is spent clearing and
    // registering the MetacardTypes - the concern is that if this registration is too lengthy
    // a query could come in that is handled while the MetacardType registrations are
    // in a state of flux.
    unregisterAllMetacardTypes();
    this.featureTypeFilters.clear();
    if (!mcTypeRegs.isEmpty()) {
        Set<Entry<String, MetacardTypeRegistration>> entries = mcTypeRegs.entrySet();
        for (Map.Entry<String, MetacardTypeRegistration> entry : mcTypeRegs.entrySet()) {
            MetacardTypeRegistration mcTypeReg = entry.getValue();
            FeatureMetacardType ftMetacard = mcTypeReg.getFtMetacard();
            ServiceRegistration serviceRegistration = context.registerService(MetacardType.class.getName(), ftMetacard, mcTypeReg.getProps());
            this.metacardTypeServiceRegistrations.put(entry.getKey(), serviceRegistration);
            this.featureTypeFilters.put(ftMetacard.getFeatureType(), new WfsFilterDelegate(ftMetacard, supportedGeo, mcTypeReg.getSrs()));
        }
    }
    if (featureTypeFilters.isEmpty()) {
        LOGGER.info("Wfs Source {}: No Feature Type schemas validated. Marking source as unavailable", getId());
    }
    LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) FeatureConverterFactory(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.converter.FeatureConverterFactory) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) ServiceRegistration(org.osgi.framework.ServiceRegistration) FeatureTypeType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) Hashtable(java.util.Hashtable) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with WfsException

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

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