dev@grizzly.java.net

Re: Grizzly 2.2 ServletHandler changes

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Thu, 22 Dec 2011 13:17:20 -0800

I've pushed a new 2.2.1 snapshot to the java.net maven repo. Would you
mind verifying the results on your end?

Thank you for the feedback!


On 12/22/11 2:20 AM, Oleksiy Stashok wrote:
> On 12/22/2011 11:14 AM, Andreas Kohn wrote:
>> On Thu, 2011-12-22 at 10:35 +0100, Oleksiy Stashok wrote:
>>> On 12/21/2011 09:32 PM, Ryan Lubke wrote:
>>>> On 12/21/11 11:47 AM, Andreas Kohn wrote:
>>>>>
>>>>> [ migrating from ServletHandler in 2.1.7 to 2.2 ]
>>>>>
>>>> With the API changes, there should be no reason to directly create the
>>>> ServletHandler yourself.
>>>>
>>>> The proper way to register a servlet now would be:
>>>>
>>>> WebappContext ctx = new WebappContext("Test", "/contextPath");
>>>>
>>>> Then call ctx.addServlet(String, Servlet);
>>>>
>>>> final ServletRegistration reg = ctx.addServlet(name, new
>>>> HttpServlet() {
>>>>
>>>> @Override
>>>> protected void doGet(
>>>> HttpServletRequest req, HttpServletResponse resp)
>>>> throws IOException {
>>>> LOGGER.log(Level.INFO, "{0} received request {1}",
>>>> new
>>>> Object[]{alias, req.getRequestURI()});
>>>> resp.setStatus(HttpServletResponse.SC_OK);
>>>> resp.setHeader("Content-Type", header);
>>>> resp.setHeader("Path-Info", req.getPathInfo());
>>>> resp.setHeader("Request-Was", req.getRequestURI());
>>>> resp.setHeader("Servlet-Name", getServletName());
>>>> resp.getWriter().write(alias);
>>>> }
>>>> });
>>>>
>>>> Then add the path mapping:
>>>>
>>>> reg.addMapping(alias);
>>>>
>>>> Register the WebappContext with the HttpServer:
>>>>
>>>> ctx.deploy(httpServerInstance);
>>>> httpServer.start();
>>>>
>>>> You should then be able to access the servlet.
>>> Just wanted to add that our motivation was making API similar to how
>>> Servlets are defined within webapplication.
>>> 1) It became easier to define several servlets, which share the same
>>> ServletContext (like webapplication)
>>> 2) Now Filters are getting associated with ServletContext
>>> (webapplication), not specific ServletHandler.
>>>
>>> Please let us know if we've missed some usecase.
>> Hi,
>>
>> thanks, the new API actually looks nicer!
>>
>> Unfortunately I'm hitting road blocks still.
>>
>> WebappContext sets the context path to '/', and does not allow an
>> empty string. This breaks the ServletContext#getContextPath() spec,
>> which says:
>>
>> The context path is the portion of the request URI that is used
>> to select the context of the request. The context path always
>> comes
>> first in a request URI. The path starts with a "/" character but
>> does not end with a "/" character. For servlets in the default
>> (root) context, this method returns "".
>>
>> (servlet-api 2.5 javadoc)
>>
>> I'm trying to map my servlet to the root, and neither addMapping("/")
>> nor addMapping("") help in work properly:
>>
>> addMapping("/") produces a handler at '//', which seems to actually work
>> if one explicitly uses the // in the URL (http://host:port//). 500
>> Internal Error is returned for http://host:port and http://host:port/,
>> I'm not yet sure where from.
>>
>> addMapping("") produces:
>>
>> java.lang.StringIndexOutOfBoundsException: String index out of
>> range: 0
>> at java.lang.String.charAt(String.java:695)
>> at
>> org.glassfish.grizzly.servlet.WebappContext.updateMappings(WebappContext.java:1575)
>> at
>> org.glassfish.grizzly.servlet.WebappContext.initServlets(WebappContext.java:1490)
>> at
>> org.glassfish.grizzly.servlet.WebappContext.deploy(WebappContext.java:247)
>>
>>
>> Is this problem known?
> No, please file an issue and we'll fix it and do an update release asap.
>
> WBR,
> Alexey.
>
>>
>> Regards,
>> --
>> Andreas
>>
>