using Jackson annotations in Wildfly - jackson

I'm struggling to get Jackson Annotations to work in my project which is deployed in wildfly.
I already tried implementing a MessageBodyWriter but no success. My project looks like this: I have an ear with an ejb module which holds the annotated Pojos and I have a web module with the REST services. This is my current configuration / dependencies:
ejb-module pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.3</version>
<scope>provided</scope>
<type>jar</type>
</dependency>
rest-module pom.xml:
no jackson dependencies.
ear-project pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.0.6.Final</version>
</dependency>
ear-project /META-INF/jboss-deployment-structure.xml:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
but the jackson annotations are ignored. What am I missing? or did I do too much?

The RESTEasy and Jackson dependencies should be marked as <scope>provided</scope>.
Also if you're only using JAX-RS and Jackson in your WAR, just move jboss-deployment-structure.xml to your WAR/WEB-INF directory. If you don't want to move it you might need to add a <sub-deployment/>.
<jboss-deployment-structure>
<sub-deployment name="rest-module.war">
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
</dependencies>
</sub-deployment>
</jboss-deployment-structure>

Related

Can I make wso2 msf4j work with jersey?

WSO2 MSF4J to improve the size adds their own jaxrs-delegate which strips quite a bit of functionality from JAX-RS standard such as UriBuilder or BadRequestException
I've noted a few of the limitations of WSO2's MSF4J implementation https://github.com/wso2/msf4j/issues/290#issuecomment-329673266
So what I tried to do was see if I can replace the WSO2 jaxrs-delegate with Jersey instead. I excluded it from the core and tried to put in the jersey and jackson dependencies, but in the end it didn't work out.
I was wondering if this is even duable.
TL;DR
Set the BOMs (note don't use the latest versions as of the time of this writing)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.8.10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.26-b03</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Add the dependencies
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
Exclude the delegate from core
<dependency>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-core</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>org.wso2.msf4j</groupId>
<artifactId>jaxrs-delegates</artifactId>
</exclusion>
</exclusions>
</dependency>

Latest ExtentReports maven dependency for selenium

I have added this in my POM file.
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>
It is not working for my project.
Try to change this strings in pom.xml:
<properties>
<selenium.version>3.0.5</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
Your string <artifactId>extentreports</artifactId> probably should be writing earler in another block - it is not dependency, it is the Name of your Project.

JAX-RS provider registered but never invoked or called

Although we specify Jackson as jax-rs provider in blueprint.xml, we dont find it being invoked/called to convert our POJO to JSON. We use
CXF version - 3.0.3
Karaf version - 3.0.3
<jaxrs:server address="/test" id="totest">
<jaxrs:serviceBeans>
<ref component-id="testREST"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
We get following exception, we observe org.apache.cxf.jaxrs.provider.json.JSONProvider being called.
at org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleExceptionEnd(AbstractJAXBProvider.java:719)
at org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleJAXBException(AbstractJAXBProvider.java:743)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.writeTo(JSONProvider.java:395)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1363)
at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:244)
at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:117)
Updated Information
POM.xml with all related jars as dependency.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.6.16</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Thanks
You will need to provide all jackson related jars to the server - either as part of WEB-INF/lib of your web project, or as a server library, or as a module. It appears that you currently only have cxf.jar which is why jackson packaged within it is getting picked up. When you run the application on the server, at the time the execution thread reaches your jackson annotations, it tries to find the corresponding jars at runtime. The only related jar it can find then seems to be cxf.

Should we use jersey-media-json-jackson or jackson-jaxrs-json-provider in Jersey 2.5.1?

According to jersey spec, we can use jersey-media-json-jackson to serialize/deserialize json/pojo, however from some thread in StackOverflow, we can use also jackson-jaxrs-json-provider 2.2.3
Can you please advise which one we should use?
Thanks,
The right way to do it is to use something like this in your maven configuration (if you are using maven, of course):
...
<properties>
<jersey.version>2.5.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
...
TL;DR - you should use jersey-media-json-jackson 2.5.1
Using the jackson library directly might break some of the auto-discoverable features of jersey.

trying to override dependency of Apache Tika 0.9 from PDFBOX 1.4.0 to PDFBOX 1.6.0

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>0.9</version>
</dependency>
I was trying to add this below dependency instead of just above dependency of tika to override the dependency of Tika to PDFBOX 1.6.0 But its not working..
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>0.9</version>
<exclusions>
<exclusion>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.6.0</version>
</dependency>
Tika Parser has a dependency on PdfBox version 1.4.0. And I wanted to change this dependency of Apache Tika to PdfBox version 1.6.0. How can I do this in my Pom.xml file.
This is my pom.xml file. Any suggestions will be appreciated.
< project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz.search</groupId>
<artifactId>xyzz-crawler4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>qcom-crawler4j</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>repo-for-dsiutils</id>
<url>http://ir.dcs.gla.ac.uk/~bpiwowar/maven/</url>
</repository>
<repository>
<id>JBoss</id>
<name>jboss-maven2-release-repository</name>
<url>https://oss.sonatype.org/content/repositories/JBoss</url>
</repository>
<repository>
<id>oracle</id>
<url>http://download.oracle.com/maven</url>
</repository>
<repository>
<id>boilerpipe</id>
<url>http://boilerpipe.googlecode.com/svn/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
<!-- 4.1.1 -->
</dependency>
//PDFBOX version 1.6.0
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.0.1</version>
</dependency>
<!-- 4.1 -->
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>6.2.2</version>
</dependency>
<dependency>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
<version>4.0.71</version>
</dependency>
<!-- Boilerpipe -->
<dependency>
<groupId>de.l3s.boilerpipe</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.0</version>
</dependency>
<!-- Tika (for non-HTML extractions) -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>0.6.5</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>0.9</version>
</dependency>
**// I was trying to add this below dependency instead of just above dependency of tika to override the dependency of Tika to PDFBOX 1.6.0 But its not working..
<!-- <dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>0.9</version>
<exclusions>
<exclusion>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.6.0</version>
</dependency>
-->**
</dependencies>
</project>
The cleanest approach is probably to add a dependencyManagement section that upgrades the PDFBox version within your dependency tree. For example:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Note that many Tika parsers are tightly tied to specific versions of the upstream parser libraries like PDFBox, so you'll need to test the system well if you override the dependency versions like this.
An alternative to forcing a dependency version change is to use the latest trunk version of Tika where the PDFBox dependency is already at version 1.6.0. Also, the Tika 0.10 release that will use the updated dependency should be out already early next week.