You are applying servlet concepts to the ResourceHandler, which is based on
the Jetty internal Handler concepts, which are not a strict participant in
the servlet infrastructure.  They are more fundamental.  In fact, the
entire servlet layer is built on-top of the Handler layer in Jetty.

The ResourceHandler needs a pathInfo to know what resource you are
requesting from the resourceBase.
If you want to use the ResourceHandler, don't use the WebAppContext, use
the ContextHandler instead.  Different behavior.

If you want to serve static content and servlets, here's 2 choices.

1) use the DefaultServlet in your webapp (war).  It is built-into the
servlet support of jetty.
See ${jetty.home}/etc/webdefault.xml to see its default configuration.
Note: the DefaultServlet itself uses the Resource framework to serve static
content.

2) split the Jetty handling of your static content from the webapp handling
your dynamic content.
This can be accomplished with 2 deployable apps.  1 using the
ContextHandler for static content, and the other using WebAppContext for
your webapp.

--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Fri, Jan 25, 2013 at 1:47 PM, Libor Jelinek <[email protected]> wrote:

> Hi Joakim!
> I agree that more proper is just ContextHandler if I plan to serve just
> static files but how this could be invalid to use WebAppContext if
> WebAppContext is indirect child of ContextHandler?
>
> You mention that this NPE is caused by not having set pathInfo correctly
> but it's absolutelly valid to have null pathInfo() [1]. Root context path
> (/) couldn't have pathInfo (/somePathInfo) by nature since otherwise it may
> collides with another servlet (with servlet deployed at somePathInfo
> context path to continue my example).
>
> [1]
> http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getPathInfo()
>
> By the way I think that well-written app should never thrown NPE to the
> end-user (or end-developer). If code doesn't except null it should check
> for it before and throw high level exception explaining what's wrong.
>
> Do you think it will be helpful to file a enhancement bug for this (to
> produce more human error in this case)?
>
> --
> Hezky den / Have a nice day
> Libor JELÍNEK
>
> VIRTAGE SOFTWARE // software - design - web
> Lucni 542 // 285 04 Uhlirske Janovice // Czech Republic
> support: +420 315 555 488 // cell: +420 777 205 142
> email/jabber: [email protected] // web: www.virtage.com
>
> Visit our developer adventures at http://devblog.virtage.com!
>
>
> On Fri, Jan 25, 2013 at 5:57 PM, Joakim Erdfelt <[email protected]>wrote:
>
>> That NPE is on ...
>>
>>
>> http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java?id=jetty-8.1.8.v20121106#n403
>>
>> So that means your the pathInfo is not set right.
>> Looking at your configuration, you have it defined as a full blown
>> WebAppContext, when you are only using low level handler stuff.
>>
>> Try this for the top level XML element instead ...
>>
>> <Configure class="org.eclipse.jetty.server.handler.ContextHandler">
>>
>> per the example in our distribution ...
>>
>>
>> http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-distribution/src/main/resources/contexts/javadoc.xml?id=jetty-8.1.8.v20121106
>>
>> --
>> Joakim Erdfelt <[email protected]>
>> webtide.com <http://www.webtide.com/>
>> Developer advice, services and support
>> from the Jetty & CometD experts
>> eclipse.org/jetty - cometd.org
>>
>>
>> On Fri, Jan 25, 2013 at 2:33 AM, Libor Jelinek <[email protected]>wrote:
>>
>>> Hello all!
>>> In very simple (maybe simplest as its just ResourceHandler) scenario to
>>> serve static plain HTML files I'm facing NPE with jetty-8.1.8.v20121106.
>>>
>>> Very basic $JETTY_HOME/my-context.xml:
>>>
>>> <?xml version="1.0"  encoding="ISO-8859-1"?>
>>> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "
>>> http://www.eclipse.org/jetty/configure.dtd";>
>>>
>>> <Configure class="org.eclipse.jetty.webapp.WebAppContext">
>>> <Set name="contextPath">/my-context</Set>
>>>  <Set name="resourceBase">/home/libor/Ubuntu
>>> One/SYSA/nice-error-pages/</Set>
>>>
>>>  <Set name="handler">
>>> <New class="org.eclipse.jetty.server.handler.ResourceHandler">
>>>   <Set name="welcomeFiles">
>>> <Array type="String">
>>>   <Item>index.html</Item>
>>> </Array>
>>>   </Set>
>>>   <Set name="cacheControl">max-age=3600,public</Set>
>>>  </New>
>>> </Set>
>>> </Configure>
>>>
>>> Produces HTTP 500 Internal Server error with the following details from
>>> log file:
>>>
>>> 2013-01-25 10:05:03.811:WARN:oejs.AbstractHttpConnection:/nice404/
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.jetty.server.handler.ResourceHandler.handle(ResourceHandler.java:403)
>>>  at
>>> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>>> at
>>> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
>>>  at
>>> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
>>> at
>>> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
>>>  at
>>> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>>> at
>>> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>>>
>>> NPE is caused by something in <Set name="handler"> block because
>>> removing or commenting it out prevents crash.
>>>
>>> What's wrong? Thanks for any suggestions.
>>>
>>> --
>>> Hezky den / Have a nice day
>>> Libor JELÍNEK
>>>
>>> VIRTAGE SOFTWARE // software - design - web
>>> Lucni 542 // 285 04 Uhlirske Janovice // Czech Republic
>>> support: +420 315 555 488 // cell: +420 777 205 142
>>> email/jabber: [email protected] // web: www.virtage.com
>>>
>>> Visit our developer adventures at http://devblog.virtage.com!
>>>
>>> _______________________________________________
>>> jetty-users mailing list
>>> [email protected]
>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>
>>>
>>
>> _______________________________________________
>> jetty-users mailing list
>> [email protected]
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to