1 57 58 package org.apache.wsif.providers.soap.apacheaxis; 59 60 import java.io.ByteArrayOutputStream ; 61 import java.io.IOException ; 62 import java.io.Serializable ; 63 64 import javax.xml.soap.SOAPException ; 65 66 import org.apache.axis.AxisFault; 67 import org.apache.axis.Message; 68 import org.apache.axis.MessageContext; 69 import org.apache.axis.handlers.BasicHandler; 70 import org.apache.wsif.WSIFCorrelationId; 71 import org.apache.wsif.WSIFCorrelationService; 72 import org.apache.wsif.WSIFException; 73 import org.apache.wsif.logging.Trc; 74 import org.apache.wsif.util.WSIFCorrelationServiceLocator; 75 import org.apache.wsif.util.WSIFProperties; 76 import org.apache.wsif.util.jms.WSIFJMSCorrelationId; 77 import org.apache.wsif.util.jms.WSIFJMSDestination; 78 79 82 public class WSIFJmsSender extends BasicHandler { 83 private static final long serialVersionUID = 1L; 84 private static final long SYNC_TIMEOUT = WSIFProperties.getSyncTimeout(); 85 private static final long ASYNC_TIMEOUT = WSIFProperties.getAsyncTimeout(); 86 private static final String DUMMY_RESPONSE = 87 "<?xml version='1.0' encoding='UTF-8'?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">\n<SOAP-ENV:Body>\n<ns1:addEntryResponse xmlns:ns1=\"http://wsifservice.addressbook/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n</ns1:addEntryResponse>\n\n</SOAP-ENV:Body>\n</SOAP-ENV:Envelope>"; 88 89 public void invoke(MessageContext messageContext) throws AxisFault { 90 Trc.entry(this, messageContext); 91 try { 92 boolean asyncMode = 94 messageContext.isPropertyTrue(WSIFJmsTransport.ASYNCOPERATION); 95 WSIFJMSDestination dest = 96 (WSIFJMSDestination) messageContext.getProperty(WSIFJmsTransport.DESTINATION); 97 98 Long transportSyncTimeoutValue = 99 (Long )messageContext.getProperty(WSIFJmsTransport.SYNC_TIMEOUT); 100 long syncTimeout = 101 transportSyncTimeoutValue==null 102 ? SYNC_TIMEOUT 103 : transportSyncTimeoutValue.longValue(); 104 105 Message message = messageContext.getRequestMessage(); 106 107 message.getContentType(messageContext.getSOAPConstants()); 111 112 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 113 message.writeTo(baos); 114 String contents = baos.toString(); 115 116 if (asyncMode) { 117 performAsyncSend(messageContext, dest, contents); 118 } else { 119 String id = dest.send(contents, null); 120 String response = dest.receiveString(id, syncTimeout); 121 Message responseMessage = new Message(response); 122 messageContext.setResponseMessage(responseMessage); 123 } 124 } catch (IOException ioe) { 125 Trc.exception(ioe); 126 throw new AxisFault(ioe.toString()); 127 } catch (SOAPException se) { 128 Trc.exception(se); 129 throw new AxisFault(se.toString()); } 130 Trc.exit(); 131 } 132 133 public void undo(MessageContext messageContext) { 134 Trc.entry(this, messageContext); 135 Trc.exit(); 136 } 137 138 147 private void performAsyncSend( 148 MessageContext messageContext, 149 WSIFJMSDestination dest, 150 String data) 151 throws WSIFException { 152 String msgID; 153 154 WSIFOperation_ApacheAxis wsifOp = 155 (WSIFOperation_ApacheAxis) messageContext.getProperty( 156 WSIFJmsTransport.WSIFOPERATION); 157 158 WSIFCorrelationId cid; 159 160 if ( wsifOp.getResponseHandler() == null ) { 162 msgID = dest.send( data ); 163 cid = new WSIFJMSCorrelationId( msgID ); 164 } else { 165 Long transportAsyncTimeoutValue = 166 (Long )messageContext.getProperty(WSIFJmsTransport.ASYNC_TIMEOUT); 167 long asyncTimeout = 168 transportAsyncTimeoutValue==null 169 ? ASYNC_TIMEOUT 170 : transportAsyncTimeoutValue.longValue(); 171 WSIFCorrelationService correlator = 172 WSIFCorrelationServiceLocator.getCorrelationService(); 173 synchronized( correlator ) { 174 msgID = dest.send( data ); 175 cid = new WSIFJMSCorrelationId( msgID ); 176 if ( correlator != null ) { 177 correlator.put( cid, (Serializable )wsifOp, asyncTimeout ); 178 } 179 } 180 } 181 182 183 wsifOp.setAsyncRequestID(new WSIFJMSCorrelationId(msgID)); 185 186 Message responseMessage = new Message(DUMMY_RESPONSE); 188 messageContext.setResponseMessage(responseMessage); 189 } 190 } | Popular Tags |