users@grizzly.java.net

Re: Quick question on servlet-mapping for Embedded Grizzly

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Thu, 14 May 2009 14:17:08 -0400

Salut,

aloleary wrote:
> The last problem i am having is related to the fact that i dont seem to be
> able to set a filter mapping when adding a filter programatically
>
> ServletAdapter restAdapter = new ServletAdapter();
> ....
> restAdapter.addFilter(delegatingFilterProxy, "springSecurityFilterChain",
> null);
> ...
>
> I need to replicate the following from the web.xml:
>
> <filter-mapping>
> <filter-name>springSecurityFilterChain</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
>
> ?

we aren't supporting filter mapping unfortunalty, e.g as soon as you add
a filter to a ServletAdapter, all request will be executed by this
filter. In should not be an issue with the above since it is *. If you
need the full support, please file an RFE and I will take a look as soon
as I can.

Thanks!

-- Jeanfrancois

>
>
> Jeanfrancois Arcand-2 wrote:
>> Salut,
>>
>> Survivant 00 wrote:
>>> I want to ask if the config is in a web.xml.
>>>
>>> because if it's there.. maybe Grizzly Deployer will be able to handle
>>> that.. if not, maybe we should have that.
>>>
>>> what do you think ?
>> Yes it will works. The issue we are having right is the GrizzlyWebServer
>> is not aware of the ServletAdapter. So it cannot automatically invoke
>> the setContextPath() automatically.
>>
>> A+
>>
>> -- Jeanfrancois
>>
>>> 2009/5/14 Jeanfrancois Arcand <Jeanfrancois.Arcand_at_sun.com
>>> <mailto:Jeanfrancois.Arcand_at_sun.com>>
>>>
>>>
>>> Salut,
>>> aloleary wrote:
>>>
>>> I am using ServletAdapter
>>>
>>> so
>>> adapter.setContextPath("/rest");
>>>
>>> was what I was missing - seems pretty obvious now
>>>
>>>
>>> yes this is a design issue we have right now. We need to fix that to
>>> make the user experience more trivial. I will file an RFE and see
>>> what we can do.
>>>
>>> Thanks!
>>>
>>> -- Jeanfrancois
>>>
>>>
>>>
>>> -A-
>>>
>>> for anyone else here is the full code thats allowing me also to
>>> boostrap
>>> spring+spring security:
>>> - test code so not very pretty right now
>>> // -----------------------------
>>> final URI baseUri =
>>> UriBuilder.fromUri("http://localhost/").port(PORT).build();
>>>
>>> final ServletAdapter adapter = new ServletAdapter();
>>>
>>> adapter.addInitParameter(
>>> "com.sun.jersey.config.property.packages",
>>> JERSEY_PACKAGE_ROOT);
>>>
>>> adapter.addContextParameter(
>>> "contextConfigLocation", SPRING_APP_CONTEXT);
>>>
>>> adapter.addServletListener(
>>>
>>> "org.springframework.web.context.ContextLoaderListener");
>>>
>>> SpringServlet springServlet = new SpringServlet();
>>>
>>> adapter.setServletInstance(springServlet);
>>> adapter.setContextPath("/rest");
>>>
>>> DelegatingFilterProxy delegatingFilterProxy = new
>>> DelegatingFilterProxy();
>>>
>>> delegatingFilterProxy.setTargetBeanName("filterChainProxy");
>>> // Add Spring Security
>>> adapter.addFilter(delegatingFilterProxy,
>>> "springSecurityFilterChain", null);
>>>
>>>
>>> adapter.addServletListener("org.springframework.security.ui.session.HttpSessionEventPublisher");
>>> threadSelector =
>>> GrizzlyServerFactory.create(baseUri, adapter);
>>>
>>> // -----------------------------
>>>
>>> Jeanfrancois Arcand-2 wrote:
>>>
>>> Salut,
>>>
>>> aloleary wrote:
>>>
>>> ...
>>>
>>> eh.. found it .. actually quite simple:
>>>
>>> adapter.setContextPath("/rest");
>>>
>>> which Adapter are you using? It might be in that adapter
>>> that the 404 is getting returned. Are you using the
>>> ServletAdapter?
>>>
>>> Thanks!!!1
>>>
>>> -- Jeanfrancois
>>>
>>>
>>> -A
>>>
>>>
>>> aloleary wrote:
>>>
>>> Sorry to be back again!
>>>
>>> so i refactored to the following code:
>>>
>>> ws = new GrizzlyWebServer(PORT);
>>> ws.addGrizzlyAdapter(adapter, new
>>> String[]{"/rest"});
>>> ws.start();
>>>
>>> However the server responds to the following url:
>>>
>>> GET http://localhost:9998/system/status OK
>>>
>>> But I want it to respond to this:
>>> GET http://localhost:9998/rest/system/status 404
>>>
>>> So I know the adapter is ok - it responds to all my
>>> calls - its just
>>> always on '/'
>>>
>>> The reason I need it this way is that /rest/* is
>>> configured with spring
>>> security/basic auth so its important for the
>>> embedded grizzly to reflect
>>> that.
>>> Any thoughts ?
>>>
>>> Thanks in advance
>>> -Al-
>>>
>>>
>>>
>>> Jeanfrancois Arcand-2 wrote:
>>>
>>> Salut,
>>>
>>> aloleary wrote:
>>>
>>> Its a good question - the answer is I don't
>>> based on the way I am
>>> configuring
>>> it above....
>>>
>>> After the lines above I do the following
>>> (apologies for not including
>>> before):
>>>
>>> // Add Spring Security
>>>
>>> adapter.addFilter(delegatingFilterProxy,
>>> "springSecurityFilterChain", null);
>>>
>>>
>>> adapter.addServletListener("org.springframework.security.ui.session.HttpSessionEventPublisher");
>>>
>>> threadSelector =
>>> GrizzlyServerFactory.create(baseUri,
>>> adapter);
>>>
>>> And now I have a running server...
>>>
>>> I guess I could refactor a bit to get usage
>>> of
>>>
>>> GrizzlyWebServer.addGrizzlyAdapter(adapter,"/rest");
>>>
>>> Yes I suspect this is the issue. But when you
>>> set the servletPath to /rest, it doesn't work?
>>> Are you getting 404 ?
>>>
>>> Thanks (and thanks for using Atmosphere :-))
>>>
>>> -- Jeanfrancois
>>>
>>>
>>> -A-
>>>
>>> Jeanfrancois Arcand-2 wrote:
>>>
>>> Salut,
>>>
>>> aloleary wrote:
>>>
>>> Hello,
>>> I have embeded Grizzly working
>>> great as part of my junit4.x test
>>> framework (@BeforeClass to boot
>>> strap for all tests and @AfterClass
>>> to
>>> tear
>>> down) I have configured it properly
>>> to bootstrap my spring context
>>> and
>>> spring-security.
>>>
>>> I have one small problem I cannot
>>> work out how to programatically
>>> configure the equivalent of the
>>> servlet mapping in web-xml fragment
>>> e.g.
>>>
>>> <!-- REST Support (Jersey/Spring)
>>> -->
>>> <servlet>
>>>
>>>
>>> <servlet-name>rest-servlet</servlet-name>
>>> <servlet-class>
>>>
>>>
>>> com.sun.jersey.spi.spring.container.servlet.SpringServlet
>>> </servlet-class>
>>>
>>> <load-on-startup>1</load-on-startup>
>>> </servlet>
>>>
>>> <servlet-mapping>
>>>
>>>
>>> <servlet-name>rest-servlet</servlet-name>
>>>
>>> <url-pattern>/rest/*</url-pattern>
>>> </servlet-mapping>
>>>
>>> Here is my embedded code:
>>>
>>> URI baseUri =
>>>
>>> UriBuilder.fromUri("http://localhost/").port(PORT).build();
>>> final ServletAdapter adapter
>>> = new ServletAdapter();
>>>
>>>
>>> adapter.addInitParameter("com.sun.jersey.config.property.packages",
>>> JERSEY_PACKAGE_ROOT);
>>>
>>>
>>>
>>> adapter.addContextParameter("contextConfigLocation",
>>> SPRING_APP_CONTEXT);
>>>
>>>
>>> adapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
>>>
>>> adapter.setServletInstance(new
>>> SpringServlet());
>>>
>>>
>>> adapter.setContextPath(baseUri.getPath());
>>> // so this is
>>> just
>>> '/'
>>> here
>>>
>>>
>>> //adapter.setServletPath("/rest");
>>> << this does not seem
>>> to
>>> work ?
>>>
>>> Any help really appreciated...
>>>
>>> How do you add the Adapter to the
>>> GrizzlyWebServer? Try something
>>> like:
>>>
>>>
>>> GrizzlyWebServer.addGrizzlyAdapter(adapter,"/rest");
>>>
>>> Let me know the result.
>>>
>>> Thanks!
>>>
>>> -- Jeanfrancois
>>>
>>>
>>> Thanks
>>> -A-
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_grizzly.dev.java.net
>>>
>>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>>> For additional commands, e-mail:
>>> users-help_at_grizzly.dev.java.net
>>> <mailto:users-help_at_grizzly.dev.java.net>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_grizzly.dev.java.net
>>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>>> For additional commands, e-mail:
>>> users-help_at_grizzly.dev.java.net
>>> <mailto:users-help_at_grizzly.dev.java.net>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> users-unsubscribe_at_grizzly.dev.java.net
>>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>>> For additional commands, e-mail:
>>> users-help_at_grizzly.dev.java.net
>>> <mailto:users-help_at_grizzly.dev.java.net>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>>> <mailto:users-unsubscribe_at_grizzly.dev.java.net>
>>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>> <mailto:users-help_at_grizzly.dev.java.net>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>>
>>
>