use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class CatalogComponentTest method getMockInputTransformer.
/**
* Mock an InputTransformer, returning a canned Metacard when the transform() method is invoked on
* the InputTransformer.
*
* @return
*/
protected InputTransformer getMockInputTransformer() {
InputTransformer inputTransformer = mock(InputTransformer.class);
Metacard generatedMetacard = getSimpleMetacard();
try {
when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
} catch (IOException e) {
LOGGER.debug("IOException", e);
} catch (CatalogTransformerException e) {
LOGGER.debug("CatalogTransformerException", e);
}
return inputTransformer;
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class TransformerConsumer method doStop.
@Override
protected void doStop() throws CatalogTransformerException {
LOGGER.debug("ENTERING: doStop");
if (registration != null) {
LOGGER.debug("Unregistering");
registration.unregister();
}
try {
super.doStop();
} catch (Exception e) {
throw new CatalogTransformerException("Failed to stop Transformer Consumer", e);
}
LOGGER.debug("EXITING: doStop");
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class AbstractCatalogService method getDocument.
@Override
public BinaryContent getDocument(String encodedSourceId, String encodedId, String transformerParam, URI absolutePath, MultivaluedMap<String, String> queryParameters, HttpServletRequest httpRequest) throws CatalogServiceException, DataUsageLimitExceededException, InternalServerErrorException {
QueryResponse queryResponse;
Metacard card = null;
LOGGER.trace("GET");
if (encodedId != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Got id: {}", LogSanitizer.sanitize(encodedId));
LOGGER.debug("Got service: {}", LogSanitizer.sanitize(transformerParam));
LOGGER.debug("Map of query parameters: \n{}", LogSanitizer.sanitize(queryParameters));
}
Map<String, Serializable> convertedMap = convert(queryParameters);
convertedMap.put("url", absolutePath.toString());
LOGGER.debug("Map converted, retrieving product.");
// default to xml if no transformer specified
try {
String id = URLDecoder.decode(encodedId, CharEncoding.UTF_8);
String transformer = DEFAULT_METACARD_TRANSFORMER;
if (transformerParam != null) {
transformer = transformerParam;
}
Filter filter = getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id);
Collection<String> sources = null;
if (encodedSourceId != null) {
String sourceid = URLDecoder.decode(encodedSourceId, CharEncoding.UTF_8);
sources = new ArrayList<>();
sources.add(sourceid);
}
QueryRequestImpl request = new QueryRequestImpl(new QueryImpl(filter), sources);
request.setProperties(convertedMap);
queryResponse = catalogFramework.query(request, null);
// pull the metacard out of the blocking queue
List<Result> results = queryResponse.getResults();
// return null if timeout elapsed)
if (results != null && !results.isEmpty()) {
card = results.get(0).getMetacard();
}
if (card == null) {
return null;
}
// Check for Range header set the value in the map appropriately so that the
// catalogFramework
// can take care of the skipping
long bytesToSkip = getRangeStart(httpRequest);
if (bytesToSkip > 0) {
LOGGER.debug("Bytes to skip: {}", bytesToSkip);
convertedMap.put(BYTES_TO_SKIP, bytesToSkip);
}
LOGGER.debug("Calling transform.");
final BinaryContent content = catalogFramework.transform(card, transformer, convertedMap);
LOGGER.debug("Read and transform complete, preparing response.");
return content;
} catch (FederationException e) {
String exceptionMessage = "READ failed due to unexpected exception: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (CatalogTransformerException e) {
String exceptionMessage = "Unable to transform Metacard. Try different transformer: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot obtain query results because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (UnsupportedQueryException e) {
String errorMessage = "Specified query is unsupported. Change query and resubmit: ";
LOGGER.info(errorMessage, e);
throw new CatalogServiceException(errorMessage);
} catch (DataUsageLimitExceededException e) {
String errorMessage = "Unable to process request. Data usage limit exceeded: ";
LOGGER.debug(errorMessage, e);
throw new DataUsageLimitExceededException(errorMessage);
} catch (OAuthPluginException e) {
Map<String, String> parameters = e.getParameters();
String url = constructUrl(httpRequest, e.getBaseUrl(), parameters);
if (url != null) {
parameters.put(REDIRECT_URI, url);
throw new OAuthPluginException(e.getSourceId(), url, e.getBaseUrl(), parameters, e.getErrorType());
}
throw e;
// The catalog framework will throw this if any of the transformers blow up.
// We need to catch this exception here or else execution will return to CXF and
// we'll lose this message and end up with a huge stack trace in a GUI or whatever
// else is connected to this endpoint
} catch (RuntimeException | UnsupportedEncodingException e) {
String exceptionMessage = "Unknown error occurred while processing request.";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
}
} else {
throw new CatalogServiceException("No ID specified.");
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class AbstractCatalogService method getHeaders.
@Override
public BinaryContent getHeaders(String sourceid, String id, URI absolutePath, MultivaluedMap<String, String> queryParameters) throws CatalogServiceException {
QueryResponse queryResponse;
Metacard card = null;
LOGGER.trace("getHeaders");
if (id != null) {
LOGGER.debug("Got id: {}", LogSanitizer.sanitize(id));
LOGGER.debug("Map of query parameters: \n{}", LogSanitizer.sanitize(queryParameters));
Map<String, Serializable> convertedMap = convert(queryParameters);
convertedMap.put("url", absolutePath.toString());
LOGGER.debug("Map converted, retrieving product.");
// default to xml if no transformer specified
try {
String transformer = DEFAULT_METACARD_TRANSFORMER;
Filter filter = getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id);
Collection<String> sources = null;
if (sourceid != null) {
sources = new ArrayList<>();
sources.add(sourceid);
}
QueryRequestImpl request = new QueryRequestImpl(new QueryImpl(filter), sources);
request.setProperties(convertedMap);
queryResponse = catalogFramework.query(request, null);
// pull the metacard out of the blocking queue
List<Result> results = queryResponse.getResults();
// return null if timeout elapsed)
if (results != null && !results.isEmpty()) {
card = results.get(0).getMetacard();
}
if (card == null) {
return null;
}
LOGGER.debug("Calling transform.");
final BinaryContent content = catalogFramework.transform(card, transformer, convertedMap);
LOGGER.debug("Read and transform complete, preparing response.");
return content;
} catch (FederationException e) {
String exceptionMessage = "READ failed due to unexpected exception: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (CatalogTransformerException e) {
String exceptionMessage = "Unable to transform Metacard. Try different transformer: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (SourceUnavailableException e) {
String exceptionMessage = "Cannot obtain query results because source is unavailable: ";
LOGGER.info(exceptionMessage, e);
throw new InternalServerErrorException(exceptionMessage);
} catch (UnsupportedQueryException e) {
String errorMessage = "Specified query is unsupported. Change query and resubmit: ";
LOGGER.info(errorMessage, e);
throw new CatalogServiceException(errorMessage);
// The catalog framework will throw this if any of the transformers blow up. We need to
// catch this exception
// here or else execution will return to CXF and we'll lose this message and end up with
// a huge stack trace
// in a GUI or whatever else is connected to this endpoint
} catch (IllegalArgumentException e) {
throw new CatalogServiceException(e.getMessage());
}
} else {
throw new CatalogServiceException("No ID specified.");
}
}
use of ddf.catalog.transform.CatalogTransformerException 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();
XML_UTILS.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);
}
}
Aggregations