View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf;
8   
9   import java.lang.reflect.Method;
10  import java.util.List;
11  import java.util.Map;
12  
13  import javax.xml.ws.handler.MessageContext.Scope;
14  
15  import org.apache.cxf.jaxws.JAXWSMethodInvoker;
16  import org.apache.cxf.jaxws.context.WebServiceContextImpl;
17  import org.apache.cxf.jaxws.context.WrappedMessageContext;
18  import org.apache.cxf.message.Exchange;
19  import org.apache.cxf.service.invoker.Invoker;
20  
21  public class MuleJAXWSInvoker extends JAXWSMethodInvoker
22  {
23      private Invoker muleInvoker;
24  
25      public MuleJAXWSInvoker(Invoker muleInvoker)
26      {
27          super(new Object());
28          this.muleInvoker = muleInvoker;
29      }
30  
31      @Override
32      protected Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params)
33      {
34          // set up the webservice request context
35          WrappedMessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);
36  
37          Map<String, Object> handlerScopedStuff = removeHandlerProperties(ctx);
38  
39          WebServiceContextImpl.setMessageContext(ctx);
40          Object res = null;
41          try
42          {
43              res = muleInvoker.invoke(exchange, serviceObject);
44              addHandlerProperties(ctx, handlerScopedStuff);
45              // update the webservice response context
46              updateWebServiceContext(exchange, ctx);
47          }
48          finally
49          {
50              // clear the WebServiceContextImpl's ThreadLocal variable
51              WebServiceContextImpl.clear();
52          }
53          return res;
54      }
55  }