users@jersey.java.net

Re: [Jersey] Right way to create embedded grizzly with already instantiated Application?

From: American Jeff Bowden <jlb_at_houseofdistraction.com>
Date: Fri, 07 Nov 2008 12:34:26 -0800

Paul Sandoz wrote:
>
> On Nov 7, 2008, at 6:52 PM, American Jeff wrote:
>
>> After a lot of poking around I've come up with this function to create
>> an embedded Grizzly instance from an already instantiated Application
>> object:
>>
>> protected SelectorThread createGrizzly(URI u, Application app)
>> throws IllegalArgumentException, IOException {
>>
>> return GrizzlyServerFactory.create(u,
>> RuntimeDelegate.getInstance().createEndpoint(app, Adapter.class));
>>
>> }
>>
>>
>> I'm wondering if this is really the right way.
>
> Yes. But how about i add methods to GrizzlyServerFactory to do this:
>
> GrizzlyServerFactory.create(String uri, ResourceConfig rc);
>
> GrizzlyServerFactory.create(URI, u, ResourceConfig rc);
>
> (and add the same for the LW HTTP server) in 1.0.1 ?

Turns out I was barking up the wrong tree anyway. What I wanted was to
control the call to WebApplication.initiate so I could pass in a
ComponentProvider but I confused WebApplication with Application
somewhere along the way. Now that I'm unconfused I've got this:

    protected SelectorThread createGrizzly(URI u, ResourceConfig rc, ComponentProvider cp) throws IOException {

        WebApplication wa = WebApplicationFactory.createWebApplication();

        wa.initiate(new ApplicationAdapter(rc), cp);

        return GrizzlyServerFactory.create(u, new GrizzlyContainer(wa));

    }

So perhaps you could add

    GrizzlyServerFactory.create(URI u, ResourceConfig rc,
ComponentProvider cp);