I am trying to create 2 clients to connect to a webservice, one does not need
Interceptors the other does.
Based on my trials it seems the Interceptors are being shared between
different clients created from the same factory. Even if a client (client1)
was created before Interceptors were added to the factory. The second client
(client2) is being created after adding the Interceptors.

Here is my code -
---------------------------------------------------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;

import javax.xml.ws.Holder;

import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;

public class WebServiceClient {

        /**
         * @param args
         */
        public static void main(String[] args) {
                JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
                factory.getInInterceptors().add(new LoggingInInterceptor());
                factory.getOutInterceptors().add(new LoggingOutInterceptor());
                factory.setServiceClass(ExtractionService.class);
                factory.setAddress("https://webservice.url.goes.here";);
                factory.setUsername("UserNameGoesHere");
                factory.setPassword("Password");

                //Creating the client1 that should not have the 
WSS4JOutInterceptor
interceptors
                ServiceA client1 = (ServiceA) factory.create();

                //Request to the webservice understood and was able to retrieve 
the data
                VersionInfo reply = client1.getVersion();
                System.out.println("API Version: " + reply.getApiVersion());
                
                Map<String, Object> outprops = new HashMap<String, Object>();
                outprops.put(WSHandlerConstants.ACTION,
WSHandlerConstants.USERNAME_TOKEN);
                outprops.put(WSHandlerConstants.USER, "UserNameGoesHere");
                outprops.put(WSHandlerConstants.PASSWORD_TYPE, 
WSConstants.PW_TEXT);
                //Gets the password from the ClientPasswordCallbackHandler class
                outprops.put(WSHandlerConstants.PW_CALLBACK_CLASS,
ClientPasswordCallbackHandler.class.getName());

                WSS4JOutInterceptor  wssout = new WSS4JOutInterceptor(outprops);
                factory.getOutInterceptors().add(wssout); 

                
                //Creating the client2 that should have WSS4JOutInterceptor 
interceptors
                ServiceB client2 = (ServiceB) factory.create();

                //Request to the webservice was not understood and was unable 
to retrieve
the data
                //although we are using client1 which was created for ServiceA
                                
                VersionInfo reply = client1.getVersion();
                System.out.println("API Version: " + reply.getApiVersion());
        
                System.exit(0);
        }
}

------------------------------------------------------------------------------------------------------

Here is the error message I get -
------------------------------------------------------------------------------------------------------
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: SOAP header
Security was not understood.
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:199)
        at $Proxy52.validateInstruments(Unknown Source)
        at
com.xxxxxxxxx.xxxxxxx.ws.client.WebServiceClient.main(WebServiceClient.java:167)
Caused by: org.apache.cxf.binding.soap.SoapFault: SOAP header Security was
not understood.
        at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:70)
        at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
        at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
        at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
        at
org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:449)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2029)
        at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
        at
org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
        at 
org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:170)
        at 
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
        at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
        ... 2 more
-------------------------



-- 
View this message in context: 
http://www.nabble.com/Shared-Interceptors-causing-error---Broken-Encapsulation--tp19438399p19438399.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to