Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] org.eclipse.jetty.server.Request cannot be cast to org.eclipse.jetty.server.Request


On Wed, Dec 30, 2015 at 1:03 PM, John Jiang <john.sha.jiang@xxxxxxxxx> wrote:
> Hi guys,
> I'm using Jetty-9.3.5.
> My web app includes a pretty simple Servlet, as shown as the below,
> public class ServerPushServlet extends HttpServlet {
>     protected void doGet(HttpServletRequest request,
>             HttpServletResponse response) throws ServletException,
> IOException {
>         System.out.println("request=" + request);
>         Request baseRequest = (Request) request;
>         System.out.println("baseRequest=" + baseRequest);
>     }
> }
> When I try to access this Servlet via browser, the output in console is the
> below,
> request=Request(GET //localhost:9020/push/primary)@63206451
> 2015-12-30 19:47:11.471:WARN:oejs.ServletHandler:qtp1104106489-15: /test
> java.lang.ClassCastException: org.eclipse.jetty.server.Request cannot be
> cast to org.eclipse.jetty.server.Request
>         at httptest.ServerPushServlet.doGet(

The Servlet specification mandates that server implementation classes
must be hidden from webapps.
As such, you cannot use server classes in your webapp.

If you try to include the jetty-server-<version>.jar in your war, you
get the ClassCastException.
If you remove it from the war, you get a ClassNotFoundException
because the server hides it from the webapp.

If you really need to use Jetty's classes, your best bet is to avoid
webapps and their classloading, and just use Jetty's
ServletContextHandler which will allow you to deploy Servlets without
the classloading complications.

Simone Bordet
Developer advice, training, services and support
from the Jetty & CometD experts.

Back to the top