1 55 56 package org.jboss.axis.transport.jms; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Message; 60 import org.jboss.axis.MessageContext; 61 import org.jboss.axis.server.AxisServer; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.logging.Logger; 64 65 import javax.jms.BytesMessage ; 66 import javax.jms.Destination ; 67 import java.io.ByteArrayInputStream ; 68 import java.io.ByteArrayOutputStream ; 69 import java.io.InputStream ; 70 71 80 public class SimpleJMSWorker implements Runnable 81 { 82 protected static Logger log = Logger.getLogger(SimpleJMSWorker.class); 83 84 SimpleJMSListener listener; 85 BytesMessage message; 86 87 public SimpleJMSWorker(SimpleJMSListener listener, BytesMessage message) 88 { 89 this.listener = listener; 90 this.message = message; 91 } 92 93 96 public void run() 97 { 98 InputStream in = null; 99 try 100 { 101 byte[] buffer = new byte[8 * 1024]; 103 ByteArrayOutputStream out = new ByteArrayOutputStream (); 104 for (int bytesRead = message.readBytes(buffer); 105 bytesRead != -1; bytesRead = message.readBytes(buffer)) 106 { 107 out.write(buffer, 0, bytesRead); 108 } 109 in = new ByteArrayInputStream (out.toByteArray()); 110 } 111 catch (Exception e) 112 { 113 log.error(Messages.getMessage("exception00"), e); 114 e.printStackTrace(); 115 return; 116 } 117 118 AxisServer server = listener.getAxisServer(); 120 Message msg = new Message(in); 121 MessageContext msgContext = new MessageContext(server); 122 msgContext.setRequestMessage(msg); 123 try 124 { 125 server.invoke(msgContext); 126 msg = msgContext.getResponseMessage(); 127 } 128 catch (AxisFault af) 129 { 130 msg = new Message(af); 131 msg.setMessageContext(msgContext); 132 } 133 catch (Exception e) 134 { 135 msg = new Message(new AxisFault(e.toString())); 136 msg.setMessageContext(msgContext); 137 } 138 139 try 140 { 141 Destination destination = message.getJMSReplyTo(); 143 if (destination == null) 144 return; 145 JMSEndpoint replyTo = listener.getConnector().createEndpoint(destination); 146 ByteArrayOutputStream out = new ByteArrayOutputStream (); 147 msg.writeTo(out); 148 replyTo.send(out.toByteArray()); 149 } 150 catch (Exception e) 151 { 152 e.printStackTrace(); 153 } 154 155 if (msgContext.getProperty(msgContext.QUIT_REQUESTED) != null) 156 try 158 { 159 listener.shutdown(); 160 } 161 catch (Exception e) 162 { 163 } 164 } 165 } 166 | Popular Tags |