Hello,

I have an exception interceptor but it doesn't feel like it's being called.

I have a web service throwing a business exception:

public class BusinessException extends Exception {

        private static final long serialVersionUID = -5864470001914577094L;

}

The unit test catches the business exception just fine and the test passes:

        @Test
        public void testMakeBusinessException() {
                try {
                        helloService.makeBusinessException();
                } catch (BusinessException e) {
                        logger.debug("==============>>> Business exception: " + 
e.getMessage() +
" " + e.getCause());
                        return;
                }
                fail("The expected business exception was not thrown.");
        }

I also have set up an interceptor:

@NoJSR250Annotations
public class ExceptionInterceptor extends AbstractSoapInterceptor {

        private Logger logger =
LoggerFactory.getLogger(ExceptionInterceptor.class);

        public ExceptionInterceptor() {
                super(Phase.PRE_LOGICAL);
                logger.error("=================>>> Calling the constructor of
ExceptionInterceptor.");
        }

        public void handleMessage(SoapMessage message) throws Fault {
                Fault fault = (Fault) message.getContent(Exception.class);
                Throwable ex = fault.getCause();
                logger.error("=================>>> A soap fault has been 
caught.");
                if (ex instanceof BusinessException) {
                        BusinessException e = (BusinessException) ex;
                        logger.debug("=================>>> Generating a soap 
fault with a
business exception.");
                        generateSoapFault(fault, e);
                } else {
                        logger.debug("=================>>> Generating a soap 
fault with an
exception that is not a business one.");
                        generateSoapFault(fault, null);
                }
        }

        private void generateSoapFault(Fault fault, Exception e) {
                int dummy_error_code = 1234;
                fault.setFaultCode(createQName(dummy_error_code));
                fault.setMessage("A business exception occured and the error 
code was " +
dummy_error_code);
        }

        private static QName createQName(int errorCode) {
                return new QName("http://cxf.nki.no";, 
String.valueOf(errorCode));
        }
        
}

With the following Spring configuration:

                <cxf:outFaultInterceptors>
                        <ref bean="exceptionInterceptor" />
                </cxf:outFaultInterceptors>

        <bean id="exceptionInterceptor"
class="no.nki.springws.server.interceptor.ExceptionInterceptor">
        </bean>

The Maven build is successful.

But I can see none of the logger.debug() statements output in the console.

The only logger.debug() statements I see in the console are these two:

This one:

        @Override
    public void makeBusinessException() throws BusinessException {
                logger.debug("===================>>> Making a business 
exception.");
        throw new BusinessException();
    }

And this one from the test above:
logger.debug("==============>>> Business exception: " + e.getMessage() + " "
+ e.getCause());

And here is the console output:

2012-02-07 20:02:15,371 DEBUG  [DependencyInjectionTestExecutionListener]
Performing dependency injection for test context [[TestContext@88e2dd
testClass = HelloServiceTest, testInstance =
no.nki.springws.server.service.HelloServiceTest@152643, testMethod = [null],
testException = [null], mergedContextConfiguration =
[MergedContextConfiguration@203c31 testClass = HelloServiceTest, locations =
'{classpath:spring-services.xml, classpath:spring-cxf.xml,
classpath:spring-jaxws-endpoints.xml, classpath:log4j.xml}', classes = '{}',
activeProfiles = '{}', contextLoader =
'org.springframework.test.context.support.DelegatingSmartContextLoader']]]. 
2012-02-07 20:02:15,372 DEBUG  [TestContext] Retrieved ApplicationContext
for test class [class no.nki.springws.server.service.HelloServiceTest] from
cache with key [[MergedContextConfiguration@203c31 testClass =
HelloServiceTest, locations = '{classpath:spring-services.xml,
classpath:spring-cxf.xml, classpath:spring-jaxws-endpoints.xml,
classpath:log4j.xml}', classes = '{}', activeProfiles = '{}', contextLoader
= 'org.springframework.test.context.support.DelegatingSmartContextLoader']]. 
2012-02-07 20:02:15,372 DEBUG  [InjectionMetadata] Processing injected
method of bean 'no.nki.springws.server.service.HelloServiceTest':
AutowiredFieldElement for private
no.nki.springws.server.service.HelloService
no.nki.springws.server.service.HelloServiceTest.helloService 
2012-02-07 20:02:15,372 DEBUG  [DefaultListableBeanFactory] Returning cached
instance of singleton bean 'helloService' 
2012-02-07 20:02:15,372 DEBUG  [HelloServiceImpl] ===================>>>
Making a business exception. 
2012-02-07 20:02:15,372 DEBUG  [HelloServiceTest] ==============>>> Business
exception: null null 
2012-02-07 20:02:15,373 DEBUG  [DirtiesContextTestExecutionListener] After
test method: context [[TestContext@88e2dd testClass = HelloServiceTest,
testInstance = no.nki.springws.server.service.HelloServiceTest@152643,
testMethod = testMakeBusinessException@HelloServiceTest, testException =
[null], mergedContextConfiguration = [MergedContextConfiguration@203c31
testClass = HelloServiceTest, locations = '{classpath:spring-services.xml,
classpath:spring-cxf.xml, classpath:spring-jaxws-endpoints.xml,
classpath:log4j.xml}', classes = '{}', activeProfiles = '{}', contextLoader
=
'org.springframework.test.context.support.DelegatingSmartContextLoader']]],
class dirties context [false], class mode [null], method dirties context
[false]. 
2012-02-07 20:02:15,373 DEBUG  [DirtiesContextTestExecutionListener] After
test class: context [[TestContext@88e2dd testClass = HelloServiceTest,
testInstance = [null], testMethod = [null], testException = [null],
mergedContextConfiguration = [MergedContextConfiguration@203c31 testClass =
HelloServiceTest, locations = '{classpath:spring-services.xml,
classpath:spring-cxf.xml, classpath:spring-jaxws-endpoints.xml,
classpath:log4j.xml}', classes = '{}', activeProfiles = '{}', contextLoader
=
'org.springframework.test.context.support.DelegatingSmartContextLoader']]],
dirtiesContext [false]. 
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.171 sec

Any clue ?

Thanks

Stephane


--
View this message in context: 
http://cxf.547215.n5.nabble.com/Why-is-my-exception-interceptor-not-being-called-tp5464238p5464238.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to