dev@grizzly.java.net

servlet-mapping didn't work well in GrizzlyWebServerDeployer

From: Bongjae Chang <carryel_at_korea.com>
Date: Thu, 27 Aug 2009 17:31:03 +0900

Hi,

I deployed an web application with using GrizzlyWebServerDeploy, I found that the Servlet is not served because of wrong path mapping.

Here is the example of web.xml
---
<web-app>
<servlet>
   <servlet-name>TestServlet</servlet-name>
   <servlet-class>my.test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>TestServlet</servlet-name>
   <url-pattern>/test/*</url-pattern>
</servlet-mapping>
...
</web-app>
---

Assuming that context path is "/example",

When I requested http://localhost:port/examples/test/abc, I expected that the TestServlet was serviced.

When I debugged, I found some strange codes.

In GrizzlyWebServerDeploy.java
---
public String[] getAlias(ServletAdapter sa, Collection<String> aliases) {
   ...
   for( String urlPattern : aliases) {
      String mapping = "";
      if (!sa.getServletPath().equals(urlPattern) && urlPattern.indexOf(sa.getServletPath()) > -1) {
         mapping = urlPattern.substring(urlPattern.indexOf(sa.getServletPath()));
      }
      String aliasTmp = sa.getContextPath() + sa.getServletPath() + mapping;
   }
   ...
}

When I deployed the web app, sa.getServletPath() is equal to "/test" and urlPattern is equal to "/test/*".

Then mapping result is equal to "/test/*" , so aliasTmp result is equal to "/example/test/test/*".

But I think that aliasTmp should become to be "/examples/test/*".

When I edited the mapping code like this experimentally,

---
mapping = urlPattern.subString(urlPattern.indexOf(sa.getServletPath()) + sa.getServletPath().length());
---

I could know that my test servlet is served well.

Could you please review this?


And I saw another strange code. This is trivial.

In GrizzlyWebServerDeployer.java
---
public String appendWarContentToClassPath(String appliPath) throw ... {
   ...
   if (appliPath != null && appliPath.endsWith(File.pathSeparator)) {
      appliPath = appliPath + File.pathSeparator;
   }
}
---
File.pathSeparator is equal to ";" in Windows.

Perhaps you mean File.separator "/" or "\". Is it right?

Then, the proposed patch is here.
---
public String appendWarContentToClassPath(String appliPath) throw ... {
   ...
   if (appliPath != null && !appliPath.endsWith(File.separator)) {
      appliPath = appliPath + File.separator;
   }
}
---

Is also Right? But, I am not sure. :)

Thanks!

--
Bongjae Chang