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;
}
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);
}
}
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);
}
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;
}
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());
}
}
Aggregations