KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > glue > GlueServiceProxy


1 /*
2  * $Id: GlueServiceProxy.java 3798 2006-11-04 04:07:14Z aperepel $
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.glue;
12
13 import electric.service.IService;
14
15 import org.mule.config.MuleProperties;
16 import org.mule.impl.MuleMessage;
17 import org.mule.providers.AbstractMessageReceiver;
18 import org.mule.providers.soap.ServiceProxy;
19 import org.mule.umo.UMOMessage;
20 import org.mule.umo.provider.UMOMessageAdapter;
21
22 import java.lang.reflect.InvocationHandler JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24 import java.lang.reflect.Proxy JavaDoc;
25
26 /**
27  * <code>ServiceProxy</code> is a proxy that wraps a soap endpointUri to look like
28  * a Web service. Also provides helper methods for building and describing web
29  * service interfaces in Mule.
30  *
31  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
32  * @version $Revision: 3798 $
33  */

34
35 public class GlueServiceProxy extends ServiceProxy
36 {
37     public static Object JavaDoc createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class JavaDoc[] classes)
38     {
39         final ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
40         return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous));
41     }
42
43     public static InvocationHandler JavaDoc createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
44     {
45         return new GlueServiceHandler(receiver, synchronous);
46     }
47
48     private static class GlueServiceHandler implements InvocationHandler JavaDoc
49     {
50         private AbstractMessageReceiver receiver;
51         private boolean synchronous = true;
52
53         public GlueServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
54         {
55             this.receiver = receiver;
56             this.synchronous = synchronous;
57         }
58
59         public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
60         {
61             GlueMessageAdapter.GlueMessageHolder holder;
62             if (args.length == 1)
63             {
64                 holder = new GlueMessageAdapter.GlueMessageHolder(args[0], (IService)proxy);
65             }
66             else
67             {
68                 holder = new GlueMessageAdapter.GlueMessageHolder(args, (IService)proxy);
69             }
70             UMOMessageAdapter messageAdapter = receiver.getConnector().getMessageAdapter(holder);
71             messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method);
72
73             UMOMessage message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous);
74
75             if (message != null)
76             {
77                 if (message.getExceptionPayload() != null)
78                 {
79                     throw message.getExceptionPayload().getException();
80                 }
81                 return message.getPayload();
82             }
83             else
84             {
85                 return null;
86             }
87         }
88     }
89 }
90
Popular Tags