Confluence plugin - apache tika parser issue - emptyparser

Hi,
I’m trying to integrate apache tika parser to parse the attachments uploaded to Confluence. I have an independent maven project where it works perfectly. But when I add the same dependencies in the confluence plugin pom, it builds correctly (I see all the files in the jar file built), but it doesn’t work during run time. The “AutoDetectParser” yields “EmptyParser”.

    Parser parser = new AutoDetectParser();
  	BodyContentHandler handler = new BodyContentHandler();
  	Metadata metadata = new Metadata();
  	InputStream content = attachmentManager.getAttachmentData(attachment);
  	parser.parse(content, handler, metadata, new ParseContext());

pom.xml dependencies:

    <dependency>
	    <groupId>org.apache.tika</groupId>
	    <artifactId>tika-parsers</artifactId>
	    <version>1.16</version>
	</dependency>

	<dependency>
	    <groupId>org.apache.tika</groupId>
	    <artifactId>tika-core</artifactId>
	    <version>1.16</version>
	</dependency>

Has any one else tried this? Any clues? Please help!!

I was thinking if this was the cause of the issue is :

Also, tried removing the whole block and building the plugin and deploying. The plugin builds fine, but doesn’t get deployed. No errors in logs. It just takes too long to deploy and in the end it doesn’t get enabled.

Seems like there was an error in the logs:

Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle examplePlugin [259]: Unable to resolve 259.0: missing requirement [259.0] osgi.wiring.package; (osgi.wiring.package=android.util)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:399)
… 111 more

Hi @sameer.v,
have you tried setting the scope explicitly? Add <scope>compile</scope> to each of your dependencies.
Best regards
Alex

Thanks @alexander.botor for the response!
Yes, I did try setting the scope for compile explicitly. Also, tried runtime with optional. Neither worked.
This was too complex for me. I created an external microservice for this purpose and called that service for parsing for now.

But, would definitely like to know if anyone has had a chance to solve this within Confluence plugin context.