From 1aefecf331373f0678fdfbfdd134a0a501e41573 Mon Sep 17 00:00:00 2001 From: Peter Huffer Date: Wed, 7 Mar 2018 17:39:53 -0700 Subject: [PATCH] DDF-3660 Update CDM in place monitoring to CreateRequests (#3033) * Update CDM in-place monitoring to send create requests instead of create storage requests * Update LocalResourceRetriever to account for derived content * Remove EventfulFileWrapper and change DurableFileEndpoint to File type --- .../java/ddf/catalog/data/types/Core.java | 3 +- .../core/catalog-core-camelcomponent/pom.xml | 4 +- .../component/catalog/CatalogComponent.java | 22 ++- .../component/catalog/CatalogEndpoint.java | 13 +- .../catalog/content/ContentComponent.java | 2 +- .../catalog/framework/FrameworkProducer.java | 51 +++--- .../InputTransformerProducer.java | 106 +++++++---- .../QueryResponseTransformerProducer.java | 10 +- .../transformer/TransformerProducer.java | 32 ++-- .../OSGI-INF/blueprint/blueprint.xml | 25 +-- .../catalog-core-directorymonitor/pom.xml | 6 +- .../monitor/AbstractDurableFileConsumer.java | 116 +++++++----- .../monitor/ContentDirectoryMonitor.java | 44 ++++- .../monitor/DavAlterationObserver.java | 2 +- .../ddf/catalog/content/monitor/DavEntry.java | 4 +- .../DurableFileAlterationListener.java | 170 ++++++++++-------- .../content/monitor/DurableFileComponent.java | 4 +- .../content/monitor/DurableFileEndpoint.java | 21 ++- .../DurableFileSystemFileConsumer.java | 4 +- .../monitor/DurableWebDavFileConsumer.java | 118 ++++++++---- .../content/monitor/EventfulFileWrapper.java | 47 ----- .../FileSystemPersistenceProvider.java | 5 + .../monitor/InPlaceMetacardProcessor.java | 166 +++++++++++++++++ .../DeletionSynchronization.java | 62 +++++++ .../FileToMetacardMappingSynchronization.java | 67 +++++++ .../content/monitor/watcher/FileWatcher.java | 78 ++++++++ .../content/monitor/watcher/FilesWatcher.java | 123 +++++++++++++ .../OSGI-INF/blueprint/blueprint.xml | 9 +- .../resources/OSGI-INF/metatype/metatype.xml | 2 +- .../monitor/ContentDirectoryMonitorTest.java | 5 +- .../DurableFileAlterationListenerTest.java | 123 ------------- .../monitor/watcher/FileWatcherTest.java | 55 ++++++ .../impl/operations/ResourceOperations.java | 2 +- .../LocalResourceRetriever.java | 123 ++++++++++--- .../LocalResourceRetrieverSpec.groovy | 73 ++++++++ .../DownloadsStatusEventListenerTest.java | 3 +- .../_tables/ContentDirectoryMonitor.adoc | 2 +- .../content/_tables/URLResourceReader.adoc | 1 + 38 files changed, 1217 insertions(+), 486 deletions(-) delete mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/EventfulFileWrapper.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/InPlaceMetacardProcessor.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/synchronizations/DeletionSynchronization.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/synchronizations/FileToMetacardMappingSynchronization.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/watcher/FileWatcher.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/main/java/org/codice/ddf/catalog/content/monitor/watcher/FilesWatcher.java delete mode 100644 catalog/core/catalog-core-directorymonitor/src/test/java/org/codice/ddf/catalog/content/monitor/DurableFileAlterationListenerTest.java create mode 100644 catalog/core/catalog-core-directorymonitor/src/test/java/org/codice/ddf/catalog/content/monitor/watcher/FileWatcherTest.java create mode 100644 catalog/core/catalog-core-standardframework/src/test/groovy/ddf/catalog/resourceretriever/LocalResourceRetrieverSpec.groovy diff --git a/catalog/core/catalog-core-api/src/main/java/ddf/catalog/data/types/Core.java b/catalog/core/catalog-core-api/src/main/java/ddf/catalog/data/types/Core.java index 6e1015dd51dd..d2ecb31610fa 100644 --- a/catalog/core/catalog-core-api/src/main/java/ddf/catalog/data/types/Core.java +++ b/catalog/core/catalog-core-api/src/main/java/ddf/catalog/data/types/Core.java @@ -96,7 +96,8 @@ public interface Core { /** * {@link ddf.catalog.data.Attribute} name for accessing the resource download URL for the product - * this {@link ddf.catalog.data.Metacard} represents.
+ * this {@link ddf.catalog.data.Metacard} represents. Typically, the framework will write this + * attribute based on the {@link Core#RESOURCE_URI}, and it should not be set directly.
*/ String RESOURCE_DOWNLOAD_URL = "resource-download-url"; diff --git a/catalog/core/catalog-core-camelcomponent/pom.xml b/catalog/core/catalog-core-camelcomponent/pom.xml index 3669c34576ca..93a6d76fdbc2 100644 --- a/catalog/core/catalog-core-camelcomponent/pom.xml +++ b/catalog/core/catalog-core-camelcomponent/pom.xml @@ -182,12 +182,12 @@ INSTRUCTION COVEREDRATIO - 0.66 + 0.63 BRANCH COVEREDRATIO - 0.53 + 0.50 COMPLEXITY diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/CatalogComponent.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/CatalogComponent.java index 08e5b33b5d6a..0ad92d5c4f18 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/CatalogComponent.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/CatalogComponent.java @@ -15,6 +15,7 @@ import ddf.catalog.CatalogFramework; import ddf.catalog.transform.CatalogTransformerException; +import ddf.mime.MimeTypeMapper; import ddf.mime.MimeTypeToTransformerMapper; import java.util.Map; import org.apache.camel.Endpoint; @@ -39,7 +40,7 @@ public class CatalogComponent extends DefaultComponent { /** The name of the scheme this custom Camel component resolves to. */ public static final String NAME = "catalog"; - private static final transient Logger LOGGER = LoggerFactory.getLogger(CatalogComponent.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CatalogComponent.class); private BundleContext bundleContext; @@ -47,6 +48,8 @@ public class CatalogComponent extends DefaultComponent { private CatalogFramework catalogFramework; + private MimeTypeMapper mimeTypeMapper; + public CatalogComponent() { super(); LOGGER.debug("INSIDE CatalogComponent constructor"); @@ -60,12 +63,11 @@ public CatalogComponent() { */ protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws CatalogTransformerException { - LOGGER.debug("ENTERING: createEndpoint"); + LOGGER.trace("ENTERING: createEndpoint"); - LOGGER.debug("uri = {}, remaining = {}", uri, remaining); - LOGGER.debug("parameters = {}", parameters); + LOGGER.debug( + "CatalogEndpoint: uri = {}, remaining = {}, parameters = {}", uri, remaining, parameters); - String contextPath = remaining; String transformerId = getAndRemoveParameter(parameters, ID_PARAMETER, String.class); String mimeType = getAndRemoveParameter(parameters, MIME_TYPE_PARAMETER, String.class); @@ -73,15 +75,15 @@ protected Endpoint createEndpoint(String uri, String remaining, Mapcatalog component. * @@ -76,7 +79,8 @@ public CatalogEndpoint( String transformerId, String mimeType, String contextPath, - CatalogFramework catalogFramework) { + CatalogFramework catalogFramework, + MimeTypeMapper mimeTypeMapper) { super(uri, component); LOGGER.debug( "INSIDE CamelCatalogEndpoint(uri, component, transformerId, contextPath, catalogFramework) constructor"); @@ -84,6 +88,7 @@ public CatalogEndpoint( this.mimeType = mimeType; this.contextPath = contextPath; this.catalogFramework = catalogFramework; + this.mimeTypeMapper = mimeTypeMapper; setSynchronous(true); } @@ -178,6 +183,10 @@ public String getMimeType() { return mimeType; } + public MimeTypeMapper getMimeTypeMapper() { + return mimeTypeMapper; + } + /* * (non-Javadoc) * diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/content/ContentComponent.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/content/ContentComponent.java index c8072683cf01..f6261427c38c 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/content/ContentComponent.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/content/ContentComponent.java @@ -26,7 +26,7 @@ public class ContentComponent extends DefaultComponent { /** The name of the scheme this custom Camel component resolves to. */ public static final String NAME = "content"; - private static final transient Logger LOGGER = LoggerFactory.getLogger(ContentComponent.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ContentComponent.class); private CatalogFramework catalogFramework; diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/framework/FrameworkProducer.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/framework/FrameworkProducer.java index 8de231884863..effda6d7ce69 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/framework/FrameworkProducer.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/framework/FrameworkProducer.java @@ -89,7 +89,7 @@ */ public class FrameworkProducer extends DefaultProducer { - private static final transient Logger LOGGER = LoggerFactory.getLogger(FrameworkProducer.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkProducer.class); private static final String CREATE_OPERATION = "CREATE"; @@ -99,6 +99,8 @@ public class FrameworkProducer extends DefaultProducer { private static final String OPERATION_HEADER_KEY = "operation"; + private static final String OBJECT_IS_NULL_MSG = "Catalog response object is null"; + private CatalogFramework catalogFramework; /** @@ -118,12 +120,12 @@ public void process(Exchange exchange) throws FrameworkProducerException { LOGGER.debug("Entering process method"); final Object operationValueObj = exchange.getIn().getHeader(OPERATION_HEADER_KEY); - String operation = null; + String operation; if (operationValueObj == null) { exchange.getIn().setBody(new ArrayList()); - - throw new FrameworkProducerException("Missing expected header!"); + throw new FrameworkProducerException( + String.format("Missing expected [%s] header!", OPERATION_HEADER_KEY)); } operation = operationValueObj.toString(); @@ -145,12 +147,9 @@ public void process(Exchange exchange) throws FrameworkProducerException { } catch (ClassCastException cce) { exchange.getIn().setBody(new ArrayList()); LOGGER.debug("Received a non-String as the operation type"); - } catch (SourceUnavailableException sue) { - exchange.getIn().setBody(new ArrayList()); - LOGGER.debug("Exception cataloging metacards", sue); - } catch (IngestException ie) { + } catch (SourceUnavailableException | IngestException e) { exchange.getIn().setBody(new ArrayList()); - LOGGER.debug("Exception cataloging metacards", ie); + LOGGER.debug("Exception cataloging metacards", e); } } @@ -365,14 +364,12 @@ private void delete(final Exchange exchange) * @return true if the list is not empty and has valid types inside, else false. */ private boolean validateList(List list, Class cls) { - if (list.size() == 0) { + if (list.isEmpty()) { LOGGER.debug("No Metacard or Metacard IDs to process"); return false; } - for (int i = 0; i < list.size(); i++) { - final Object o = list.get(i); - + for (final Object o : list) { if (!cls.isInstance(o)) { LOGGER.debug("Received a list of non-{} objects", cls.getName()); return false; @@ -390,14 +387,14 @@ private boolean validateList(List list, Class cls) { */ private void processCatalogResponse(final CreateResponse response, final Exchange exchange) { if (response == null) { - LOGGER.debug("Catalog response object is null"); - exchange.getIn().setBody((List) (new ArrayList())); + LOGGER.debug(OBJECT_IS_NULL_MSG); + exchange.getIn().setBody(new ArrayList()); return; } if (response.getCreatedMetacards() == null) { LOGGER.debug("No Metacards created by catalog framework"); - exchange.getIn().setBody((List) (new ArrayList())); + exchange.getIn().setBody(new ArrayList()); return; } @@ -412,14 +409,14 @@ private void processCatalogResponse(final CreateResponse response, final Exchang */ private void processCatalogResponse(final UpdateResponse response, final Exchange exchange) { if (response == null) { - LOGGER.debug("Catalog response object is null"); - exchange.getIn().setBody((List) (new ArrayList())); + LOGGER.debug(OBJECT_IS_NULL_MSG); + exchange.getIn().setBody(new ArrayList()); return; } if (response.getUpdatedMetacards() == null) { LOGGER.debug("No Metacards updated by catalog framework"); - exchange.getIn().setBody((List) (new ArrayList())); + exchange.getIn().setBody(new ArrayList()); return; } @@ -434,14 +431,14 @@ private void processCatalogResponse(final UpdateResponse response, final Exchang */ private void processCatalogResponse(final DeleteResponse response, final Exchange exchange) { if (response == null) { - LOGGER.debug("Catalog response object is null"); - exchange.getIn().setBody((List) (new ArrayList())); + LOGGER.debug(OBJECT_IS_NULL_MSG); + exchange.getIn().setBody(new ArrayList()); return; } if (response.getDeletedMetacards() == null) { LOGGER.debug("No Metacards deleted by catalog framework"); - exchange.getIn().setBody((List) (new ArrayList())); + exchange.getIn().setBody(new ArrayList()); return; } @@ -455,7 +452,7 @@ private void processCatalogResponse(final DeleteResponse response, final Exchang * @return {@link java.util.List} of {@link String} representing Metacard IDs */ private List readBodyDataAsMetacardIds(final Exchange exchange) { - List metacardIdsToBeProcessed = new ArrayList(); + List metacardIdsToBeProcessed = new ArrayList<>(); try { if (exchange.getIn().getBody() == null) { @@ -478,7 +475,7 @@ private List readBodyDataAsMetacardIds(final Exchange exchange) { final String metacardIdToBeProcessed = exchange.getIn().getBody(String.class); if (metacardIdToBeProcessed != null) { - metacardIdsToBeProcessed = new ArrayList(); + metacardIdsToBeProcessed = new ArrayList<>(); metacardIdsToBeProcessed.add(metacardIdToBeProcessed); LOGGER.debug("Successfully read in body data as String"); return metacardIdsToBeProcessed; @@ -486,7 +483,7 @@ private List readBodyDataAsMetacardIds(final Exchange exchange) { // if we get here, we neither had String or List, so set a // default list - metacardIdsToBeProcessed = new ArrayList(); + metacardIdsToBeProcessed = new ArrayList<>(); } catch (TypeConversionException tce1) { LOGGER.debug("Invalid message body. Expected either String or List", tce1); } @@ -501,7 +498,7 @@ private List readBodyDataAsMetacardIds(final Exchange exchange) { * @return {@link java.util.List} of Metacard objects */ private List readBodyDataAsMetacards(final Exchange exchange) { - List metacardsToProcess = new ArrayList(); + List metacardsToProcess = new ArrayList<>(); try { if (exchange.getIn().getBody() == null) { @@ -526,7 +523,7 @@ private List readBodyDataAsMetacards(final Exchange exchange) { metacardsToProcess = exchange.getIn().getBody(List.class); if (metacardsToProcess == null) { LOGGER.debug("Problem reading in body data as List"); - metacardsToProcess = new ArrayList(); + metacardsToProcess = new ArrayList<>(); return metacardsToProcess; } LOGGER.debug("Successfully read in body data as List"); diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/inputtransformer/InputTransformerProducer.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/inputtransformer/InputTransformerProducer.java index e04272e2a6b0..bbf4d184f8d5 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/inputtransformer/InputTransformerProducer.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/inputtransformer/InputTransformerProducer.java @@ -19,6 +19,7 @@ import ddf.catalog.data.MetacardCreationException; import ddf.catalog.transform.CatalogTransformerException; import ddf.catalog.transform.InputTransformer; +import ddf.mime.MimeTypeResolutionException; import ddf.mime.MimeTypeToTransformerMapper; import java.io.IOException; import java.io.InputStream; @@ -27,6 +28,7 @@ import javax.activation.MimeTypeParseException; import org.apache.camel.Message; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.codice.ddf.platform.util.TemporaryFileBackedOutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,8 +43,12 @@ * @author ddf.isgs@lmco.com */ public class InputTransformerProducer extends TransformerProducer { - private static final transient Logger LOGGER = - LoggerFactory.getLogger(InputTransformerProducer.class); + private static final Logger LOGGER = LoggerFactory.getLogger(InputTransformerProducer.class); + + private static final String METACARD_ID_HEADER = + "org.codice.ddf.camel.transformer.MetacardUpdateId"; + + private static final String FILE_EXTENSION_HEADER = "org.codice.ddf.camel.FileExtension"; /** * Constructs the {@link org.apache.camel.Producer} for the custom Camel CatalogComponent. This @@ -56,34 +62,44 @@ public InputTransformerProducer(CatalogEndpoint endpoint) { } 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) { + Message in, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) + throws MimeTypeParseException, CatalogTransformerException { + InputStream message = in.getBody(InputStream.class); + if (message == null) { + throw new CatalogTransformerException("Message body was null; unable to generate Metacard!"); + } + + MimeType derivedMimeType = null; + if (StringUtils.isEmpty(mimeType)) { + try (TemporaryFileBackedOutputStream fileBackedOutputStream = + new TemporaryFileBackedOutputStream()) { + try { + IOUtils.copy(message, fileBackedOutputStream); + derivedMimeType = + new MimeType( + getMimeTypeFromHeader(in, fileBackedOutputStream.asByteSource().openStream())); + } catch (IOException e) { + LOGGER.debug("Failed to copy incoming inputStream message", e); + } finally { + message = fileBackedOutputStream.asByteSource().openStream(); + } + } catch (IOException e) { + LOGGER.debug("Failed to create TemporaryFileBackedOuputStream", e); + } + } else if (StringUtils.isNotBlank(transformerId)) { derivedMimeType = new MimeType(mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId); } - InputStream message = null; - Metacard metacard = null; + if (derivedMimeType == null) { + derivedMimeType = new MimeType(mimeType); + } + + String metacardUpdateID = getHeaderAsStringAndRemove(in, METACARD_ID_HEADER); + + Metacard metacard; 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!"); - } + metacard = generateMetacard(derivedMimeType, mapper, message, metacardUpdateID); } catch (MetacardCreationException e) { throw new CatalogTransformerException( "Did not find an InputTransformer for MIME Type [" @@ -95,16 +111,14 @@ protected Object transform( + "]", e); } finally { - if (null != message) { - IOUtils.closeQuietly(message); - } + IOUtils.closeQuietly(message); } return metacard; } private Metacard generateMetacard( - MimeType mimeType, MimeTypeToTransformerMapper mapper, InputStream message) + MimeType mimeType, MimeTypeToTransformerMapper mapper, InputStream message, String metacardId) throws MetacardCreationException { LOGGER.trace("ENTERING: generateMetacard"); @@ -133,9 +147,13 @@ private Metacard generateMetacard( try (InputStream inputStreamMessageCopy = fileBackedOutputStream.asByteSource().openStream()) { - generatedMetacard = transformer.transform(inputStreamMessageCopy); + if (StringUtils.isEmpty(metacardId)) { + generatedMetacard = transformer.transform(inputStreamMessageCopy); + } else { + generatedMetacard = transformer.transform(inputStreamMessageCopy, metacardId); + } } catch (IOException | CatalogTransformerException e) { - LOGGER.debug("Transformer [" + transformer + "] could not create metacard.", e); + LOGGER.debug("Transformer [{}] could not create metacard.", transformer, e); } if (generatedMetacard != null) { break; @@ -156,4 +174,30 @@ private Metacard generateMetacard( return generatedMetacard; } + + private String getMimeTypeFromHeader(Message in, InputStream is) { + String fileExtension = getHeaderAsStringAndRemove(in, FILE_EXTENSION_HEADER); + if (fileExtension == null) { + return null; + } + + try { + return ((CatalogEndpoint) getEndpoint()).getMimeTypeMapper().guessMimeType(is, fileExtension); + } catch (MimeTypeResolutionException e) { + LOGGER.debug( + "Failed to get mimeType for file extension [{}] received from exchange headers."); + return null; + } + } + + private String getHeaderAsStringAndRemove(Message message, String key) { + String value = message.getHeader(key, String.class); + if (value != null) { + LOGGER.trace( + "Retrieved and removed header [{}] from exchange message [{}]", message.getMessageId()); + message.removeHeader(key); + return value; + } + return null; + } } diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/queryresponsetransformer/QueryResponseTransformerProducer.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/queryresponsetransformer/QueryResponseTransformerProducer.java index 38a1393dacae..86c9c0db159a 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/queryresponsetransformer/QueryResponseTransformerProducer.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/queryresponsetransformer/QueryResponseTransformerProducer.java @@ -38,7 +38,7 @@ * @author ddf.isgs@lmco.com */ public class QueryResponseTransformerProducer extends TransformerProducer { - private static final transient Logger LOGGER = + private static final Logger LOGGER = LoggerFactory.getLogger(QueryResponseTransformerProducer.class); /** @@ -52,11 +52,7 @@ public QueryResponseTransformerProducer(CatalogEndpoint endpoint) { } protected Object transform( - Message in, - Object obj, - String mimeType, - String transformerId, - MimeTypeToTransformerMapper mapper) + Message in, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, CatalogTransformerException { // Look up the QueryResponseTransformer for the request's mime type. // If a transformer is found, then transform the request's payload into a BinaryContent @@ -73,7 +69,7 @@ protected Object transform( Object binaryContent = null; if (matches != null && matches.size() == 1) { - Map arguments = new HashMap(); + Map arguments = new HashMap<>(); for (Entry entry : in.getHeaders().entrySet()) { if (entry.getValue() instanceof Serializable) { arguments.put(entry.getKey(), (Serializable) entry.getValue()); diff --git a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/transformer/TransformerProducer.java b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/transformer/TransformerProducer.java index 96636c6aedcc..afa9b30566f4 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/transformer/TransformerProducer.java +++ b/catalog/core/catalog-core-camelcomponent/src/main/java/ddf/camel/component/catalog/transformer/TransformerProducer.java @@ -34,13 +34,15 @@ * @author ddf.isgs@lmco.com */ public abstract class TransformerProducer extends DefaultProducer { - private static final transient Logger LOGGER = LoggerFactory.getLogger(TransformerProducer.class); + + private static final Logger LOGGER = LoggerFactory.getLogger(TransformerProducer.class); private CatalogEndpoint endpoint; /** - * Constructs the {@link Producer} for the custom Camel CatalogComponent. This producer would map - * to a Camel route node with a URI like catalog:inputtransformer + * Constructs the {@link org.apache.camel.Producer} for the custom Camel CatalogComponent. This + * producer would map to a Camel route node with a URI like catalog:inputtransformer + * * * @param endpoint the Camel endpoint that created this consumer */ @@ -59,13 +61,10 @@ public TransformerProducer(CatalogEndpoint endpoint) { */ public void process(Exchange exchange) throws CatalogTransformerException, MimeTypeParseException, IOException { - - LOGGER.debug("ENTERING: process"); - + LOGGER.trace("ENTERING: process"); LOGGER.debug("exchange pattern = {}", exchange.getPattern()); Message in = exchange.getIn(); - Object metacard = null; // Get the MIME Type and ID of the transformer to use to transform the // request's payload from the endpoint that manages this producer @@ -87,7 +86,9 @@ public void process(Exchange exchange) if (mimeType != null) { in.removeHeader(CatalogComponent.MIME_TYPE_PARAMETER); } else { - LOGGER.debug("MIME Type retrieved from CamelCatalogEndpoint"); + LOGGER.debug( + "No mimeType provided, defaulting to Camel CatalogEndpoint mimeType of [{}]", + endpoint.getMimeType()); mimeType = endpoint.getMimeType(); } @@ -95,26 +96,23 @@ public void process(Exchange exchange) MimeTypeToTransformerMapper mapper = endpoint.getComponent().getMimeTypeToTransformerMapper(); + Object metacard; if (mapper != null) { LOGGER.debug("Got a MimeTypeToTransformerMapper service"); - metacard = transform(in, metacard, mimeType, transformerId, mapper); + metacard = transform(in, mimeType, transformerId, mapper); } else { LOGGER.debug("Did not find a MimeTypeToTransformerMapper service"); throw new CatalogTransformerException("Did not find a MimeTypeToTransformerMapper service"); } - // Set the response output to the Metacard from the transformation - exchange.getOut().setBody(metacard); + // Set the body to the Metacard from the transformation + in.setBody(metacard); - LOGGER.debug("EXITING: process"); + LOGGER.trace("EXITING: process"); } protected abstract Object transform( - Message in, - Object metacard, - String mimeType, - String transformerId, - MimeTypeToTransformerMapper mapper) + Message in, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, IOException, CatalogTransformerException; } diff --git a/catalog/core/catalog-core-camelcomponent/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/catalog/core/catalog-core-camelcomponent/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 57ebe00b5a47..72447b112c6a 100644 --- a/catalog/core/catalog-core-camelcomponent/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/catalog/core/catalog-core-camelcomponent/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -15,7 +15,7 @@ xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd" - > +> @@ -23,24 +23,27 @@ - + - - + + - + + - - + + - - - - + + + +