Hi Xavier I'm finishing some DOSGI JAX-RS work so I will run the tests tomorrow morning at the latest. Just one question, before I try to do a test :
what happens if you only have a base AuthenticationExceptionMapper ? Does it catch ForbiddenLGOException ? what happens if you remove AuthenticationExceptionMapper ? Does ForbiddenLGOExceptionmapper catch ForbiddenLGOExceptions in this case ? thanks, Sergey Xavier wrote: > > Hello, > > I've been facing the following issue for the last two days and I can't > find that's wrong with my config (using CXF 2.2.3 with Spring 2.5) : > > I have regsitered 2 ExceptionMappers that should intercept some custom > checked exceptions that my service bean may throw. These exceptions are > authentication related. For now, the Exception Mappers are not called, and > on the browser side, I get 500 errors pages with (ugly) stacktraces, > instead of 403 errors pages with a custom message. > I'd like to use the exception mappers to be able to handle any king of > exceptions (those checked exceptions and later any other runtime exception > with custom messages), instead of having try/catch blocks everywhere with > WebApplicationException wrappers. Code would remain cleaner and lighter > ;-) > > Here are my config files and classes: > > web.xml: > <?xml version="1.0" encoding="UTF-8"?> > <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://java.sun.com/xml/ns/javaee" > xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee > http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" > id="WebApp_ID" version="2.5"> > > <context-param> > <param-name>contextConfigLocation</param-name> > <param-value>classpath*:META-INF/spring*Context.xml</param-value> > </context-param> > > <listener> > > <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> > </listener> > > <servlet> > <display-name>CXF Servlet</display-name> > <servlet-name>CXFServlet</servlet-name> > > <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> > <load-on-startup>1</load-on-startup> > </servlet> > > <servlet-mapping> > <servlet-name>CXFServlet</servlet-name> > <url-pattern>/*</url-pattern> > </servlet-mapping> > > > </web-app> > > > > spring config file (named springCXFContext.xml): > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:context="http://www.springframework.org/schema/context" > xmlns:jaxrs="http://cxf.apache.org/jaxrs" > xmlns:cxf="http://cxf.apache.org/core" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://www.springframework.org/schema/context > http://www.springframework.org/schema/context/spring-context-2.5.xsd > http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd > http://cxf.apache.org/core http://cxf.apache.org/schemascore.xsd"> > > <import resource="classpath:META-INF/cxf/cxf.xml" /> > <import > resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" /> > <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> > > > > <jaxrs:server id="alertesService" address="/"> > <jaxrs:features> > <cxf:logging /> > </jaxrs:features> > > <jaxrs:serviceBeans> > <ref bean="alertesServiceBean" /> > </jaxrs:serviceBeans> > <jaxrs:providers > > <bean class="org.apache.cxf.jaxrs.provider.AtomFeedProvider" /> > <ref bean="forbiddenOfficineExceptionMapper" /> > <ref bean="forbiddenLGOExceptionMapper" /> > <ref bean="genericFaultResponseExceptionMapper" /> > </jaxrs:providers> > </jaxrs:server> > > > > <bean id="alertesServiceBean" class="x.y.z.AlertesService" /> > <bean id="forbiddenOfficineExceptionMapper" > class="x.y.z.provider.ForbiddenOfficineExceptionMapper" /> > <bean id="forbiddenLGOExceptionMapper" > class="x.y.z.provider.ForbiddenLGOExceptionMapper" /> > <bean id="authenticationExceptionMapper" > class="x.y.z.provider.AuthenticationExceptionMapper" /> > <bean id="genericFaultResponseExceptionMapper" > class="x.y.z.provider.GenericFaultResponseExceptionMapper" /> > > </beans> > > > Code for ForbiddenOfficineExceptionMapper : > > @Provider > public class ForbiddenOfficineExceptionMapper implements > ExceptionMapper<ForbiddenOfficineException> { > > public Response toResponse(ForbiddenOfficineException e) { > return > Response.status(403).type(MediaType.TEXT_PLAIN).entity("...").build(); > } > } > > > Code (snippet)for AlertesServiceBean : > > @GET > @Path("/{finess}/heartbeat") > @Produces("text/plain") > @Transactional(readOnly = true) > public Response heartbeat(@PathParam("finess") String codeFiness, > @Context UriInfo ui, @Context HttpHeaders headers) > throws > AuthenticationException > { ... } > > (AuthenticationException is the super class of ForbiddenOfficineException) > > > BTW, some console messages (running on tomcat 6): > > 25 août 2009 16:50:30 org.apache.tomcat.util.digester.SetPropertiesRule > begin > ATTENTION: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting > property 'source' to 'org.eclipse.jst.j2ee.server:DP-ServicesAnnexes-WS' > did not find a matching property. > 25 août 2009 16:50:30 org.apache.catalina.core.AprLifecycleListener init > INFO: Loaded APR based Apache Tomcat Native library 1.1.14. > 25 août 2009 16:50:30 org.apache.catalina.core.AprLifecycleListener init > INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters > [false], random [true]. > 25 août 2009 16:50:31 org.apache.coyote.http11.Http11AprProtocol init > INFO: Initialisation de Coyote HTTP/1.1 sur http-8080 > 25 août 2009 16:50:31 org.apache.coyote.ajp.AjpAprProtocol init > INFO: Initializing Coyote AJP/1.3 on ajp-8009 > 25 août 2009 16:50:31 org.apache.catalina.startup.Catalina load > INFO: Initialization processed in 2603 ms > 25 août 2009 16:50:32 org.apache.catalina.core.StandardService start > INFO: D�marrage du service Catalina > 25 août 2009 16:50:32 org.apache.catalina.core.StandardEngine start > INFO: Starting Servlet Engine: Apache Tomcat/6.0.18 > 25 août 2009 16:50:35 org.apache.catalina.core.ApplicationContext log > INFO: Initializing Spring root WebApplicationContext > ehcache configuration for cache named > [org.hibernate.cache.StandardQueryCache]; using defaults. > 25 août 2009 16:51:24 org.apache.cxf.endpoint.ServerImpl initDestination > INFO: Setting the server's publish address to be / > 25 août 2009 16:51:25 org.apache.cxf.transport.servlet.CXFServlet > updateContext > INFO: Load the bus with application context > Console> 2009-08-25 16:51:25|INFO || > AbstractApplicationContext.prepareRefresh |Refreshing > org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7: display name > [org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7]; startup date > [Tue Aug 25 16:51:25 CEST 2009]; parent: > org.springframework.web.context.support.xmlwebapplicationcont...@15e0c2b > 25 août 2009 16:51:25 org.apache.cxf.bus.spring.BusApplicationContext > getConfigResources > INFO: No cxf.xml configuration file detected, relying on defaults. > Console> 2009-08-25 16:51:25|INFO || > AbstractApplicationContext.obtainFreshBeanFactory |Bean factory for > application context > [org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7]: > org.springframework.beans.factory.support.defaultlistablebeanfact...@32835b > Console> 2009-08-25 16:51:25|DEBUG|| > AbstractApplicationContext.obtainFreshBeanFactory |0 beans defined in > org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7: display name > [org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7]; startup date > [Tue Aug 25 16:51:25 CEST 2009]; parent: > org.springframework.web.context.support.xmlwebapplicationcont...@15e0c2b > Console> 2009-08-25 16:51:25|DEBUG|| > AbstractApplicationContext.initMessageSource |Unable to locate > MessageSource with name 'messageSource': using default > [org.springframework.context.support.delegatingmessagesou...@146ccac] > Console> 2009-08-25 16:51:25|DEBUG|| > AbstractApplicationContext.initApplicationEventMulticaster |Unable to > locate ApplicationEventMulticaster with name > 'applicationEventMulticaster': using default > [org.springframework.context.event.simpleapplicationeventmulticas...@1274873] > Console> 2009-08-25 16:51:25|DEBUG|| > AbstractApplicationContext.publishEvent |Publishing event in context > [org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7]: > org.springframework.context.event.contextrefreshedevent[source=org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7: > display name [org.apache.cxf.bus.spring.busapplicationcont...@17ef0a7]; > startup date [Tue Aug 25 16:51:25 CEST 2009]; parent: > org.springframework.web.context.support.xmlwebapplicationcont...@15e0c2b] > 25 août 2009 16:51:25 org.apache.cxf.transport.servlet.AbstractCXFServlet > replaceDestinationFactory > INFO: Servlet transport factory already registered > 25 août 2009 16:51:26 org.apache.coyote.http11.Http11AprProtocol start > INFO: D�marrage de Coyote HTTP/1.1 sur http-8080 > 25 août 2009 16:51:26 org.apache.coyote.ajp.AjpAprProtocol start > INFO: Starting Coyote AJP/1.3 on ajp-8009 > 25 août 2009 16:51:26 org.apache.catalina.startup.Catalina start > INFO: Server startup in 54687 ms > 25 août 2009 16:51:40 org.apache.cxf.interceptor.LoggingInInterceptor > logging > INFO: Inbound Message > ... > [spring, hibernate and auth stuff occur here] > ... > > 25 août 2009 16:51:48 org.apache.cxf.phase.PhaseInterceptorChain > doIntercept > INFO: Application has thrown exception, unwinding now: > dp.servicesannexes.exception.ForbiddenOfficineException: L'officine n'est > pas encore active > 25 août 2009 16:51:49 org.apache.cxf.phase.PhaseInterceptorChain > doIntercept > INFO: Application has thrown exception, unwinding now: > dp.servicesannexes.exception.ForbiddenOfficineException: L'officine n'est > pas encore active > 25 août 2009 16:51:49 org.apache.cxf.phase.PhaseInterceptorChain unwind > ATTENTION: Exception in handleFault on interceptor > org.apache.cxf.binding.xml.interceptor.xmlfaultoutintercep...@db19d3 > org.apache.cxf.interceptor.Fault: L'officine n'est pas encore active > at > org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:148) > at > org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:114) > at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:118) > at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:78) > at > org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) > at > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269) > at java.util.concurrent.FutureTask.run(FutureTask.java:123) > at > org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) > at > org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:98) > at > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236) > at > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104) > at > org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99) > at > org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:452) > at > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:159) > at > org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:220) > at > org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFServlet.java:158) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) > at > org.apache.cxf.transport.servlet.AbstractCXFServlet.service(AbstractCXFServlet.java:211) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) > at > org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857) > at > org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565) > at > org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509) > at java.lang.Thread.run(Thread.java:595) > Caused by <root cause> > > > Any idea why the exception is not caught by the registered ExceptionMapper > ? > > Thank you in advance > Regards, > Xavier > -- View this message in context: http://www.nabble.com/-JAXRS--ExceptionMappers-not-called-tp25136326p25138455.html Sent from the cxf-user mailing list archive at Nabble.com.
