Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

WebLogic 12.1.2 may not be listed on Oracle Technology Network Downloads page but it is still being used. When it comes to RESTful services on WebLogic, 12.1.2 supports Jersey 1.13 so if you're looking to make use of Jersey 2.x features, there's some extra work to be done. With 12.1.3 you can go straight for Jersey 2.x but that's outside the scope of this article.

There is an upgrade guide for Jersey in the WebLogic 12.1.2 documentation but it doesn't cover upgrading to Jersey 2.x. That is exactly what I wanted to do however, the process is very similar to the 1.x upgrade.

My approach to using Jersey 2.x was to first package it as a shared library. I've previously covered how to package shared libraries for WebLogic deployment so will not cover it again here. How you package Jersey depends on the features you use, but in the minimum the following is required as a dependency (change version as required) - Servlet based server-side application...
 pom.xml Maven Dependency
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25.1</version>
</dependency>


You're likely going to want other parts of Jersey as well, the modules list contains these. I had to use a number of media modules so I added those to my dependency list, e.g.
 Maven Dependency
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-jaxb</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
...




After the dependency list is put together, Maven can package and deploy the WAR file to WebLogic. That's not the end of the story though.

Assuming that your REST service is packaged as a WAR file, its weblogic.xml needs to be updated to reference the new shared library. That's just stock standard weblogic shared library usage. For example...
 weblogic.xml
<library-ref>
<library-name>jersey</library-name>
<specification-version>2.0</specification-version>
<implementation-version>2.25.1</implementation-version>
<exact-match>true</exact-match>
</library-ref>


So far everything has been boiler plate WebLogic J2EE deployments. Unfortunately if you try to deploy/start your REST service now and have used Jersey 2.x features, it will fail to start. That's because WebLogic is still going to try and use its built-in Jersey 1.13 library. The upgrade guide I mentioned earlier covers this as well in some detail, but here's what you actually need to do...

In weblogic.xml the prefer-application-packages element needs to have entries added for ALL OF THE PACKAGES in the Jersey 2.x shared library JAR files. That means you need to go through every jar file in WEB-INF/lib for the shared library that was created with Maven and make sure the packages it defines are included in this element. See this article for a script that will generate this information for you.

For example...
 weblogic.xml
<container-descriptor>
<prefer-application-packages>
<package-name>javax.ws.rs.*</package-name>
<package-name>org.glassfish.jersey.*</package-name>
...
</prefer-application-packages>
</container-descriptor>


The list of packages above is not exhaustive because it really depends on what features and modules of Jersey you require. Be sure not to use names that are too generic i.e. using the org.* package will cause problems. Once the package list in weblogic.xml is complete, your Jersey 2.x based REST service should deploy/start normally.

-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...