dev@grizzly.java.net

Re: servlet-mapping didn't work well in GrizzlyWebServerDeployer

From: Bongjae Chang <carryel_at_korea.com>
Date: Mon, 31 Aug 2009 22:37:21 +0900

I attached the test web app(simple_war.war).

The simple_war.war includes web.xml, SimpleServlet.java and SimpleServlet.class.

web.xml is here.
---
<web-app>
   <servlet>
      <servlet-name>SimpleServlet</servlet-name>
      <servlet-class>SimpleServlet</servlet-class>
      ...
   </servlet>
   <servlet-mapping>
      <servlet-name>SimpleServlet</servlet-name>
      <url-pattern>/simple_servlet/*</url-pattern>
   </servlet-mapping>
</web-app>
---

I ran the application with JDK6 on Windows like this:

---
java -jar grizzly-http-servlet-deployer.jar --application=c:\simple_war.war --port=8080

or

java -cp grizzly-http-servlet-deployer.jar com.sun.grizzly.http.servlet.deployer.GrizzlyWebServerDeployer --application=c:\simple_war.war --port=8080
---

And I requested "http://localhost:8080/simple_war/simple_servlet" or "http://localhost:8080/simple_war/simple_servlet/abc" with IE6.

I think that the browser should print "Hello, SimpleServlet!".

And I think that you can reproduce it easily with the attached .war.

Thanks!

--
Bongjae Chang


  ----- Original Message -----
  From: Survivant 00
  To: dev_at_grizzly.dev.java.net
  Sent: Monday, August 31, 2009 10:27 PM
  Subject: Re: servlet-mapping didn't work well in GrizzlyWebServerDeployer


  thanks.


  2009/8/31 Bongjae Chang <carryel_at_korea.com>

    Hi Sebastien,
    Â
    Okay! I will try to make a simple .war for reproducing this issue in a few hours and will attach it.
    Â
    Thanks!
    --
    Bongjae Chang
    Â
    Â
      ----- Original Message -----
      From: Survivant 00
      To: dev_at_grizzly.dev.java.net
      Sent: Monday, August 31, 2009 9:41 PM
      Subject: Re: servlet-mapping didn't work well in GrizzlyWebServerDeployer


      will try that on debug tonight.


      the mapping doesn't look special.Ã, I thinkÃ, grizzly-twitter have the same things.. /words/Ã, Ã, something like that.

      I'll check.


      can you package a .war that I can test.Ã, Will be easier to test.. with the command line you use please.




      2009/8/31 Bongjae Chang <carryel_at_korea.com>

        Hi Sebastien,
        Ã,Â
        Thank you for your reply.
        Ã,Â
        I think that maybeÃ, your last reply is concerned about the following.
        Ã,Â
        ---
        Ã, Ã, if (appliPath != null && appliPath.endsWith(File.pathSeparator)) {
        Ã, Ã, Ã, Ã, Ã, appliPath = appliPath + File.pathSeparator;
        Ã, Ã, }
        ---
        I see...
        Ã,Â
        But, I think thatÃ, definately, the following code is not correct.
        Ã,Â
        ---
        mapping = urlPattern.substring(urlPattern.indexOf(sa.getServletPath()));
        ---
        Ã,Â
        After you will review it, please let me know. :)
        Ã,Â
        Thanks!
        Ã,Â
        --
        Bongjae Chang
        Ã,Â
        Ã,Â
          ----- Original Message -----
          From: Survivant 00
          To: dev_at_grizzly.dev.java.net
          Sent: Thursday, August 27, 2009 6:59 PM
          Subject: Re: servlet-mapping didn't work well in GrizzlyWebServerDeployer


          it's to early in the morning to think about it.. will come back to you later.

          but here what's in the help


-a, --application=[path]* Application(s) path(s). Application(s) deployed can be :
                              Servlet(s), war(s) and expanded war folder(s). To deploy multiple applications use File.pathSeparator Example : -a /app.war:/servlet/web.xml:/warfolder/






          2009/8/27 Bongjae Chang <carryel_at_korea.com>

            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