Jersey and other JAX-RS api extensions - e.g. Shiro, Guice - jersey

Does Jersey got any extensions to support frameworks like Shiro, Guice for example? Or do you use them seperately, independent from jersey?
How does it look for other JAX-RS frameworks. Restlet, RestEasy - do they provide any extensions or is it done seperately as well?
I already know that they got their own implementation of OAuth instead of cooperating with other OAuth framworks.

Regarding Restlet Framework, we offer an extensive set of extensions summarized here. It is however generally easy to do your own integration with other libraries. Regarding Guice, there is already an extension in the Restlet Incubator, see specifications here.

The dependency page of the Jersey docs specifies there are extensions for Guice:
Jersey's runtime dependences are categorized into the following:
Core server. The minimum set of dependences that Jersey requires for
the server.
Core client. The minimum set of dependences that Jersey requires for
the client.
Container. The set of container dependences. Each container provider
has it's own set of dependences.
Entity. The set of entity dependencies. Each entity provider has it's
own set of dependences.
Tools. The set of dependencies required for runtime tooling.
Spring. The set of dependencies required for Spring.
Guice. The set of dependencies required for Guice.
I have not tried integrating Jersey, Guice, and Shiro, but I don't see why you couldn't do it.

Related

Which dependency should be used to integrate Apache Camel with Spring Boot

Apache Camel provides two ways to integrate with Spring Boot:
camel-spring-boot
camel-spring-boot-starter
When I look at the starter then I see that it only includes camel-spring-boot and spring-boot-starter. What is the difference then and what are the advantages of using starter?
At the moment of writing this answer, camel-spring-boot is only supported from Camel 2.15 and camel-spring-boot-starter only from Camel 2.17, which is important considering the current version that your project is using.
Then the major difference between these two dependencies, lies in the "opinionated" auto-configuration provided by the starter.
camel-spring-boot, should be used if you want just to include a jar to make your camel routes auto-discovered by spring boot, this also gives you the freedom to update this dependency regardless of your spring-boot version.
camel-spring-boot-starter, (recommended way to go) should be used if you want a collection of dependencies (including camel-spring-boot) that provides the best developer/user experience, due to the fact of customizable properties, additional libraries, and default configuration for the camel library. Check the reference documentation for the starter: https://camel.apache.org/components/latest/spring-boot.html#_spring_boot_auto_configuration
Summary
Use camel-spring-boot, if you want a vanilla jar to use camel with spring boot
Use camel-spring-boot-starter, if you want an automatic-configured component to start to develop with.
You should always use the camel-xxx-starter dependencies, as these are the Camel components that is support with Spring Boot. Also as mentioned they provide auto configuration and some of them additional capabilities.
If there is no camel-xxx-starter component then its because its not supported on Spring Boot with Camel.
See more at: https://github.com/apache/camel/tree/master/platforms/spring-boot/components-starter#camel-component-starters

Is there a version of postmark java client library which uses jersey 1.x instead of 2.x?

I have a RESTful web service application in java deployed on google app-engine which uses jersey 1.18.6.
I want to use postmark java client to send transactional emails from it.
When I integrated it, i was seeing the following exception:
javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family
From what I could find, I think this error was because of there were two different (and probably incompatible) version of jersey being used ,1.18.6 for jersey-server, jersey-guice and jersey-bundle and 2.25.1 for jersey-client (by postmark).
Then I tried to make the jersey version 1.18,6 throughout, so in the my main project pom, while including the dependency for postmark, I excluded the jersey-client (by added exclusions header) and separately added jersey-client dependency in my main project .
But then I got the following error:
java.lang.NoClassDefFoundError: javax/ws/rs/core/MultivaluedHashMap
This is I think the class MultivaluedHashMap is present only in jax-rs 2.x versions (which is compatible with jersey 2.x versions)
So my questions are:
Is there a version of postmark java client library which uses jersey 1.x instead of jersey 2.x?
If no then what options do I have other than migrating my main project from jersey 1.x to jersey 2.x. I don't want to do that since we will have to migrate not just the jersey dependencies but I think some other things like guice, shiro etc. which would be time consuming. Also it doesn't really seem optimal to modify multiple existing dependencies just to include one additional module.
There isn't. The very first commit of the project's pom.xml already used Jersey 2.25.1
as Mureinik mentioned above, when we worked on the library, our plan at Postmark was to use newer library versions, since they are better options in long run.
On our Github page Rupert made good suggestions, from which I find separate ClassLoader a good choice. I will play a bit with the library code in next couple of days on compatibility, however we are always in favour of using newer libraries for our codebase.
please check out my latest comment on Github issues page for possible solution for using older Jersey version https://github.com/wildbit/postmark-java/issues/11
It should be pretty easy to port the library to Jersey 1.x by porting only the HttpClient class on your side.

RESTful web service

I am implementing a REST service from scratch. I am using Spring + ibatis for the same.
Now, spring offers REST support using annotations. However, online, I find many tutorials to integrate Jersey with Spring.
My question: Why would one want to introduce extra dependencies by including another framework, that is Jersey JAX-RS, when Spring itself is good?
You assume that there's a problem with introducing "another" dependency, which, unless you're developing for some tiny embedded system, there isn't. The added memory footprint, complexity etc would generally be irrelevant.
The decision to use Spring or Jersey for RESTv implementation should be one of personal preference and suitability. Pick the one that satisfies your requirements and you're most comfortable with.
Also, using Spring for REST will require additional dependencies itself. If you're only using Spring for dependency injection, you won't require spring-web or spring-webmvc, whereas these will be required for REST.
Hope this helps

How to use OSGI with CDI in jboss?

I'm experimenting with OSGI and CDI. I want to register my OSGI services using CDI annotations and also retrieve the registered OSGI services using CDI.
I have found the following: https://github.com/mathieuancelin/weld-osgi, it seems like it is integrated into weld-core. But when I depenend on the weld-core 1.2.0.Beta1 or 2.0.0.Final version, I do not find any of the annotations specified in the documentation on https://github.com/mathieuancelin/weld-osgi.
It this weld-osgi the way to go when you want to use OSGI with CDI? Or should I use spring? (I prefer weld because my AS is currently jboss EAP 6.1)
In which dependency can I find the annotations specified in the documentation?
Thanks!
Currently I do not advice using CDI to work with OSGi services. The Weld-OSGi library is still very experimental and will most likely change when the OSGi-CDI specification is released.
At this moment a new specification, OSGi-CDI (RFC 193) is being written in the Enterprise OSGi expert group (I'm one of the members writing this spec). OSGi-CDI is scheduled to be part of Enterprise OSGi R6 early next year. Unfortunately, it's too early to start using this yet, the reference implementation is far from finished. Some more details about the upcoming specification can be found in a presentation I gave at EclipseCon this year: https://speakerdeck.com/paulbakker/rfc-193-osgi-cdi
I strongly advice to use one of the other dependency injection solutions available for OSGi services, preferably either Apache Felix Dependency Manager or Dynamic Services. Because both of these libraries are built directly on the OSGi service API, you don't have to drag in other dependencies. The programming model is obviously different than CDI, but the concepts are very similar, so it should be easy to pick up.
Do not use Spring either because it doesn't really fit OSGi very well (although it can work).
I haven't worked on it, and I know little about weld-osgi, but you should be using it if you want OSGi and CDI to play nicely. I'm pretty sure they're separate jars, you'll need to add the weld-osgi dependency to your project.

How do I make JaxWsPortProxyFactoryBean use JAX-WS 2.1?

I'm working on a project that delivers web services using Jersey, which has a dependency on JAXB 2.1. I have to add a feature that fetches data from another web service. The way this has been implemented elsewhere uses a Spring JaxWsPortProxyFactoryBean.
When Spring tries to initialize this bean it fails with a : ClassCastException (com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext).
It appears that this is because JavaSE6 includes JAX-WS 2.0 API.
The only solution I have found suggests putting the 2.1 jars in the JRE endorsed directory. This isn't an option - I'm sharing a server with other application teams so I can't mess with the JRE.
Does anybody know of another way to make Spring use the 2.1 jars?

Resources