users@jersey.java.net

Re: switch providers based on URL

From: Jason Erickson <jason_at_jasonerickson.com>
Date: Tue, 30 Nov 2010 12:40:38 -0800

I was thinking you could create more than one Spring servlet with different configurations for com.sun.jersey.config.property.packages and different servlet mappings. You may be able to achieve what you want by putting legacy stuff in it's own packages. So, if your domain objects were in com.foo.domain and your legacy providers are in com.foo.providers.v1 and your lovely new providers are in com.foo.providers.v2, then you could set up your web.xml something like this:

        <servlet>
                <servlet-name>jersey-spring-v1</servlet-name>
                <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
                <init-param>
                        <param-name>com.sun.jersey.config.property.packages</param-name>
                        <param-value>com.foo.domain;com.foo.providers.v1</param-value>
                </init-param>
        </servlet>
        <servlet>
                <servlet-name>jersey-spring-v2</servlet-name>
                <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
                <init-param>
                        <param-name>com.sun.jersey.config.property.packages</param-name>
                        <param-value>com.foo.domain;com.foo.providers.v2</param-value>
                </init-param>
        </servlet>
        <servlet-mapping>
                <servlet-name>jersey-spring-v2</servlet-name>
                <url-pattern>/v2</url-pattern>
        </servlet-mapping>

I don't know if that would work the way I expect it too, because I'm pretty new to Jersey and just spent a few days trying untangle my own path problems, but it seems to me that that should do what you need.

On Nov 30, 2010, at 11:39 AM, Ronak Patel wrote:

> Only other thing I can think of is playing games with Spring and dynamically loading the @Provider bean per request instead of as a Singleton...
>
> Would that work?
>
> From: Ronak Patel <ronak2121_at_yahoo.com>
> To: users_at_jersey.java.net
> Sent: Tue, November 30, 2010 11:37:14 AM
> Subject: Re: switch providers based on URL
>
> So that means we can't do that?...
>
> This will force me to create two different copies of my war files then....one legacy one that uses the mapped style when I didn't know any better....
>
> and
>
> a new war file that uses the better natural style JSON.....
>
> That's what I was afraid of....
>
> From: Reto Bachmann-Gmür <reto_at_gmuer.ch>
> To: users_at_jersey.java.net
> Sent: Tue, November 30, 2010 7:36:43 AM
> Subject: Re: switch providers based on URL
>
> I think it would be a good extension to the jax-rs spec to restrict ceratin provider to a URI-space.
>
> Cheers,
> Reto
>
> On Tue, Nov 30, 2010 at 4:26 PM, Ronak Patel <ronak2121_at_yahoo.com> wrote:
> Hi All,
>
> Does anyone know if we can switch which @Provider JAX-RS Jersey uses based on a URI?
>
> I have certain endpoints I want wrapped style JSON (for backward compatibility) and certain endpoints I want natural style JSON (for everything going forward).
>
> Thanks,
>
> Ronak Patel
>
>
>
>
>