How can we access/edit the CXF Soap Interceptor List?

Solution Unverified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP) 6.x
  • JBoss Enterprise Application Platform (EAP) 5.x

Issue

  • We would like to know how to access the SOAP interceptor list on a JBossWS SOAP client and disable certain interceptors for debug purposes.

Resolution

Take a look at this page:
http://cxf.apache.org/docs/interceptors.html

Search for "InterceptorProviders" about 20% of the way down, and there's a code example:

To add an interceptor to an interceptor chain, you'll want to add it to one of the Interceptor Providers.
MyInterceptor interceptor = new MyInterceptor();
provider.getInInterceptors().add(interceptor);

When you call provider.getInterceptors() this returns a collection object (probably a list of some sort) and while the example has you adding a new interceptor you should be able to iterate through it and change/remove interceptors as well.

As you iterate you should be able to check the class type and look for the interceptor type you want to remove. Here is some sample code for removing an Interceptor:

public static void removeInterceptor(Class<? extends Interceptor<?>> interceptorType, Message message) {
        Iterator<Interceptor<? extends Message>> iterator = message.getInterceptorChain().iterator();
        Interceptor<?> removeInterceptor = null;
        for (; iterator.hasNext();) {
            Interceptor<?> interceptor = iterator.next();
            if (interceptorType.isInstance(interceptor)) {
                removeInterceptor = interceptor;
                break;
            }
        }

        if (removeInterceptor != null) {
            LOGGER.debug("Removing interceptor {}", removeInterceptor.getClass().getName());
            message.getInterceptorChain().remove(removeInterceptor);
        }
    }

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments