KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > axis > AxisServiceProxy


1 /*
2  * $Id: AxisServiceProxy.java 3865 2006-11-09 17:11:08Z Lajos $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.soap.axis;
12
13 import java.lang.reflect.InvocationHandler JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15 import java.lang.reflect.Proxy JavaDoc;
16 import org.mule.config.ExceptionHelper;
17 import org.mule.config.MuleProperties;
18 import org.mule.impl.MuleMessage;
19 import org.mule.impl.RequestContext;
20 import org.mule.providers.AbstractMessageReceiver;
21 import org.mule.providers.soap.ServiceProxy;
22 import org.mule.umo.UMOException;
23 import org.mule.umo.UMOExceptionPayload;
24 import org.mule.umo.UMOMessage;
25 import org.mule.umo.provider.UMOMessageAdapter;
26 import org.mule.providers.soap.axis.extras.AxisCleanAndAddProperties;
27
28 /**
29  * <code>ServiceProxy</code> is a proxy that wraps a soap endpointUri to look like
30  * a Web service. Also provides helper methods for building and describing web
31  * service interfaces in Mule.
32  *
33  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
34  * @version $Revision: 3865 $
35  */

36
37 public class AxisServiceProxy extends ServiceProxy
38 {
39
40     public static Object JavaDoc createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class JavaDoc[] classes)
41     {
42         final ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
43         return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous));
44     }
45
46     public static InvocationHandler JavaDoc createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
47     {
48         return new AxisServiceHandler(receiver, synchronous);
49     }
50
51     private static class AxisServiceHandler implements InvocationHandler JavaDoc
52     {
53         private AbstractMessageReceiver receiver;
54         private boolean synchronous = true;
55
56         public AxisServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
57         {
58             this.receiver = receiver;
59             this.synchronous = synchronous;
60         }
61
62         public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
63         {
64             UMOMessageAdapter messageAdapter = receiver.getConnector().getMessageAdapter(args);
65             messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method);
66             
67             // add all custom headers, filter out all mule headers (such as
68
// MULE_SESSION) except
69
// for MULE_USER header. Filter out other headers like "soapMethods" and
70
// MuleProperties.MULE_METHOD_PROPERTY and "soapAction"
71
// and also filter out any http related header
72
messageAdapter.addProperties(AxisCleanAndAddProperties.cleanAndAdd(RequestContext.getEventContext()));
73                                    
74             UMOMessage message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous);
75             
76             if (message != null)
77             {
78                 UMOExceptionPayload wsException = message.getExceptionPayload();
79
80                 if (wsException != null)
81                 {
82                     UMOException umoException = ExceptionHelper.getRootMuleException(wsException.getException());
83                     // if the exception has a cause, then throw only the cause
84
if (umoException.getCause() != null)
85                     {
86                         throw umoException.getCause();
87                     }
88                     else
89                     {
90                         throw umoException;
91                     }
92                 }
93
94                 return message.getPayload();
95             }
96             else
97             {
98                 return null;
99             }
100         }
101     }
102 }
103
Popular Tags