I have a very similar issue, but using Tika on Karaf vs. eclipse.
I am using Tika v1.2 and Karaf v2.2.7 on Windows 7.
I have made an OSGi bundle that uses Tika and provides a
getFileExtensionForMimeType(...) method. I have added a
org/apache/tika/mime/custom-mimetypes.xml file to my src/main/resources
directory. I have made a custom parser and added a
META-INF/services/org.apache.tika.parser.Parser file that lists it (although
I am not trying to use the custom parser yet).
When another bundle invokes this bundle's getFileExtensionForMimeType(...)
method it works for mime types that Tika supports by default, but it does
not find the mime types in my custom-mimetypes.xml file.
It's like this custom mime types file is not found by the OSGi container.
Any help is appreciated.
Here is my method's code:
public String getFileExtensionForMimeType( String contentType ) throws
MimeTypeException
{
//TikaConfig config = TikaConfig.getDefaultConfig(); // this did
not work for custom mime types
TikaConfig config = null;
try
{
config = new TikaConfig( this.getClass().getClassLoader() );
}
catch ( IOException e )
{
logger.warn( "Error creating TikaConfig with ClassLoader", e );
return null;
}
MimeTypes mimeTypes = config.getMimeRepository();
String extension = null;
try
{
MimeType mimeType = mimeTypes.forName( contentType );
extension = mimeType.getExtension();
}
catch ( Exception e )
{
logger.warn( "Exception caught getting file extension for mime
type" + contentType, e );
}
logger.debug( "mimeType = " + contentType + ", file extension = ["
+ extension + "]" );
return extension;
}
And here is my custom-mimetypes.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info>
<mime-type type="image/nitf">
<alias type="image/ntf"/>
<glob pattern="*.nitf"/>
</mime-type>
</mime-info>
I have verified my input is "image/nitf" mime type. This method worked when
the input was "application/octet-stream", it returned ".bin"
--
View this message in context:
http://apache-tika-users.1629097.n2.nabble.com/using-tika-with-eclipse-tp7572799p7572828.html
Sent from the Apache Tika - Users mailing list archive at Nabble.com.