1 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 ; 23 import java.lang.reflect.Method ; 24 import java.lang.reflect.Proxy ; 25 26 34 35 public class GlueServiceProxy extends ServiceProxy 36 { 37 public static Object createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class [] classes) 38 { 39 final ClassLoader cl = Thread.currentThread().getContextClassLoader(); 40 return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous)); 41 } 42 43 public static InvocationHandler createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous) 44 { 45 return new GlueServiceHandler(receiver, synchronous); 46 } 47 48 private static class GlueServiceHandler implements InvocationHandler 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 invoke(Object proxy, Method method, Object [] args) throws Throwable 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 |