use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class InputTransformerProducer method transform.
protected Object transform(Message in, Object obj, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, IOException, CatalogTransformerException {
// Look up the InputTransformer for the request's mime type.
// If a transformer is found, then transform the request's payload into
// a Metacard.
// Otherwise, throw an exception.
MimeType derivedMimeType = new MimeType(mimeType);
if (transformerId != null) {
derivedMimeType = new MimeType(mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId);
}
InputStream message = null;
Metacard metacard = null;
try {
message = in.getBody(InputStream.class);
if (null != message) {
metacard = generateMetacard(derivedMimeType, mapper, message);
} else {
throw new CatalogTransformerException("Message body was null; unable to generate Metacard!");
}
} catch (MetacardCreationException e) {
throw new CatalogTransformerException("Did not find an InputTransformer for MIME Type [" + mimeType + "] and " + MimeTypeToTransformerMapper.ID_KEY + " [" + transformerId + "]", e);
} finally {
if (null != message) {
IOUtils.closeQuietly(message);
}
}
return metacard;
}
use of ddf.catalog.transform.CatalogTransformerException in project alliance by codice.
the class MpegTsInputTransformerTest method setup.
@Before
public void setup() throws IOException, CatalogTransformerException {
metacardTypes = Collections.singletonList(mock(MetacardType.class));
stanag4609Processor = mock(Stanag4609Processor.class);
klvHandlerFactory = mock(KlvHandlerFactory.class);
defaultKlvHandler = mock(KlvHandler.class);
streamParser = mock(Stanag4609TransportStreamParser.class);
metacard = new MetacardImpl();
inputTransformer = mock(InputTransformer.class);
stanagParserFactory = mock(StanagParserFactory.class);
klvProcessor = mock(KlvProcessor.class);
when(inputTransformer.transform(any(), any())).thenReturn(metacard);
when(stanagParserFactory.createParser(any())).thenReturn(() -> {
try {
return streamParser.parse();
} catch (Exception e) {
throw new Stanag4609ParseException(e);
}
});
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class ConfluenceInputTransformer method getJsonObject.
private Map<String, Object> getJsonObject(InputStream stream) throws CatalogTransformerException {
String jsonString = null;
try {
jsonString = IOUtils.toString(stream, StandardCharsets.UTF_8);
Map<String, Object> rootObject = GSON.fromJson(jsonString, MAP_STRING_TO_OBJECT_TYPE);
LOGGER.debug(jsonString);
return rootObject;
} catch (IOException | RuntimeException re) {
throw new CatalogTransformerException("Invalid json. Could not parse: " + jsonString, re);
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class ConfluenceSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
Query query = request.getQuery();
ConfluenceFilterDelegate confluenceDelegate = new ConfluenceFilterDelegate();
String cql = filterAdapter.adapt(query, confluenceDelegate);
if (!confluenceDelegate.isConfluenceQuery() || (StringUtils.isEmpty(cql) && (confluenceSpaces.isEmpty() || !confluenceDelegate.isWildCardQuery()))) {
return new SourceResponseImpl(request, Collections.emptyList());
}
cql = getSortedQuery(query.getSortBy(), getSpaceQuery(cql));
LOGGER.debug(cql);
String finalExpandedSections = expandedSections;
if (includePageContent && StringUtils.isNotBlank(bodyExpansion)) {
finalExpandedSections += "," + bodyExpansion;
}
SearchResource confluence = getClientFactory().getClient();
String cqlContext = null;
String excerpt = null;
Response confluenceResponse = confluence.search(cql, cqlContext, excerpt, finalExpandedSections, query.getStartIndex() - 1, query.getPageSize(), includeArchivedSpaces);
InputStream stream = null;
Object entityObj = confluenceResponse.getEntity();
if (entityObj != null) {
stream = (InputStream) entityObj;
}
if (Response.Status.OK.getStatusCode() != confluenceResponse.getStatus()) {
String error = "";
try {
if (stream != null) {
error = IOUtils.toString(stream);
}
} catch (IOException ioe) {
LOGGER.debug("Could not convert error message to a string for output.", ioe);
}
throw new UnsupportedQueryException(String.format("Received error code from remote source (status %s ): %s", confluenceResponse.getStatus(), error));
}
try {
List<Result> results = transformer.transformConfluenceResponse(stream, bodyExpansion).stream().map(this::getUpdatedResult).collect(Collectors.toList());
return new SourceResponseImpl(request, results);
} catch (CatalogTransformerException e) {
throw new UnsupportedQueryException("Exception processing results from Confluence");
}
}
use of ddf.catalog.transform.CatalogTransformerException in project ddf by codice.
the class TransformerConsumer method transform.
protected <T> T transform(Class<T> objClass, Object upstreamResponse, Map<String, Serializable> arguments) throws CatalogTransformerException {
LOGGER.debug("ENTERING: transform");
T content = null;
Exchange exchange = endpoint.createExchange();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("exchange pattern = {}", exchange.getPattern());
}
// Copy SourceResponse into message body and arguments into headers
Message in = exchange.getIn();
in.setBody(upstreamResponse);
for (Entry<String, Serializable> entry : arguments.entrySet()) {
in.setHeader(entry.getKey(), entry.getValue());
}
try {
// Send message to next processor in the route. This is configured to be a blocking
// call and will wait until the entire route completes and returns the result.
getProcessor().process(exchange);
LOGGER.debug("AFTER process(exchange)");
// Entire route has completed - get the output from the last node in the route.
content = exchange.getMessage().getBody(objClass);
// and it cannot be converted
if (null == content) {
LOGGER.debug("Unable to create {} - throwing exception", objClass.getName());
throw new CatalogTransformerException("Unable to create t" + objClass.getName());
}
} catch (Exception e) {
Exception e2 = exchange.getException();
if (e2 instanceof CatalogTransformerException) {
throw (CatalogTransformerException) e2;
}
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
} finally {
// log exception if an exception occurred and was not handled
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
}
LOGGER.debug("EXITING: transform");
return content;
}
Aggregations