From: Michael M. <mmu...@re...> - 2011-02-10 18:17:42
|
I do not know the cause of your issue but for what its worth here is some code that I have used in my surefire maven plugin without issues: protected static void startRestEasy(Class<?> ... classes) throws Exception { server = new TJWSEmbeddedJaxrsServer(); server.setPort(PORT); server.start(); Registry registry = server.getDeployment().getRegistry(); ResteasyProviderFactory factory = server.getDeployment().getDispatcher().getProviderFactory(); if (classes != null) for (Class<?> clazz : classes) registry.addPerRequestResource(clazz); factory.addExceptionMapper(...); } @BeforeClass public static void beforeClass() throws Exception {startRestEasy(...);} Mike > Hello Everybody, > > I'm sorry to trouble the list with this question, but I haven't been > able to find an answer via google or the archives, so I thought I'd > email you guys. Basically, I'm trying to use the Embedded server for > jUnit tests on my RESTEasy implementation. I was having trouble just > getting a simple example to work, so I searched Google and came across > the following post from Rob Williams: > "http://www.jroller.com/robwilliams/entry/resteasy_oobe_a_10". In > the comments section, Solomon Duskis makes a suggestion: > >> RESTEasy ClientRequest and EmbeddedServer make this kind of testing >> even easier. Unfortunately, they're not documented yet... the docs >> are in progress. >> >> An example can be found at: >> http://resteasy.svn.sourceforge.net/viewvc/resteasy/trunk/jaxrs/resteasy-jaxrs/src/test/java/org/jboss/resteasy/test/finegrain/client/ClientResponseTest.java?view=markup >> >> >> Posted by *Solomon Duskis* <http://jroller.com/Solomon> on April 27, >> 2009 at 07:21 AM PDT # >> <http://www.jroller.com/robwilliams/entry/resteasy_oobe_a_10#comment-1240842101000> >> > So I followed his suggested approach. My unit tests run perfectly in > my IDE (IntelliJ 10) with no apparent issues. However, when I evoke my > test as part of a general maven 3 build, I run into the following problem: > >> Caused by: java.lang.NullPointerException >> at javax.servlet.GenericServlet.log(GenericServlet.java:300) >> at javax.servlet.GenericServlet.init(GenericServlet.java:257) >> at >> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:33) >> >> at Acme.Serve.Serve.addServlet(Serve.java:509) >> at Acme.Serve.Serve.addServlet(Serve.java:493) >> at >> org.jboss.resteasy.plugins.server.tjws.TJWSServletServer.addServlet(TJWSServletServer.java:57) >> >> at >> org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer.start(TJWSEmbeddedJaxrsServer.java:42) >> >> at >> org.jboss.resteasy.test.TJWSServletContainer.start(TJWSServletContainer.java:50) >> >> at >> org.jboss.resteasy.test.TJWSServletContainer.start(TJWSServletContainer.java:40) >> >> at >> org.jboss.resteasy.test.TJWSServletContainer.start(TJWSServletContainer.java:22) >> > > As I mentioned, it's not possible to debug this, as when I step > through the downloaded source (man, I love maven), I see no NPE from > the IDE perspective. Any ideas as to what could be going on? Am I > missing some logging configuration data that IntelliJ somehow > magically passes on? > > I should also mention, that I although my Unit Tests in IntelliJ all > run, and come up green, I do see the following logged errors in the > output stream: > >> [Thu Feb 10 11:19:40 CST 2011] MIME map can't be >> loaded:java.lang.NullPointerException >> [Thu Feb 10 11:19:40 CST 2011] Servlet for path '/' already defined >> and no default will be used. >> [Thu Feb 10 11:19:40 CST 2011] TJWS httpd 0.0.0.0 - SimpleAcceptor >> ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=8081] is listening. >> [ Thu Feb 10 11:19:47 CST 2011] IO error: java.net.SocketException: >> Broken pipe in processing a request from /127.0.0.1:8081 / >> java.net.Socket >> [Thu Feb 10 11:19:47 CST 2011] Unexpected problem running servlet >> java.lang.IllegalStateException: Can not send an error, headers have >> been already written >> at Acme.Serve.Serve$ServeConnection.realSendError(Serve.java:4205) >> at Acme.Serve.Serve$ServeConnection.sendError(Serve.java:4183) >> at >> org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:71) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.handleFailure(SynchronousDispatcher.java:246) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.handleWriterException(SynchronousDispatcher.java:363) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:202) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.handleWriteResponseException(SynchronousDispatcher.java:187) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488) >> >> at >> org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) >> >> at >> org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:207) >> >> at >> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) >> >> at >> org.jboss.resteasy.plugins.server.tjws.TJWSServletDispatcher.service(TJWSServletDispatcher.java:40) >> >> at >> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) >> >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) >> at Acme.Serve.Serve$ServeConnection.runServlet(Serve.java:2324) >> at Acme.Serve.Serve$ServeConnection.parseRequest(Serve.java:2278) >> at Acme.Serve.Serve$ServeConnection.run(Serve.java:2052) >> at Acme.Utils$ThreadPool$PooledThread.run(Utils.java:1402) >> at java.lang.Thread.run(Thread.java:680) > > I wonder if the null mime map is the issue I'm seeing in Maven? > Should I do more to initialize TJWS then: > >> ResteasyDeployment deployment = EmbeddedContainer.start(); >> dispatcher = deployment.getDispatcher(); >> dispatcher.getRegistry().addPerRequestResource(PackageService.class); > > Here's my client connection code: > >> URL url = new URL(generateBaseUrl() + "/packages"); >> connection = (HttpURLConnection)url.openConnection(); > > Really looking forward to your ideas and suggestions. > > best wishes, > > Andrew Waterman > > > ------------------------------------------------------------------------------ > The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: > Pinpoint memory and threading errors before they happen. > Find and fix more than 250 security defects in the development cycle. > Locate bottlenecks in serial and parallel code that limit performance. > http://p.sf.net/sfu/intel-dev2devfeb > > > _______________________________________________ > Resteasy-users mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/resteasy-users |