1 18 package org.apache.axis2.transport.http; 19 20 import org.apache.axis2.Constants; 21 import org.apache.axis2.context.ConfigurationContext; 22 import org.apache.axis2.context.MessageContext; 23 import org.apache.axis2.description.TransportOutDescription; 24 import org.apache.axis2.engine.AxisEngine; 25 import org.apache.axis2.engine.AxisFault; 26 import org.apache.axis2.util.threadpool.AxisWorker; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import javax.xml.namespace.QName ; 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.net.Socket ; 34 import java.util.Map ; 35 36 public class HTTPWorker implements AxisWorker { 37 protected Log log = LogFactory.getLog(getClass().getName()); 38 private ConfigurationContext configurationContext; 39 private Socket socket; 40 41 public HTTPWorker(ConfigurationContext configurationContext, Socket socket) { 42 this.configurationContext = configurationContext; 43 this.socket = socket; 44 } 45 46 public void doWork() { 47 MessageContext msgContext = null; 48 SimpleHTTPOutputStream out = null; 49 try { 50 if (socket != null) { 51 if (configurationContext == null) { 52 throw new AxisFault("Engine Must be null"); 53 } 54 55 InputStream inStream = socket.getInputStream(); 56 57 TransportOutDescription transportOut = 58 configurationContext.getAxisConfiguration().getTransportOut( 59 new QName (Constants.TRANSPORT_HTTP)); 60 msgContext = 61 new MessageContext( 62 configurationContext, 63 configurationContext.getAxisConfiguration().getTransportIn( 64 new QName (Constants.TRANSPORT_HTTP)), 65 transportOut); 66 msgContext.setServerSide(true); 67 68 HTTPTransportReceiver reciver = new HTTPTransportReceiver(); 70 Map map = reciver.parseTheHeaders(inStream, true); 71 72 74 String transferEncoding = (String ) map.get(HTTPConstants.HEADER_TRANSFER_ENCODING); 75 if (transferEncoding != null 76 && HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding)) { 77 inStream = new ChunkedInputStream(inStream); 78 out = new SimpleHTTPOutputStream(socket.getOutputStream(), true); 79 } else { 80 out = new SimpleHTTPOutputStream(socket.getOutputStream(), false); 81 } 82 msgContext.setProperty(MessageContext.TRANSPORT_OUT, out); 83 84 msgContext.setProperty( 86 HTTPConstants.HTTPOutTransportInfo, 87 new SimpleHTTPOutTransportInfo(out)); 88 89 if (HTTPConstants.HEADER_GET.equals(map.get(HTTPConstants.HTTP_REQ_TYPE))) { 90 boolean processed = 92 HTTPTransportUtils.processHTTPGetRequest( 93 msgContext, 94 inStream, 95 out, 96 (String ) map.get(HTTPConstants.HEADER_CONTENT_TYPE), 97 (String ) map.get(HTTPConstants.HEADER_SOAP_ACTION), 98 (String ) map.get(HTTPConstants.REQUEST_URI), 99 configurationContext, 100 HTTPTransportReceiver.getGetRequestParameters( 101 (String ) map.get(HTTPConstants.REQUEST_URI))); 102 103 if (!processed) { 104 out.write( 105 HTTPTransportReceiver.getServicesHTML(configurationContext).getBytes()); 106 out.flush(); 107 } 108 } else { 109 HTTPTransportUtils.processHTTPPostRequest( 111 msgContext, 112 inStream, 113 out, 114 (String ) map.get(HTTPConstants.HEADER_CONTENT_TYPE), 115 (String ) map.get(HTTPConstants.HEADER_SOAP_ACTION), 116 (String ) map.get(HTTPConstants.REQUEST_URI), 117 configurationContext); 118 } 119 120 out.finalize(); 121 } 122 } catch (Throwable e) { 123 try { 124 AxisEngine engine = new AxisEngine(configurationContext); 125 if (msgContext != null) { 126 if (out == null) { 127 out = new SimpleHTTPOutputStream(socket.getOutputStream(), false); 128 } 129 msgContext.setProperty(MessageContext.TRANSPORT_OUT, out); 130 engine.handleFault(msgContext, e); 131 } 132 } catch (Exception e1) { 133 log.error(e1); 134 e1.printStackTrace(); 135 } 136 e.printStackTrace(); 137 } finally { 138 if (socket != null) { 139 try { 140 this.socket.close(); 141 } catch (IOException e1) { 142 log.error(e1); 143 } 144 } 145 } 146 147 } 148 149 } 150 | Popular Tags |