1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.ejb.AbstractServer; 32 import com.caucho.ejb.message.MessageServer; 33 import com.caucho.ejb.protocol.Skeleton; 34 import com.caucho.hessian.io.HessianInput; 35 import com.caucho.hessian.io.HessianOutput; 36 import com.caucho.hessian.io.HessianSerializerInput; 37 import com.caucho.log.Log; 38 import com.caucho.services.message.MessageSender; 39 import com.caucho.util.CharBuffer; 40 41 import javax.jms.Connection ; 42 import javax.jms.Destination ; 43 import javax.jms.Message ; 44 import javax.jms.MessageProducer ; 45 import javax.jms.Session ; 46 import java.io.IOException ; 47 import java.io.InputStream ; 48 import java.io.OutputStream ; 49 import java.io.Serializable ; 50 import java.util.HashMap ; 51 import java.util.logging.Level ; 52 import java.util.logging.Logger ; 53 54 62 public class MessageSkeleton extends Skeleton { 63 protected static Logger log = Log.open(MessageSkeleton.class); 64 65 protected MessageServer _server; 66 protected Connection _connection; 67 68 protected Destination _destination; 69 70 protected Session _session; 71 protected MessageProducer _producer; 72 73 MessageSkeleton(MessageServer server) 74 throws javax.jms.JMSException 75 { 76 _server = server; 77 _destination = server.getDestination(); 78 _connection = server.getJMSConnection(); 79 _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 80 _producer = _session.createProducer(_destination); 81 } 82 83 86 void _setServer(AbstractServer server) 87 { 88 _server = (MessageServer) server; 89 } 90 91 94 protected void _setObject(Object obj) 95 { 96 } 97 98 108 public void _service(InputStream rawIs, OutputStream rawOs) 109 throws Exception 110 { 111 HessianInput in = new HessianSerializerInput(rawIs); 112 HessianOutput out = new HessianWriter(rawOs); 113 114 try { 115 in.startCall(); 116 117 String method = in.getMethod(); 118 119 if (! "send".equals(method)) 120 throw new IOException ("no such method: " + method); 121 122 HashMap headers = (HashMap ) in.readObject(); 123 Object data = in.readObject(); 124 125 in.completeCall(); 126 127 if (_destination instanceof MessageSender) { 128 ((MessageSender) _destination).send(headers, data); 129 } 130 else { 131 Message message = null; 132 133 if (data instanceof String ) { 134 message = _session.createTextMessage((String ) data); 135 } 136 else 137 message = _session.createObjectMessage((Serializable ) data); 138 139 _producer.send(message); 140 } 141 142 out.startReply(); 143 out.writeNull(); 144 out.completeReply(); 145 } catch (Exception e) { 146 log.log(Level.FINE, e.toString(), e); 147 148 out.startReply(); 149 out.writeFault("SystemFault", String.valueOf(e), e); 150 out.completeReply(); 151 } 152 } 153 154 protected void _execute(CharBuffer method, 155 HessianInput in, 156 HessianOutput out) 157 throws Exception 158 { 159 } 160 } 161 162 163 | Popular Tags |