1 10 11 package org.mule.extras.spring.remoting; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.ObjectInputStream ; 15 16 import org.mule.transformers.AbstractTransformer; 17 import org.mule.umo.transformer.TransformerException; 18 import org.springframework.remoting.support.RemoteInvocation; 19 20 public class ObjectToRemoteInvocationTransformer extends AbstractTransformer 21 { 22 private static final long serialVersionUID = -7067819657247418549L; 23 24 public ObjectToRemoteInvocationTransformer() 25 { 26 super(); 27 this.registerSourceType(RemoteInvocation.class); 28 this.registerSourceType(byte[].class); 29 this.setReturnClass(RemoteInvocation.class); 30 } 31 32 protected Object doTransform(Object src, String encoding) throws TransformerException 33 { 34 if (logger.isDebugEnabled()) 35 { 36 logger.debug("HttpToRemoteInvocation.doTransform(" + src + ")"); 37 } 38 if (src instanceof RemoteInvocation) 39 { 40 return src; 41 } 42 43 try 44 { 45 byte[] data = (byte[])src; 46 ByteArrayInputStream bais = new ByteArrayInputStream (data); 47 ObjectInputStream ois = new ObjectInputStream (bais); 48 Object o = ois.readObject(); 49 RemoteInvocation ri = (RemoteInvocation)o; 50 if (logger.isDebugEnabled()) 51 { 52 logger.debug("request to execute " + ri.getMethodName()); 53 for (int i = 0; i < ri.getArguments().length; i++) 54 { 55 Object a = ri.getArguments()[i]; 56 logger.debug("with argument (" + a.toString() + ")"); 57 } 58 } 59 return ri; 60 } 61 catch (Exception e) 62 { 63 throw new TransformerException(this, e); 64 } 65 } 66 } 67 | Popular Tags |