1 28 29 package com.caucho.ejb.burlap; 30 31 import com.caucho.burlap.io.BurlapInput; 32 import com.caucho.burlap.io.BurlapOutput; 33 import com.caucho.ejb.AbstractServer; 34 import com.caucho.ejb.message.MessageServer; 35 import com.caucho.ejb.protocol.Skeleton; 36 import com.caucho.log.Log; 37 import com.caucho.services.message.MessageSender; 38 import com.caucho.util.CharBuffer; 39 40 import javax.jms.Connection ; 41 import javax.jms.Destination ; 42 import javax.jms.JMSException ; 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 72 protected MessageProducer _sender; 73 74 MessageSkeleton(MessageServer server) 75 throws JMSException 76 { 77 _server = server; 78 _destination = server.getDestination(); 79 _connection = server.getJMSConnection(); 80 81 _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 82 _sender = _session.createProducer(server.getDestination()); 83 } 84 85 88 void _setServer(AbstractServer server) 89 { 90 _server = (MessageServer) server; 91 } 92 93 96 protected void _setObject(Object obj) 97 { 98 } 99 100 110 public void _service(InputStream rawIs, OutputStream rawOs) 111 throws Exception 112 { 113 BurlapInput in = new BurlapInput(rawIs); 114 BurlapOutput out = new BurlapWriter(rawOs); 115 116 try { 117 in.startCall(); 118 119 String method = in.getMethod(); 120 121 if (! "send".equals(method)) 122 throw new IOException ("no such method: " + method); 123 124 HashMap headers = (HashMap ) in.readObject(); 125 Object data = in.readObject(); 126 127 in.completeCall(); 128 129 if (_destination instanceof MessageSender) { 130 ((MessageSender) _destination).send(headers, data); 131 } 132 else { 133 Message message = null; 134 135 if (data instanceof String ) { 136 message = _session.createTextMessage((String ) data); 137 } 138 else 139 message = _session.createObjectMessage((Serializable ) data); 140 141 _sender.send(message); 142 } 143 144 out.startReply(); 145 out.writeNull(); 146 out.completeReply(); 147 } catch (Exception e) { 148 log.log(Level.WARNING, e.toString(), e); 149 150 out.startReply(); 151 out.writeFault("SystemFault", String.valueOf(e), e); 152 out.completeReply(); 153 } 154 } 155 156 protected void _execute(CharBuffer method, 157 BurlapInput in, 158 BurlapOutput out) 159 throws Exception 160 { 161 } 162 } 163 164 165 | Popular Tags |