when trying to use org.eclipse.jetty.server.Request in my app, either get class cast exceptions, or can't find class

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

when trying to use org.eclipse.jetty.server.Request in my app, either get class cast exceptions, or can't find class

buildlackey
Hi,

I have an application which depends on
the continuation support in org.eclipse.jetty.server.Request.

In my doGet/doPost methods I find that I am getting
class cast exceptions when I try to cast the incoming
javax.servlet.http.HttpServletRequest argument to
org.eclipse.jetty.server.Request.

I've stripped down my problem to the very simple servlet you see below..  A full zip of the maven
project which demonstrates the issue is also attached.



package test;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.servlet.http.HttpUtils;

public class HelloServlet extends HttpServlet {
        public void doGet (HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
                org.eclipse.jetty.server.Request r =
                    (org.eclipse.jetty.server.Request)req;         <<<---- Class cast exception occurs here.
                String url = HttpUtils.getRequestURL(req).toString();
                System.out.println(" here is the url: " + url);
                PrintWriter out = res.getWriter();
                out.println("

Hello, world!

<br>");
                out.println("

Billy-Ray Bob and Chen-ho love Servlets!

");
                out.close();
        }
}


When I run with the jetty system classes packaged up as part of my .war I get the following error:


    java.lang.ClassCastException: org.eclipse.jetty.server.Request cannot be cast to org.eclipse.jetty.server.Request

This happens when my maven pom.xml is defined thusly..

    <dependency>
     <artifactId>jetty-server</artifactId>
       <groupId>org.eclipse.jetty</groupId>
       <version>7.0.0.RC6 </version>
    </dependency>

which leads to the following conent of my WEB-INF/lib/ directory.

jetty-continuation-7.0.0.RC6.jar  jetty-server-7.0.0.RC6.jar
jetty-http-7.0.0.RC6.jar          jetty-util-7.0.0.RC6.jar
jetty-io-7.0.0.RC6.jar
 



When I exclude the jetty system classes from my .war by changing the jetty dependency in my pom to this ->
    <dependency>
     <artifactId>jetty-server</artifactId>
       <groupId>org.eclipse.jetty</groupId>
       <version>7.0.0.RC6 </version>
       <scope>provided</scope>
    </dependency>

the WEB-INF/lib/ directory of my .war no longer includes  the jetty system classes.


I deploy and re-run my application      (  to run: http://localhost:8080/findFiles/hello )

Without the jetty system classes in my .war I no longer get a class cast exception, I get this error:


        java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Request


It seems the classes in jetty's lib directory are not visible to me, and I don't understand how to
make them visible.


I tried putting this static block in my servlet class.. but it just NPE'd out..

    static {
        ContextHandler.Context ctx =
                org.eclipse.jetty.server.handler.ContextHandler.getCurrentContext();
        WebAppContext webAppContext = (WebAppContext)ctx.getContextHandler();
        String classes[] = new String[]   { "org.eclipse.jetty.server.Request" };
        webAppContext.setServerClasses( classes );
    }


I'm guessing that other folks have done similar things.. any help much appreciated.
thanks !
 Chris

--
Chris Bedford

Founder & Lead Lackey
Build Lackey Labs
http://buildlackey.com


jettyProblem.tar.gz
Reply | Threaded
Open this post in threaded view
|

Re: when trying to use org.eclipse.jetty.server.Request in my app, either get class cast exceptions, or can't find class

gevorg
This post has NOT been accepted by the mailing list yet.
Chris,

did you find out what was causing the issue? I'm having the same problem and have no idea what's going on...

Thanks!