mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-17703: TikaPowerMetadataExtracter Destroys Content on Failed Embed
- Removed catch of exception and closing of output stream in TikaPoweredMetadataExtracter to allow AbstractMappingMetadataExtracter to better handle the error - Added catch of ContentIOException during construction of error details in AbstractMappingMetadataExtracter - Added ContentMetadataEmbedderTest to test a failing embedder git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@45949 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -375,38 +375,23 @@ public abstract class TikaPoweredMetadataExtracter
|
||||
{
|
||||
return;
|
||||
}
|
||||
OutputStream outputStream = null;
|
||||
try
|
||||
|
||||
Metadata metadataToEmbed = new Metadata();
|
||||
for (String metadataKey : properties.keySet())
|
||||
{
|
||||
Metadata metadataToEmbed = new Metadata();
|
||||
for (String metadataKey : properties.keySet())
|
||||
Serializable value = properties.get(metadataKey);
|
||||
if (value == null)
|
||||
{
|
||||
Serializable value = properties.get(metadataKey);
|
||||
if (value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (value instanceof Collection<?>)
|
||||
{
|
||||
for (Object singleValue : (Collection<?>) value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Convert to a string value for Tika
|
||||
metadataToEmbed.add(metadataKey, DefaultTypeConverter.INSTANCE.convert(String.class, singleValue));
|
||||
}
|
||||
catch (TypeConversionException e)
|
||||
{
|
||||
logger.info("Could not convert " + metadataKey + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if (value instanceof Collection<?>)
|
||||
{
|
||||
for (Object singleValue : (Collection<?>) value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Convert to a string value for Tika
|
||||
metadataToEmbed.add(metadataKey, DefaultTypeConverter.INSTANCE.convert(String.class, value));
|
||||
metadataToEmbed.add(metadataKey, DefaultTypeConverter.INSTANCE.convert(String.class, singleValue));
|
||||
}
|
||||
catch (TypeConversionException e)
|
||||
{
|
||||
@@ -414,22 +399,22 @@ public abstract class TikaPoweredMetadataExtracter
|
||||
}
|
||||
}
|
||||
}
|
||||
InputStream inputStream = getInputStream(reader);
|
||||
outputStream = writer.getContentOutputStream();
|
||||
embedder.embed(metadataToEmbed, inputStream, outputStream, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (outputStream != null)
|
||||
else
|
||||
{
|
||||
try { outputStream.close(); } catch (Throwable e) {}
|
||||
try
|
||||
{
|
||||
// Convert to a string value for Tika
|
||||
metadataToEmbed.add(metadataKey, DefaultTypeConverter.INSTANCE.convert(String.class, value));
|
||||
}
|
||||
catch (TypeConversionException e)
|
||||
{
|
||||
logger.info("Could not convert " + metadataKey + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputStream inputStream = getInputStream(reader);
|
||||
OutputStream outputStream = writer.getContentOutputStream();
|
||||
embedder.embed(metadataToEmbed, inputStream, outputStream, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user