Problems with Spring, Jetty and SimpleUrlHandlerMapping

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with Spring, Jetty and SimpleUrlHandlerMapping

Ståle Undheim
After all the fuss I have heard about Spring, I decided I wanted to
check it out for myself.

My basic setup for running webapps is eclipse, using the jetty
launcher to start jetty applications (Basically, it just generates a
big command line that it uses to start jetty, including the classpath
from eclipse, and setting the webapp folder to where I choose).

I started out with the example at
http://static.springframework.org/spring/articles/2005/MVC-step-by-step/Spring-MVC-step-by-step-Part-1.html
but I haven't made it past the first page yet.

Basically I have to go to the URL
http://localhost:8080/springapp/hello.htm - which will use the
argument "hello.htm" to map to my class.

Now, by now you might think that this belongs in the Spring framework
mailling list. The reason I post here is that when I examined the
code, I saw how Spring extracts the "hello.htm" part from the request
URI. Condensed, the code is something like this:

Note: this is a root webapp, springapp is the servlet.

String contextPath = request.getContextPath() # ""
String requestURI = request.getRequestURI() # "/springapp/hello.htm"

String pathWithinApp = requestUri.substring(contextPath.length()) #
"/springapp/hello.htm"
String servletPath = request.getServletPath() # "/springapp/hello.htm"

return pathWithinApp.substring(servletPath.length()) # ""

So, the result of pathWithinApp and servletPath is the same, while I
suspect Spring expects servletPath to only contain the servlet part
("/springapp") of the URI. I was unsure wether this was Spring using
the servlet API wrong or Jetty implementing it wrong. But the JavaDoc
on the Servlet API says:
---
Returns the part of this request's URL that calls the servlet. This
includes either the servlet name or a path to the servlet, but does
not include any extra path information or a query string. Same as the
value of the CGI variable SCRIPT_NAME


-------------------------------------------------------
SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
online with coworkers and clients while avoiding the high cost of travel and
communications. There is no equipment to buy and you can meet as often as
you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Problems with Spring, Jetty and SimpleUrlHandlerMapping

jan_bartel
Hi Ståle,

If you check the Jetty dump demo at:

http://jetty.mortbay.org/demo/dump/info?A=1&A=2&A=3&B=5&C=6

You will see that Jetty returns the correct servlet path.

Perhaps the Spring tutorial is incorrect? I don't know anything about
the Spring mvc stuff, so perhaps this won't help, but I notice that the
property mapping in the tutorial is different from the reference manual.
The tutorial uses:

   <prop key="/hello.htm">springappController</prop>

whereas the reference manual uses a pattern match:

   <prop key="/ex/view*.html">someViewController</prop>
   <prop key="/**/help.html">helpController</prop>

cheers
Jan


Ståle Undheim wrote:

> After all the fuss I have heard about Spring, I decided I wanted to
> check it out for myself.
>
> My basic setup for running webapps is eclipse, using the jetty
> launcher to start jetty applications (Basically, it just generates a
> big command line that it uses to start jetty, including the classpath
> from eclipse, and setting the webapp folder to where I choose).
>
> I started out with the example at
> http://static.springframework.org/spring/articles/2005/MVC-step-by-step/Spring-MVC-step-by-step-Part-1.html
> but I haven't made it past the first page yet.
>
> Basically I have to go to the URL
> http://localhost:8080/springapp/hello.htm - which will use the
> argument "hello.htm" to map to my class.
>
> Now, by now you might think that this belongs in the Spring framework
> mailling list. The reason I post here is that when I examined the
> code, I saw how Spring extracts the "hello.htm" part from the request
> URI. Condensed, the code is something like this:
>
> Note: this is a root webapp, springapp is the servlet.
>
> String contextPath = request.getContextPath() # ""
> String requestURI = request.getRequestURI() # "/springapp/hello.htm"
>
> String pathWithinApp = requestUri.substring(contextPath.length()) #
> "/springapp/hello.htm"
> String servletPath = request.getServletPath() # "/springapp/hello.htm"
>
> return pathWithinApp.substring(servletPath.length()) # ""
>
> So, the result of pathWithinApp and servletPath is the same, while I
> suspect Spring expects servletPath to only contain the servlet part
> ("/springapp") of the URI. I was unsure wether this was Spring using
> the servlet API wrong or Jetty implementing it wrong. But the JavaDoc
> on the Servlet API says:
> ---
> Returns the part of this request's URL that calls the servlet. This
> includes either the servlet name or a path to the servlet, but does
> not include any extra path information or a query string. Same as the
> value of the CGI variable SCRIPT_NAME
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
> online with coworkers and clients while avoiding the high cost of travel and
> communications. There is no equipment to buy and you can meet as often as
> you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
online with coworkers and clients while avoiding the high cost of travel and
communications. There is no equipment to buy and you can meet as often as
you want. Try it free.http://ads.osdn.com/?ad_id=7402&alloc_id=16135&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Re: Problems with Spring, Jetty and SimpleUrlHandlerMapping

Ståle Undheim
On 5/26/05, Jan Bartel <[hidden email]> wrote:
> Hi Ståle,
>
> If you check the Jetty dump demo at:
>
> http://jetty.mortbay.org/demo/dump/info?A=1&A=2&A=3&B=5&C=6
>
> You will see that Jetty returns the correct servlet path.
>

I will have to look a bit more into it later today. I Just attached
the Spring source to my project, and ran in debug mode. From there I
could see what the return of each method call was, and the URI and
Servlet Paths where the same there. Maybe I am doing something
completly trivial in the wrong way.

Now that I think about it, it might be something in my web.xmls
mapping that is off. Will this matching cause it to think the entire
URL is the servlet?
  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

Maybe changing it to this will help:
<url-pattern>springapp/*</url-pattern>

> Perhaps the Spring tutorial is incorrect? I don't know anything about
> the Spring mvc stuff, so perhaps this won't help, but I notice that the
> property mapping in the tutorial is different from the reference manual.
> The tutorial uses:
>
>    <prop key="/hello.htm">springappController</prop>
>
> whereas the reference manual uses a pattern match:
>
>    <prop key="/ex/view*.html">someViewController</prop>
>    <prop key="/**/help.html">helpController</prop>

Well, you can use a pattern to match more views, or just use an
absolute match, which is what I have done.

> Ståle Undheim wrote:
> > After all the fuss I have heard about Spring, I decided I wanted to
> > check it out for myself.
> >
> > My basic setup for running webapps is eclipse, using the jetty
> > launcher to start jetty applications (Basically, it just generates a
> > big command line that it uses to start jetty, including the classpath
> > from eclipse, and setting the webapp folder to where I choose).
> >
> > I started out with the example at
> > http://static.springframework.org/spring/articles/2005/MVC-step-by-step/Spring-MVC-step-by-step-Part-1.html
> > but I haven't made it past the first page yet.
> >
> > Basically I have to go to the URL
> > http://localhost:8080/springapp/hello.htm - which will use the
> > argument "hello.htm" to map to my class.
> >
> > Now, by now you might think that this belongs in the Spring framework
> > mailling list. The reason I post here is that when I examined the
> > code, I saw how Spring extracts the "hello.htm" part from the request
> > URI. Condensed, the code is something like this:
> >
> > Note: this is a root webapp, springapp is the servlet.
> >
> > String contextPath = request.getContextPath() # ""
> > String requestURI = request.getRequestURI() # "/springapp/hello.htm"
> >
> > String pathWithinApp = requestUri.substring(contextPath.length()) #
> > "/springapp/hello.htm"
> > String servletPath = request.getServletPath() # "/springapp/hello.htm"
> >
> > return pathWithinApp.substring(servletPath.length()) # ""
> >
> > So, the result of pathWithinApp and servletPath is the same, while I
> > suspect Spring expects servletPath to only contain the servlet part
> > ("/springapp") of the URI. I was unsure wether this was Spring using
> > the servlet API wrong or Jetty implementing it wrong. But the JavaDoc
> > on the Servlet API says:
> > ---
> > Returns the part of this request's URL that calls the servlet. This
> > includes either the servlet name or a path to the servlet, but does
> > not include any extra path information or a query string. Same as the
> > value of the CGI variable SCRIPT_NAME
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
> > online with coworkers and clients while avoiding the high cost of travel and
> > communications. There is no equipment to buy and you can meet as often as
> > you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
> > _______________________________________________
> > Jetty-support mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/jetty-support
> >
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
> online with coworkers and clients while avoiding the high cost of travel and
> communications. There is no equipment to buy and you can meet as often as
> you want. Try it free.http://ads.osdn.com/?ad_id=7402&alloc_id=16135&op=click
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>


-------------------------------------------------------
SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
online with coworkers and clients while avoiding the high cost of travel and
communications. There is no equipment to buy and you can meet as often as
you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Problems with Spring, Jetty and SimpleUrlHandlerMapping

Greg Wilkins-5

There is a big difference between *.foo and foo/* mappings in the
results you will get from pathInfo and servletPath, so I expect this
is the problem.

cheers


Ståle Undheim wrote:

> On 5/26/05, Jan Bartel <[hidden email]> wrote:
>
>>Hi Ståle,
>>
>>If you check the Jetty dump demo at:
>>
>>http://jetty.mortbay.org/demo/dump/info?A=1&A=2&A=3&B=5&C=6
>>
>>You will see that Jetty returns the correct servlet path.
>>
>
>
> I will have to look a bit more into it later today. I Just attached
> the Spring source to my project, and ran in debug mode. From there I
> could see what the return of each method call was, and the URI and
> Servlet Paths where the same there. Maybe I am doing something
> completly trivial in the wrong way.
>
> Now that I think about it, it might be something in my web.xmls
> mapping that is off. Will this matching cause it to think the entire
> URL is the servlet?
>   <servlet-mapping>
>     <servlet-name>springapp</servlet-name>
>     <url-pattern>*.htm</url-pattern>
>   </servlet-mapping>
>
> Maybe changing it to this will help:
> <url-pattern>springapp/*</url-pattern>
>
>>Perhaps the Spring tutorial is incorrect? I don't know anything about
>>the Spring mvc stuff, so perhaps this won't help, but I notice that the
>>property mapping in the tutorial is different from the reference manual.
>>The tutorial uses:
>>
>>   <prop key="/hello.htm">springappController</prop>
>>
>>whereas the reference manual uses a pattern match:
>>
>>   <prop key="/ex/view*.html">someViewController</prop>
>>   <prop key="/**/help.html">helpController</prop>
>
>
> Well, you can use a pattern to match more views, or just use an
> absolute match, which is what I have done.
>
>
>>Ståle Undheim wrote:
>>
>>>After all the fuss I have heard about Spring, I decided I wanted to
>>>check it out for myself.
>>>
>>>My basic setup for running webapps is eclipse, using the jetty
>>>launcher to start jetty applications (Basically, it just generates a
>>>big command line that it uses to start jetty, including the classpath
>>>from eclipse, and setting the webapp folder to where I choose).
>>>
>>>I started out with the example at
>>>http://static.springframework.org/spring/articles/2005/MVC-step-by-step/Spring-MVC-step-by-step-Part-1.html
>>>but I haven't made it past the first page yet.
>>>
>>>Basically I have to go to the URL
>>>http://localhost:8080/springapp/hello.htm - which will use the
>>>argument "hello.htm" to map to my class.
>>>
>>>Now, by now you might think that this belongs in the Spring framework
>>>mailling list. The reason I post here is that when I examined the
>>>code, I saw how Spring extracts the "hello.htm" part from the request
>>>URI. Condensed, the code is something like this:
>>>
>>>Note: this is a root webapp, springapp is the servlet.
>>>
>>>String contextPath = request.getContextPath() # ""
>>>String requestURI = request.getRequestURI() # "/springapp/hello.htm"
>>>
>>>String pathWithinApp = requestUri.substring(contextPath.length()) #
>>>"/springapp/hello.htm"
>>>String servletPath = request.getServletPath() # "/springapp/hello.htm"
>>>
>>>return pathWithinApp.substring(servletPath.length()) # ""
>>>
>>>So, the result of pathWithinApp and servletPath is the same, while I
>>>suspect Spring expects servletPath to only contain the servlet part
>>>("/springapp") of the URI. I was unsure wether this was Spring using
>>>the servlet API wrong or Jetty implementing it wrong. But the JavaDoc
>>>on the Servlet API says:
>>>---
>>>Returns the part of this request's URL that calls the servlet. This
>>>includes either the servlet name or a path to the servlet, but does
>>>not include any extra path information or a query string. Same as the
>>>value of the CGI variable SCRIPT_NAME
>>>
>>>
>>>-------------------------------------------------------
>>>SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
>>>online with coworkers and clients while avoiding the high cost of travel and
>>>communications. There is no equipment to buy and you can meet as often as
>>>you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
>>>_______________________________________________
>>>Jetty-support mailing list
>>>[hidden email]
>>>https://lists.sourceforge.net/lists/listinfo/jetty-support
>>>
>>
>>
>>
>>-------------------------------------------------------
>>SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
>>online with coworkers and clients while avoiding the high cost of travel and
>>communications. There is no equipment to buy and you can meet as often as
>>you want. Try it free.http://ads.osdn.com/?ad_id=7402&alloc_id=16135&op=click
>>_______________________________________________
>>Jetty-support mailing list
>>[hidden email]
>>https://lists.sourceforge.net/lists/listinfo/jetty-support
>>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: GoToMeeting - the easiest way to collaborate
> online with coworkers and clients while avoiding the high cost of travel and
> communications. There is no equipment to buy and you can meet as often as
> you want. Try it free.<a href="http://ads.osdn.com/?ad_idt02&alloc_id135&op=click">http://ads.osdn.com/?ad_idt02&alloc_id135&op=click
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support