RANADEEP SHARMA created CXF-6963:
------------------------------------

             Summary: Setting ThreadLocal specific property on RequestContext 
is still not thread-safe
                 Key: CXF-6963
                 URL: https://issues.apache.org/jira/browse/CXF-6963
             Project: CXF
          Issue Type: Bug
          Components: JAX-WS Runtime
    Affects Versions: 3.1.6, 3.1.0
         Environment: 
Redhat Enterprise Linux (Santiago), OpenJDK 7, Tomcat 7
            Reporter: RANADEEP SHARMA


Hi,

I have a overridden factory for JaxWS proxy clients, as shown below. I created 
this class as per the link - 

http://cxf.apache.org/faq.html#FAQ%2DAreJAX%2DWSclientproxiesthreadsafe%3F.

Here's the spring config
--------------------------------
    <bean id="proxyFactory" 
class="com.vcf.soap.jaxws.TSafeJaxWsProxyFactoryBean">
        <property name="serviceClass" 
value="com.vcf.ws.stubs.session.SessionManagerService"/>
        <property name="address" value="${session.manager.service.uri}"/>
    </bean>

    <bean id="sessionManagerServiceClient" 
class="com.vcf.ws.stubs.session.SessionManagerService"
          factory-bean="proxyFactory" factory-method="create"/>

    <bean id="sessionManagerWrapper" 
class="com.vcf.services.session.wrapper.SessionManagerWrapperImpl">
        <property name="sessionManagerService" 
ref="sessionManagerServiceClient" />
        <property name="endpointUri" value="${session.manager.service.uri}" />
    </bean>

Here goes the classes
--------------------------------

public class TSafeJaxWsProxyFactoryBean extends JaxWsProxyFactoryBean {

    public TSafeJaxWsProxyFactoryBean() {
        super();
    }

    public TSafeJaxWsProxyFactoryBean(ClientFactoryBean fact) {
        super(fact);
    }

    @Override
    protected ClientProxy clientClientProxy(Client c) {
        ClientProxy clientProxy = super.clientClientProxy(c);

        clientProxy.getRequestContext().put("thread.local.request.context", 
"true");

        return clientProxy;
    }
}

In my application, I have 2 methods that use the proxy created by the above 
factory. One method - getSessionInfo() populates the 
BindingProvider.ENDPOINT_ADDRESS_PROPERTY into the RequestContext before the 
service call. Another method - startSession() just calls service without 
populating above property.

public class SessionManagerWrapperImpl {

    public SessionInfo startSession() {
        ...
        Map<String, Object> requestContext = ((BindingProvider)       
sessionManagerService).getRequestContext();
        
if(requestContext.containsKey(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)) {
            requestContext.remove(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
        }
        ...
        // Make service call using 'sessionManagerService'
        ...
    }
    
    public SessionInfo getSessionInfo(String sessionId) {

        ((BindingProvider) sessionManagerService).getRequestContext()
                .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUri + 
";jsessionid=" + sessionId);
        
        SessionInfo result = sessionManagerService.getSessionInfo(sessionId);
    }
}

Now, I am getting into a situation where RequestContext is already having the 
mentioned property for the thread processing startSession(). This is not 
expected, since CXF documentation claims the explained usage to be thread-safe. 

Please let me know if my understanding and implementation is correct. However, 
if my usage is correct, is there a possible bug in CXF?

NOTE : i have already created a user thread - 
http://cxf.547215.n5.nabble.com/CXF-client-for-JaxWS-proxy-NOT-thread-safe-tt5770148.html



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to