1 16 package org.apache.axis2.transport.tcp; 17 18 import org.apache.axis2.addressing.EndpointReference; 19 import org.apache.axis2.context.MessageContext; 20 import org.apache.axis2.engine.AxisFault; 21 import org.apache.axis2.transport.AbstractTransportSender; 22 import org.apache.axis2.util.URL; 23 24 import java.io.ByteArrayOutputStream ; 25 import java.io.IOException ; 26 import java.io.OutputStream ; 27 import java.io.Writer ; 28 import java.net.InetSocketAddress ; 29 import java.net.MalformedURLException ; 30 import java.net.Socket ; 31 import java.net.SocketAddress ; 32 33 36 public class TCPTransportSender extends AbstractTransportSender { 37 40 protected Writer out; 41 42 45 private Socket socket; 46 private ByteArrayOutputStream outputStream; 47 48 56 protected void writeTransportHeaders( 57 Writer out, 58 URL url, 59 MessageContext msgContext, 60 int contentLength) 61 throws IOException { 62 } 64 65 public void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,OutputStream out) { 66 } 67 68 public void finalizeSendWithToAddress(MessageContext msgContext,OutputStream out) throws AxisFault { 69 try { 70 socket.shutdownOutput(); 71 msgContext.setProperty( 72 MessageContext.TRANSPORT_IN,socket.getInputStream()); 73 } catch (IOException e) { 74 throw new AxisFault(e); 75 } 76 } 77 78 protected OutputStream openTheConnection(EndpointReference toURL,MessageContext msgContext) throws AxisFault { 79 if (toURL != null) { 80 try { 81 URL url = new URL(toURL.getAddress()); 82 SocketAddress add = 83 new InetSocketAddress (url.getHost(), url.getPort() == -1 ? 80 : url.getPort()); 84 socket = new Socket (); 85 socket.connect(add); 86 return socket.getOutputStream(); 87 } catch (MalformedURLException e) { 88 throw new AxisFault(e.getMessage(), e); 89 } catch (IOException e) { 90 throw new AxisFault(e.getMessage(), e); 91 } 92 } else { 93 throw new AxisFault("to EPR must be specified"); 94 } 95 } 96 97 public OutputStream startSendWithOutputStreamFromIncomingConnection( 98 MessageContext msgContext, 99 OutputStream out) 100 throws AxisFault { 101 return out; 102 } 103 104 public OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out) { 105 return out; 106 } 107 108 public void cleanUp(MessageContext msgContext) throws AxisFault { 109 try { 110 if (socket != null) { 111 socket.close(); 112 socket = null; 113 } 114 115 } catch (IOException e) { 116 } 117 118 } 119 120 } 121 | Popular Tags |