1 16 17 package org.apache.axis.transport.jms; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Message; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.components.logger.LogFactory; 23 import org.apache.axis.server.AxisServer; 24 import org.apache.axis.utils.Messages; 25 import org.apache.commons.logging.Log; 26 27 import javax.jms.BytesMessage ; 28 import javax.jms.Destination ; 29 import java.io.ByteArrayInputStream ; 30 import java.io.ByteArrayOutputStream ; 31 import java.io.InputStream ; 32 33 42 public class SimpleJMSWorker implements Runnable 43 { 44 protected static Log log = 45 LogFactory.getLog(SimpleJMSWorker.class.getName()); 46 47 SimpleJMSListener listener; 48 BytesMessage message; 49 50 public SimpleJMSWorker(SimpleJMSListener listener, BytesMessage message) 51 { 52 this.listener = listener; 53 this.message = message; 54 } 55 56 59 public void run() 60 { 61 InputStream in = null; 62 try 63 { 64 byte[] buffer = new byte[8 * 1024]; 66 ByteArrayOutputStream out = new ByteArrayOutputStream (); 67 for(int bytesRead = message.readBytes(buffer); 68 bytesRead != -1; bytesRead = message.readBytes(buffer)) 69 { 70 out.write(buffer, 0, bytesRead); 71 } 72 in = new ByteArrayInputStream (out.toByteArray()); 73 } 74 catch(Exception e) 75 { 76 log.error(Messages.getMessage("exception00"), e); 77 e.printStackTrace(); 78 return; 79 } 80 81 AxisServer server = SimpleJMSListener.getAxisServer(); 83 84 String contentType = null; 87 try 88 { 89 contentType = message.getStringProperty("contentType"); 90 } 91 catch(Exception e) 92 { 93 e.printStackTrace(); 94 } 95 96 Message msg = null; 97 if(contentType != null && !contentType.trim().equals("")) 98 { 99 msg = new Message(in, true, contentType, null); 100 } 101 else 102 { 103 msg = new Message(in); 104 } 105 106 MessageContext msgContext = new MessageContext(server); 107 msgContext.setRequestMessage( msg ); 108 try 109 { 110 server.invoke( msgContext ); 111 msg = msgContext.getResponseMessage(); 112 } 113 catch (AxisFault af) 114 { 115 msg = new Message(af); 116 msg.setMessageContext(msgContext); 117 } 118 catch (Exception e) 119 { 120 msg = new Message(new AxisFault(e.toString())); 121 msg.setMessageContext(msgContext); 122 } 123 124 try 125 { 126 Destination destination = message.getJMSReplyTo(); 128 if(destination == null) 129 return; 130 JMSEndpoint replyTo = listener.getConnector().createEndpoint(destination); 131 ByteArrayOutputStream out = new ByteArrayOutputStream (); 132 msg.writeTo(out); 133 replyTo.send(out.toByteArray()); 134 } 135 catch(Exception e) 136 { 137 e.printStackTrace(); 138 } 139 140 if (msgContext.getProperty(MessageContext.QUIT_REQUESTED) != null) 141 try {listener.shutdown();} catch (Exception e) {} 143 } 144 } 145 | Popular Tags |