1 22 package org.jboss.invocation.unified.marshall; 23 24 import org.jboss.invocation.Invocation; 25 import org.jboss.invocation.MarshalledInvocation; 26 import org.jboss.logging.Logger; 27 import org.jboss.remoting.InvocationRequest; 28 import org.jboss.remoting.marshal.serializable.SerializableMarshaller; 29 import org.jboss.remoting.marshal.Marshaller; 30 import org.jboss.remoting.marshal.http.HTTPMarshaller; 31 import org.jboss.tm.TransactionPropagationContextFactory; 32 import org.jboss.tm.TransactionPropagationContextUtil; 33 34 import javax.transaction.SystemException ; 35 import java.io.IOException ; 36 import java.io.OutputStream ; 37 38 45 public class HTTPInvocationMarshaller extends HTTPMarshaller 46 { 47 public final static String DATATYPE = "invocationhttp"; 48 49 private static final Logger log = Logger.getLogger(HTTPInvocationMarshaller.class); 50 51 63 public void write(Object dataObject, OutputStream output) throws IOException 64 { 65 if(dataObject instanceof InvocationRequest) 66 { 67 InvocationRequest remoteInv = (InvocationRequest) dataObject; 68 69 if(remoteInv.getParameter() instanceof Invocation) 70 { 71 Invocation inv = (Invocation) remoteInv.getParameter(); 72 73 MarshalledInvocation marshInv = new MarshalledInvocation(inv); 74 75 if(inv != null) 76 { 77 81 try 82 { 83 marshInv.setTransactionPropagationContext(getTransactionPropagationContext()); 84 } 85 catch(SystemException e) 86 { 87 log.error("Error setting transaction propagation context.", e); 88 throw new IOException ("Error setting transaction context. Message: " + e.getMessage()); 89 } 90 91 remoteInv.setParameter(marshInv); 93 } 94 else 95 { 96 log.error("Attempting to marshall Invocation but is null. Can not proceed."); 98 throw new IOException ("Can not process data object due to the InvocationRequest's parameter being null."); 99 } 100 101 } 102 103 super.write(dataObject, output); 104 105 } 106 else { 108 super.write(dataObject, output); 109 } 110 } 111 112 public Object getTransactionPropagationContext() 113 throws SystemException 114 { 115 TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide(); 116 return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext(); 117 } 118 119 public Marshaller cloneMarshaller() throws CloneNotSupportedException 120 { 121 return new HTTPInvocationMarshaller(); 122 } 123 124 } | Popular Tags |