Search in sources :

Example 11 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswSubscriptionEndpoint method deleteCswSubscription.

private synchronized CswSubscription deleteCswSubscription(String subscriptionId) throws CswException {
    String methodName = "deleteCswSubscription";
    LOGGER.trace("ENTERING: {}", methodName);
    LOGGER.trace("subscriptionId = {}", subscriptionId);
    if (StringUtils.isEmpty(subscriptionId)) {
        throw new CswException("Unable to delete subscription because subscription ID is null or empty");
    }
    CswSubscription subscription = getSubscription(subscriptionId);
    try {
        LOGGER.debug("Removing (unregistering) subscription: {}", subscriptionId);
        ServiceRegistration sr = (ServiceRegistration) registeredSubscriptions.remove(subscriptionId);
        if (sr != null) {
            sr.unregister();
        } else {
            LOGGER.debug("No ServiceRegistration found for subscription: {}", subscriptionId);
        }
        Configuration subscriptionConfig = getSubscriptionConfiguration(subscriptionId);
        try {
            if (subscriptionConfig != null) {
                LOGGER.debug("Deleting subscription for subscriptionId = {}", subscriptionId);
                subscriptionConfig.delete();
            } else {
                LOGGER.debug("subscriptionConfig is NULL for ID = {}", subscriptionId);
            }
        } catch (IOException e) {
            LOGGER.debug("IOException trying to delete subscription's configuration for subscription ID {}", subscriptionId, e);
        }
        LOGGER.debug("Subscription removal complete");
    } catch (Exception e) {
        LOGGER.debug("Could not delete subscription for {}", subscriptionId, e);
    }
    LOGGER.trace("EXITING: {}    (status = {})", methodName, false);
    return subscription;
}
Also used : Configuration(org.osgi.service.cm.Configuration) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) IOException(java.io.IOException) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 12 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswSubscriptionEndpoint method getMetacards.

private List<Metacard> getMetacards(GetRecordsResponseType recordsResponse) throws CswException {
    try {
        InputTransformer transformer = inputTransformerManager.getTransformerBySchema(recordsResponse.getSearchResults().getRecordSchema());
        List<Metacard> metacards = new ArrayList<>();
        for (Object result : recordsResponse.getSearchResults().getAny()) {
            if (result instanceof Node) {
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                XMLUtils.transform((Node) result, new TransformerProperties(), new StreamResult(outputStream));
                InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
                metacards.add(transformer.transform(is));
            }
        }
        return metacards;
    } catch (IOException | CatalogTransformerException e) {
        String msg = "Could not parse SearchResults in getRecordsResponse";
        LOGGER.debug(msg, e);
        throw new CswException(msg, e);
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) TransformerProperties(org.codice.ddf.platform.util.TransformerProperties) ArrayList(java.util.ArrayList) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class CswSubscriptionEndpoint method createOrUpdateSubscription.

public Response createOrUpdateSubscription(GetRecordsType request, String requestId, boolean persist) throws CswException {
    validator.validateOutputFormat(request.getOutputFormat(), mimeTypeTransformerManager);
    validator.validateOutputSchema(request.getOutputSchema(), schemaTransformerManager);
    if (request.getAbstractQuery() != null) {
        if (!request.getAbstractQuery().getValue().getClass().equals(QueryType.class)) {
            throw new CswException("Unknown QueryType: " + request.getAbstractQuery().getValue().getClass());
        }
        QueryType query = (QueryType) request.getAbstractQuery().getValue();
        validator.validateTypes(query.getTypeNames(), CswConstants.VERSION_2_0_2);
        validator.validateElementNames(query);
        if (query.getConstraint() != null && query.getConstraint().isSetFilter() && query.getConstraint().isSetCqlText()) {
            throw new CswException("A Csw Query can only have a Filter or CQL constraint");
        }
    }
    if (requestId != null) {
        request.setRequestId(requestId);
    }
    addOrUpdateSubscription(request, persist);
    LOGGER.trace("Exiting getRecordsSubscription.");
    return createAcknowledgment(request);
}
Also used : CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType)

Example 14 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class AbstractCswSource method getCapabilities.

protected CapabilitiesType getCapabilities() {
    CapabilitiesType caps = null;
    Subject subject = getSystemSubject();
    Csw csw = factory.getClientForSubject(subject);
    try {
        LOGGER.debug("Doing getCapabilities() call for CSW");
        GetCapabilitiesRequest request = new GetCapabilitiesRequest(CswConstants.CSW);
        request.setAcceptVersions(CswConstants.VERSION_2_0_2 + "," + CswConstants.VERSION_2_0_1);
        caps = csw.getCapabilities(request);
    } catch (CswException cswe) {
        LOGGER.info(CSW_SERVER_ERROR + " Received HTTP code '{}' from server for source with id='{}'. Set Logging to DEBUG for details.", cswe.getHttpStatus(), cswSourceConfiguration.getId());
        LOGGER.debug(CSW_SERVER_ERROR, cswe);
    } catch (WebApplicationException wae) {
        LOGGER.debug(handleWebApplicationException(wae), wae);
    } catch (Exception ce) {
        handleClientException(ce);
    }
    return caps;
}
Also used : GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) WebApplicationException(javax.ws.rs.WebApplicationException) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Subject(ddf.security.Subject) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException)

Example 15 with CswException

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswException in project ddf by codice.

the class AbstractCswSource method configureEventService.

private void configureEventService() {
    if (!cswSourceConfiguration.isRegisterForEvents()) {
        LOGGER.debug("registerForEvents = false - do not configure site {} for events", this.getId());
        removeEventServiceSubscription();
        return;
    }
    if (StringUtils.isEmpty(cswSourceConfiguration.getEventServiceAddress())) {
        LOGGER.debug("eventServiceAddress is NULL or empty - do not configure site {} for events", this.getId());
        return;
    }
    // a single event should be sent)
    if (filterlessSubscriptionId != null) {
        LOGGER.debug("filterless subscription already configured for site " + filterlessSubscriptionId);
        return;
    }
    initSubscribeClientFactory();
    CswSubscribe cswSubscribe = subscribeClientFactory.getClientForSubject(getSystemSubject());
    GetRecordsType request = createSubscriptionGetRecordsRequest();
    try {
        Response response = cswSubscribe.createRecordsSubscription(request);
        if (Response.Status.OK.getStatusCode() == response.getStatus()) {
            AcknowledgementType acknowledgementType = response.readEntity(AcknowledgementType.class);
            filterlessSubscriptionId = acknowledgementType.getRequestId();
        }
    } catch (CswException e) {
        LOGGER.info("Failed to register a subscription for events from csw source with id of " + this.getId());
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Aggregations

CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)84 Test (org.junit.Test)55 CapabilitiesType (net.opengis.cat.csw.v_2_0_2.CapabilitiesType)19 GetCapabilitiesType (net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType)19 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QueryImpl (ddf.catalog.operation.impl.QueryImpl)13 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)13 DescribeRecordResponseType (net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType)13 Matchers.anyString (org.mockito.Matchers.anyString)13 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)10 ArrayList (java.util.ArrayList)10 SchemaComponentType (net.opengis.cat.csw.v_2_0_2.SchemaComponentType)10 GetCapabilitiesRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest)10 SourceResponse (ddf.catalog.operation.SourceResponse)9 IOException (java.io.IOException)9 DescribeRecordRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest)9 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)7 Filter (org.opengis.filter.Filter)7 JAXBException (javax.xml.bind.JAXBException)6