Hi,

I've got a pretty simple example using CXF 2.2.5 and Spring 2.5.4.  I am setup 
in my spring for both SOAP and REST services, but am only testing the REST 
service right now.  I have a simple service that throws an exception and have 
registered a simple ExceptionMapper, but the mapper is never being called.  The 
exception is being converted into a Fault and handled instead by 
XMLFaultOutInterceptor.  With my debugger I can see that my mapper is never 
being called.  What am I doing wrong?

Thanks

John McGinn

My mapper class looks like this:
@Provider
public class InvalidEquipmentIdExceptionMapper implements 
ExceptionMapper<InvalidEquipmentIdException> {

        public Response toResponse(InvalidEquipmentIdException e) {

                EquipmentValidationResponse response = new 
EquipmentValidationResponse();

                response.setMessageHeader(new MessageHeaderResponseType());
                response.getMessageHeader().setCorrelationId("TEST");
                response.getMessageHeader().setSender("RAIL");
                response.getMessageHeader().setReceiver("TEST");
                
response.getMessageHeader().setTimestamp(Calendar.getInstance());
                response.getMessageHeader().setResultDetails(new 
ResultDetailsType());

                response.getMessageHeader().setResult("FAILED");
                response.getMessageHeader().setResultDescription("Equipment ID 
is Not in a Valid Format");
                ErrorDetailType error = new ErrorDetailType();
                error.setResultCode("INVALID_EQUIP_ID");
                error.setDescription(e.getMessage());
                
response.getMessageHeader().getResultDetails().getResultDetails().add(error);

                return 
Response.status(Status.BAD_REQUEST).entity(response).type("application/xml").build();
                //throw new 
WebApplicationException(Response.status(Status.BAD_REQUEST).entity(response).type("application/xml").build());
        }
}

My spring JAXRS config looks like this:
        <jaxrs:server id="restService" address="/services/">
                <jaxrs:providers>
                        <ref bean="invalidEquipmentIdExceptionMapper"/>
                </jaxrs:providers>
                <jaxrs:serviceBeans>
                        <ref bean="equipmentServiceImpl" />
                </jaxrs:serviceBeans>
        </jaxrs:server>

When I call the service with a certain value it throws 
InvalidEquipmentIdException (a checked exception).

In my log I see the following:
2010-01-07 11:31:24,377 http-8080-2 DEBUG 
[apache.cxf.phase.PhaseInterceptorChain] Invoking handleMessage on interceptor 
org.apache.cxf.binding.xml.interceptor.xmlfaultoutintercep...@b2c64
2010-01-07 11:31:24,377 http-8080-2 DEBUG 
[apache.cxf.phase.PhaseInterceptorChain] Application has thrown exception, 
unwinding now
org.apache.cxf.interceptor.Fault: Equipment Number must be numeric
        at 
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
        at 
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:130)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:82)
        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:106)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
        at 
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:109)
        at 
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:98)
        at 
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:394)
        at 
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:133)
        at 
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
        at 
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
        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:175)
        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:263)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:595)
Caused by: 
com.railinc.test.work4.equipment.services.InvalidEquipmentIdException: 
Equipment Number must be numeric
        at 
com.railinc.test.work4.equipment.services.impl.ExampleEquipmentLookupServiceImpl.lookupEquipment(ExampleEquipmentLookupServiceImpl.java:44)
        at 
com.railinc.test.work4.eq.services.impl.ExampleEquipmentServiceImpl.getEquipment(ExampleEquipmentServiceImpl.java:59)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)
        at 
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
        ... 30 more

CXFServlet eventually converts this into a RuntimeException.

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. If 
you have received this email in error please notify the system manager. This 
message contains confidential information and is intended only for the 
individual named. If you are not the named addressee you should not 
disseminate, distribute or copy this e-mail.

Reply via email to