1 16 17 package samples.transport.tcp; 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.handlers.BasicHandler; 24 import org.apache.commons.logging.Log; 25 26 import java.io.BufferedInputStream ; 27 import java.io.OutputStream ; 28 import java.net.Socket ; 29 30 36 public class TCPSender extends BasicHandler { 37 static Log log = 38 LogFactory.getLog(TCPSender.class.getName()); 39 40 public void invoke(MessageContext msgContext) throws AxisFault { 41 log.info( "Enter: TCPSender::invoke" ); 42 43 44 45 String targetURL = null ; 46 Message outMsg = null ; 47 String reqEnv = null ; 48 49 targetURL = msgContext.getStrProp( MessageContext.TRANS_URL); 50 try { 51 String host = msgContext.getStrProp(TCPTransport.HOST); 52 int port = Integer.parseInt(msgContext.getStrProp(TCPTransport.PORT)); 53 byte[] buf = new byte[4097]; 54 int rc = 0 ; 55 56 Socket sock = null ; 57 58 sock = new Socket ( host, port ); 59 log.info( "Created an insecure HTTP connection"); 60 61 reqEnv = (String ) msgContext.getRequestMessage().getSOAPPartAsString(); 62 63 65 BufferedInputStream inp = new BufferedInputStream (sock.getInputStream()); 66 OutputStream out = sock.getOutputStream(); 67 68 byte[] bytes = reqEnv.getBytes(); 69 String length = "" + bytes.length + "\r\n"; 70 out.write(length.getBytes()); 71 out.write( bytes ); 72 out.flush(); 73 74 log.debug( "XML sent:" ); 75 log.debug( "---------------------------------------------------"); 76 log.debug( reqEnv ); 77 78 if ( false ) { 79 byte b; 83 while ( (b = (byte) inp.read()) != -1 ) 84 System.err.print((char)b); 85 System.err.println(""); 86 } 87 88 outMsg = new Message( inp ); 89 if (log.isDebugEnabled()) { 90 log.debug( "\nNo Content-Length" ); 91 log.debug( "\nXML received:" ); 92 log.debug( "-----------------------------------------------"); 93 log.debug( (String ) outMsg.getSOAPPartAsString() ); 94 } 95 96 msgContext.setResponseMessage( outMsg ); 97 } 98 catch( Exception e ) { 99 log.error( e ); 100 e.printStackTrace(); 101 throw AxisFault.makeFault(e); 102 } 103 log.info( "Exit: TCPSender::invoke" ); 104 } 105 }; 106 | Popular Tags |