Source:
protected Object transform( Message in, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, CatalogTransformerException { MimeType derivedMimeType = null; try (InputStream message = in.getBody(InputStream.class); TemporaryFileBackedOutputStream tfbos = new TemporaryFileBackedOutputStream()) { if (message == null) { throw new CatalogTransformerException( "Message body was null; unable to generate Metacard!"); } IOUtils.copy(message, tfbos); String fileExtensionHeader = getHeaderAsStringAndRemove(in, FILE_EXTENSION_HEADER); if (StringUtils.isNotEmpty(fileExtensionHeader)) { Optional<String> fileMimeType = getMimeTypeFor(tfbos.asByteSource().openBufferedStream(), fileExtensionHeader); if (fileMimeType.isPresent()) { LOGGER.trace( "Setting mimetype to from Message header [{}]", fileMimeType.get(), FILE_EXTENSION_HEADER); derivedMimeType = new MimeType(fileMimeType.get()); } } if (derivedMimeType == null) { if (StringUtils.isNotEmpty(mimeType)) { if (StringUtils.isNotEmpty(transformerId)) { derivedMimeType = new MimeType( mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId); LOGGER.trace("Using mimeType to [{}]", derivedMimeType); } else { LOGGER.trace("Using CatalogEndpoint's configured mimeType [{}]", mimeType); derivedMimeType = new MimeType(mimeType); } } else { LOGGER.debug("Unable to determine mimeType. Defaulting to [{}]", DEFAULT_MIME_TYPE); derivedMimeType = new MimeType(DEFAULT_MIME_TYPE); } } String metacardUpdateID = getHeaderAsStringAndRemove(in, METACARD_ID_HEADER); return generateMetacard(derivedMimeType, mapper, tfbos, metacardUpdateID) .orElseThrow( () -> new CatalogTransformerException( String.format( "Did not find an InputTransformer for MIME Type [%s] and %s [%s]", mimeType, MimeTypeToTransformerMapper.ID_KEY, transformerId))); } catch (IOException e) { LOGGER.debug("Failed to get mimeType by reading input stream", e); } throw new CatalogTransformerException("Unable to transform incoming product"); }

Target:
protected Object transform( Message in, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, CatalogTransformerException { MimeType derivedMimeType = null; try (InputStream message = in.getBody(InputStream.class); TemporaryFileBackedOutputStream tfbos = new TemporaryFileBackedOutputStream()) { if (message == null) { throw new CatalogTransformerException( "Message body was null; unable to generate Metacard!"); } IOUtils.copy(message, tfbos); String fileExtensionHeader = getHeaderAsStringAndRemove(in, FILE_EXTENSION_HEADER); if (StringUtils.isNotEmpty(fileExtensionHeader)) { Optional<String> fileMimeType = getMimeTypeFor(tfbos.asByteSource().openBufferedStream(), fileExtensionHeader); if (fileMimeType.isPresent()) { LOGGER.trace( "Setting mimetype to from Message header [{}]", fileMimeType.get(), FILE_EXTENSION_HEADER); derivedMimeType = new MimeType(fileMimeType.get()); } } if (derivedMimeType == null) { if (StringUtils.isNotEmpty(mimeType)) { if (StringUtils.isNotEmpty(transformerId)) { derivedMimeType = new MimeType( mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId); LOGGER.trace("Using mimeType to [{}]", derivedMimeType); } else { LOGGER.trace("Using CatalogEndpoint's configured mimeType [{}]", mimeType); derivedMimeType = new MimeType(mimeType); } } else { LOGGER.debug("Unable to determine mimeType. Defaulting to [{}]", DEFAULT_MIME_TYPE); derivedMimeType = new MimeType(DEFAULT_MIME_TYPE); } } String metacardUpdateID = getHeaderAsStringAndRemove(in, METACARD_ID_HEADER); return generateMetacard(derivedMimeType, mapper, tfbos, metacardUpdateID) .orElseThrow( () -> new CatalogTransformerException( String.format( "Did not find an InputTransformer for MIME Type [%s] and %s [%s]", mimeType, MimeTypeToTransformerMapper.ID_KEY, transformerId))); } catch (IOException e) { throw new CatalogTransformerException("Unable to transform incoming product", e); } }