RequestDispatcherAdaptor NullPointerException [message #79507] |
Tue, 19 December 2006 14:06 |
Eclipse User |
|
|
|
Originally posted by: ridcully560.yahoo.com
Hi,
I ran into a problem with the RequestDispatcherAdaptor. In the webapp
I'm trying to set up for running as a bundle in Equinox, I got a
DispatcherServlet that forwards the request to other Servlets:
> getServletContext().getNamedDispatcher(
> AppointmentServlet.class.getSimpleName()).forward(request, response);
This works fine in the old version running with tomcat, but when I try
it with Equinox, I allways get the following exception:
> java.lang.NullPointerException
> at org.eclipse.equinox.http.servlet.internal.RequestDispatcherA daptor.forward(RequestDispatcherAdaptor.java:19)
Which points to here, where requestDispatcher is null:
> public void forward(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
> if (req instanceof HttpServletRequestAdaptor)
> req = ((HttpServletRequestAdaptor) req).getRequest();
>
> requestDispatcher.forward(req, resp);
> }
In an - not answered - older post I found a hint that it might be
because of different context of the servlets. After that, I also
registered the other servlet:
> ServiceReference sr = bc.getServiceReference(HttpService.class.getName());
> if(sr != null) {
> HttpService http = (HttpService)context.getService(sr);
> if(http != null) {
> http.registerServlet("/path/MainServlet", new MainServlet(), null, null);
> http.registerServlet("/path/ForwardToServlet", new ForwardToServlet(), null, null);
> }
> }
But the exception still is thrown.
Maybe someone got a hint about that,
Johannes
|
|
|
Re: RequestDispatcherAdaptor NullPointerException [message #79524 is a reply to message #79507] |
Tue, 19 December 2006 16:00 |
Simon Kaegi Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Hi Johannes,
The OSGi HttpService does not provide support or uniqueness guarantees for
registering a servlet by "name" unfortunately, just uniquesness guarantess
on the "path".
What this amounts to is that as you've found
getServletContext().getNamedDispatcher(...) will return null as there are no
named servlets to find. Even if you register with the same HttpContext this
will still return null.
All is not lost...
You can still do your Request Dispatching by "path" and I'd suggest doing
something like this instead.
getServletContext().getRequestDispatcher("/pathToAppointmentServlet ").forward(request,
response)
HTH
-Simon
"Johannes" <ridcully560@yahoo.com> wrote in message
news:em8ric$fob$1@utils.eclipse.org...
> Hi,
>
> I ran into a problem with the RequestDispatcherAdaptor. In the webapp I'm
> trying to set up for running as a bundle in Equinox, I got a
> DispatcherServlet that forwards the request to other Servlets:
>
>> getServletContext().getNamedDispatcher(
>> AppointmentServlet.class.getSimpleName()).forward(request, response);
>
> This works fine in the old version running with tomcat, but when I try it
> with Equinox, I allways get the following exception:
>
>> java.lang.NullPointerException
>> at
>> org.eclipse.equinox.http.servlet.internal.RequestDispatcherA daptor.forward(RequestDispatcherAdaptor.java:19)
>
> Which points to here, where requestDispatcher is null:
>
>> public void forward(ServletRequest req, ServletResponse resp) throws
>> ServletException, IOException {
>> if (req instanceof HttpServletRequestAdaptor)
>> req = ((HttpServletRequestAdaptor) req).getRequest();
>>
>> requestDispatcher.forward(req, resp);
>> }
>
> In an - not answered - older post I found a hint that it might be because
> of different context of the servlets. After that, I also registered the
> other servlet:
>
>> ServiceReference sr =
>> bc.getServiceReference(HttpService.class.getName());
>> if(sr != null) {
>> HttpService http = (HttpService)context.getService(sr);
>> if(http != null) {
>> http.registerServlet("/path/MainServlet", new MainServlet(), null,
>> null);
>> http.registerServlet("/path/ForwardToServlet", new ForwardToServlet(),
>> null, null);
>> }
>> }
>
> But the exception still is thrown.
>
> Maybe someone got a hint about that,
> Johannes
|
|
|
Re: RequestDispatcherAdaptor NullPointerException [message #79596 is a reply to message #79524] |
Tue, 19 December 2006 17:50 |
Eclipse User |
|
|
|
Originally posted by: ridcully560.yahoo.com
Hi Simon
> All is not lost...
> You can still do your Request Dispatching by "path" and I'd suggest doing
> something like this instead.
> getServletContext().getRequestDispatcher("/pathToAppointmentServlet ").forward(request,
> response)
>
> HTH
>
> -Simon
Yes, seems to work!
Thanks,
Johannes
|
|
|
Powered by
FUDForum. Page generated in 0.03374 seconds