We have a service (DefaultMessageListenerContainer) that listens to messages
and when it processes one, we make an HTTP Post to a third party that
requires us to create a stateful session for our interaction.  In the
DefaultMessageListenerContainer we have the min/max Consumers set to 5/10. 
So when we send in about 20+ messages, we have what appears to be a
threading issues.  We use the WebClient to:

1) Setup maintain session
2) Call login
3) Receive a cookie
4) Call method
5) Parse response

What winds up happening is that it appears like another thread comes in and
wiping out the login/Cookie of the previous thread before the previous
thread calls the method it is supposed to, so our 3rd party service assumes
we haven't logged in yet.

Here is our code:

    public ResponseModel postSampleModel(RequestModel requestModel) {
        WebClient webClient = null;

        ResponseModel responseModel = null;
        try {
                    //Create webClient in code with threadsafe set to true
            webClient = WebClient.create(httpsUrl, jaxbProviders, true);
                        WebClient.getConfig(webClient).getRequestContext()
                    .put(org.apache.cxf.message.Message.MAINTAIN_SESSION,
Boolean.TRUE);
                                        
                        //create login xml and send request
            RequestModel loginRequest = createLogin();
            postRequest(webClient, loginRequest);
                        
            //send original after the login
            Response response = postRequest(webClient, requestModel);
            InputStream inputStream = (InputStream) response.getEntity();
                        
                        //return the unmarshalled response
            responseModel = ResponseModelUtil.unmarshal(ResponseModel.class,
inputStream);
        } finally {
            if (webClient != null) {
                webClient.reset();
            }
        }
        return responseModel;
    }

    private Response postRequest(WebClient webClient, RequestModel
requestModel) {

                String xml = RequestModelUtil.marshal(RequestModel.class, 
requestModel);
                
        Response response = webClient.post(xml);

        if (response.getStatus() != 200) {
            LOGGER.error("Request to fastrieve was unsuccessful");
        }
        return response;

    }

So when something like this sits in a DefaultMessageListenerContainer, if a
few instances are running at a time, will the WebClient produce a unique
cookie for each request running in parallel?  What other reason could be
causing this potential threading issue?

Thanks...jay



--
View this message in context: 
http://cxf.547215.n5.nabble.com/WebClient-multithreading-within-a-DefaultMessageListenerContainer-tp5719525.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to