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.handlers.BasicHandler; 62 63 import javax.jms.Destination ; 64 import java.io.ByteArrayOutputStream ; 65 import java.util.HashMap ; 66 67 74 public class JMSSender extends BasicHandler 75 { 76 public JMSSender() 77 { 78 } 79 80 89 public void invoke(MessageContext msgContext) throws AxisFault 90 { 91 try 92 { 93 Object destination = msgContext.getProperty(JMSConstants.DESTINATION); 94 if (destination == null) 95 throw new AxisFault("noDestination"); 96 97 JMSConnector connector = (JMSConnector)msgContext.getProperty(JMSConstants.CONNECTOR); 98 JMSEndpoint endpoint = null; 99 if (destination instanceof String ) 100 endpoint = connector.createEndpoint((String )destination); 101 else 102 endpoint = connector.createEndpoint((Destination )destination); 103 104 ByteArrayOutputStream out = new ByteArrayOutputStream (); 105 msgContext.getRequestMessage().writeTo(out); 106 107 HashMap props = createSendProperties(msgContext); 108 boolean waitForResponse = true; 109 if (msgContext.containsProperty(JMSConstants.WAIT_FOR_RESPONSE)) 110 waitForResponse = 111 ((Boolean )msgContext.getProperty(JMSConstants.WAIT_FOR_RESPONSE)).booleanValue(); 112 if (waitForResponse) 113 { 114 long timeout = (long)msgContext.getTimeout(); 115 byte[] response = endpoint.call(out.toByteArray(), timeout, props); 116 Message msg = new Message(response); 117 msgContext.setResponseMessage(msg); 118 } 119 else 120 { 121 endpoint.send(out.toByteArray(), props); 122 } 123 } 124 catch (Exception e) 125 { 126 throw new AxisFault("failedSend", e); 127 } 128 } 129 130 private HashMap createSendProperties(MessageContext context) 131 { 132 133 if (!context.containsProperty(JMSConstants.PRIORITY) && 134 !context.containsProperty(JMSConstants.DELIVERY_MODE) && 135 !context.containsProperty(JMSConstants.TIME_TO_LIVE)) 136 { 137 return null; 138 } 139 140 HashMap props = new HashMap (); 141 if (context.containsProperty(JMSConstants.PRIORITY)) 142 props.put(JMSConstants.PRIORITY, 143 context.getProperty(JMSConstants.PRIORITY)); 144 if (context.containsProperty(JMSConstants.DELIVERY_MODE)) 145 props.put(JMSConstants.DELIVERY_MODE, 146 context.getProperty(JMSConstants.DELIVERY_MODE)); 147 if (context.containsProperty(JMSConstants.TIME_TO_LIVE)) 148 props.put(JMSConstants.TIME_TO_LIVE, 149 context.getProperty(JMSConstants.TIME_TO_LIVE)); 150 return props; 151 } 152 153 154 } | Popular Tags |