users@jersey.java.net

[Jersey] Re: Multiple Resource Configurations

From: Mikael Ståldal <mikael.staldal_at_appearnetworks.com>
Date: Mon, 17 Nov 2014 10:41:15 +0100

I don't know about Grizzly, but I did something similar for Jetty. This is
for serving static resources in parallel to the Jersey app.

It would be nice if JettyHttpContainerFactory had some shortcut method for
this.

    private static void startServer(int port, ResourceConfig application)
throws Exception {
        JettyHttpContainer container =
ContainerFactory.createContaier(JettyHttpContainer.class,
application);
        URI baseUri = UriBuilder.fromUri("http://localhost/
").port(port).build();
        Server server = JettyHttpContainerFactory.createServer(baseUri,
null, null, false);

        ResourceHandler resourceHandler = new ResourceHandler();

resourceHandler.setBaseResource(Resource.newClassPathResource("webapp"));

        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{resourceHandler, container});
        server.setHandler(handlers);

        server.start();
    }


On Fri, Nov 14, 2014 at 6:42 PM, Robert DiFalco <robert.difalco_at_gmail.com>
wrote:

> I'm using Grizzly with Jersey via GrizzlyHttpServerFactory. I was
> wondering if it was possible to have N paths that map to N ResourceConfig
> instances?
>
> There are a lot of debates about the right way to version APIs and I'd
> rather not go down that rabbit hole.
>
> But lets assume that I want a "rest/v1.0" path that maps to a
> ResourceConfigV1 and a "rest/v2.0" path that maps to a ResourceConfigV2.
>
> What is the simplest way to do that in Jersey with Grizzly?
>
> Thanks in advance!
>
> R.
>



-- 
Mikael Ståldal
Chief Software Architect
*Appear*
Phone: +46 8 545 91 572
Email: mikael.staldal_at_appearnetworks.com