From do-not-reply at jboss.com Thu May 28 13:15:57 2009 Content-Type: multipart/mixed; boundary="===============4191391818074459894==" MIME-Version: 1.0 From: jrinderle To: jbossws-users at lists.jboss.org Subject: [jbossws-users] [JBossWS] - Resteasy, handling and logging of WebApplicationException Date: Thu, 28 May 2009 13:08:02 -0400 Message-ID: <8358661.1243530482760.JavaMail.jboss@tmp3.prod.atl2.jboss.com> --===============4191391818074459894== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Resteasy logs a stracktrace for all WebApplicationExceptions, which is not = what I was expecting. My expectation was that Resteasy would catch this exc= eption and return an appropriate response, but not log the exception. This = creates a lot of output in the server logs. * What is the most appropriate way to specify a response status? I could re= turn Response but it seems cleaner to return a specific type and throw WebA= pplicationException for errors. I created the following test case: | @GET | @Path("/status/{code}") | public String getStatus(@PathParam("code") int statusCode) { | throw new WebApplicationException(statusCode); | } | = No matter what code I specify, the exception stack trace is logged to STDER= R and I get the JBossWeb default error page back (even if I modify the code= to specify no content). * This behavior caused me to question my understanding. Should I not specif= y a response status by throwing a WebApplicationException? Should I instead= return Response or use a custom exception with an exception mapper? In a p= roduction environment I do not need to log a stack trace for 401, 404, etc. * Is it possible to disable the default error page and return an empty resp= onse? I tried changing the test case to throw new WebApplicationException(R= esponse.noContent().status(statusCode).build()); but I still get default er= ror page. * I was also surprised to see the exception logged to STDERR. The documenta= tion says that Resteasy uses slf4j configured or log4j. Perhaps I have some= thing configured incorrectly? I have tested this behavior with Resteasy 1.0.2GA and 1.1RC2. I am running = on JBoss 4.2.3.GA. = When I request this resource with /status/401, I get the following response= (output is from curl). = | < HTTP/1.1 401 Unauthorized | < Date: Thu, 28 May 2009 16:36:38 GMT | < Server: Apache | < Content-Length: 948 | < Content-Type: text/html;charset=3Dutf-8 | * Connection #0 to host localhost left intact | * Closing connection #0 | JBossWeb/2.0.1.GA - Error report

HTTP Status 401 -


<= b>type Status report

message

description<= /b> This request requires HTTP authentication ().


JBossWeb/2.0.1.GA

| = And the following exception is logged (I sanitized my class and package nam= e, line 74 corresponds to the exception thrown above): | 2009-05-28 12:38:42,883 ERROR [STDERR] 147486 [ajp-127.0.0.1-8009-11] E= RROR org.jboss.resteasy.core.SynchronousDispatcher - failed t | o execute | 2009-05-28 12:38:42,883 ERROR [STDERR] javax.ws.rs.WebApplicationExcept= ion | 2009-05-28 12:38:42,883 ERROR [STDERR] at my.test.app.MyResource.getSe= ssionDetails(MyResource.ja | va:74) | 2009-05-28 12:38:42,883 ERROR [STDERR] at sun.reflect.NativeMethodAcce= ssorImpl.invoke0(Native Method) | 2009-05-28 12:38:42,884 ERROR [STDERR] at sun.reflect.NativeMethodAcce= ssorImpl.invoke(NativeMethodAccessorImpl.java:39) | 2009-05-28 12:38:42,884 ERROR [STDERR] at sun.reflect.DelegatingMethod= AccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | 2009-05-28 12:38:42,884 ERROR [STDERR] at java.lang.reflect.Method.inv= oke(Method.java:597) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Meth= odInjectorImpl.invoke(MethodInjectorImpl.java:119) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Reso= urceMethod.invokeOnTarget(ResourceMethod.java:211) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Reso= urceMethod.invoke(ResourceMethod.java:176) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Reso= urceMethod.invoke(ResourceMethod.java:166) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Sync= hronousDispatcher.invoke(SynchronousDispatcher.java:356) | 2009-05-28 12:38:42,884 ERROR [STDERR] at org.jboss.resteasy.core.Sync= hronousDispatcher.invoke(SynchronousDispatcher.java:160) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.jboss.resteasy.plugins.s= erver.servlet.HttpServletDispatcher.service(HttpServletDispat | cher.java:113) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.jboss.resteasy.plugins.s= erver.servlet.HttpServletDispatcher.service(HttpServletDispat | cher.java:69) | 2009-05-28 12:38:42,885 ERROR [STDERR] at javax.servlet.http.HttpServl= et.service(HttpServlet.java:803) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.apache.catalina.core.App= licationFilterChain.internalDoFilter(ApplicationFilterChain.j | ava:290) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.apache.catalina.core.App= licationFilterChain.doFilter(ApplicationFilterChain.java:206) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.jboss.web.tomcat.filters= .ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.apache.catalina.core.App= licationFilterChain.internalDoFilter(ApplicationFilterChain.j | ava:235) | 2009-05-28 12:38:42,885 ERROR [STDERR] at org.apache.catalina.core.App= licationFilterChain.doFilter(ApplicationFilterChain.java:206) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.core.Sta= ndardWrapperValve.invoke(StandardWrapperValve.java:230) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.core.Sta= ndardContextValve.invoke(StandardContextValve.java:175) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.jboss.web.tomcat.securit= y.SecurityAssociationValve.invoke(SecurityAssociationValve.ja | va:182) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.jboss.web.tomcat.securit= y.JaccContextValve.invoke(JaccContextValve.java:84) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.core.Sta= ndardHostValve.invoke(StandardHostValve.java:127) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.valves.E= rrorReportValve.invoke(ErrorReportValve.java:102) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.jboss.web.tomcat.service= .jca.CachedConnectionValve.invoke(CachedConnectionValve.java: | 157) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.core.Sta= ndardEngineValve.invoke(StandardEngineValve.java:109) | 2009-05-28 12:38:42,886 ERROR [STDERR] at org.apache.catalina.connecto= r.CoyoteAdapter.service(CoyoteAdapter.java:262) | 2009-05-28 12:38:42,887 ERROR [STDERR] at org.apache.coyote.ajp.AjpPro= cessor.process(AjpProcessor.java:437) | 2009-05-28 12:38:42,887 ERROR [STDERR] at org.apache.coyote.ajp.AjpPro= tocol$AjpConnectionHandler.process(AjpProtocol.java:366) | 2009-05-28 12:38:42,887 ERROR [STDERR] at org.apache.tomcat.util.net.J= IoEndpoint$Worker.run(JIoEndpoint.java:446) | 2009-05-28 12:38:42,887 ERROR [STDERR] at java.lang.Thread.run(Thread.= java:619) | = SynchronousDispatcher.java:324: if (!(wae instanceof NoLogWebApplicationException)) logger.error("failed to= execute", wae); My web.xml is as follows: | | | | resteasy.scan | true | | | org.jboss.resteasy.plugins.server.servlet.ResteasyBoo= tstrap | | | RESTeasy | org.jboss.resteasy.plugins.server.servlet.HttpServletD= ispatcher | | | RESTeasy | /* | | | = Thank you for your help! View the original post : http://www.jboss.org/index.html?module=3Dbb&op=3Dv= iewtopic&p=3D4233957#4233957 Reply to the post : http://www.jboss.org/index.html?module=3Dbb&op=3Dpostin= g&mode=3Dreply&p=3D4233957 --===============4191391818074459894==--