View Javadoc

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