You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/16 18:18:08 UTC

svn commit: r357187 [15/25] - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./ addressing/ client/ client/async/ context/ deployment/ deployment/listener/ deployment/repository/util/ deployment/scheduler/ deployment/util/ descript...

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.http;
 
@@ -50,41 +51,121 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.PushbackInputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
-import java.io.PushbackInputStream;
-import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 
 public class HTTPTransportUtils {
+    private static final int BOM_SIZE = 4;
+
+    public static boolean checkEnvelopeForOptimise(SOAPEnvelope envelope) {
+        return isOptimised(envelope);
+    }
+
+    public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl, Map map) {
+        String[] values = Utils.parseRequestURLForServiceAndOperation(requestUrl);
+
+        if ((values[1] != null) && (values[0] != null)) {
+            String operation = values[1];
+            SOAPFactory soapFactory = new SOAP11Factory();
+            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
+            OMNamespace omNs = soapFactory.createOMNamespace(values[0], "services");
+            OMNamespace defualtNs = new OMNamespaceImpl("", null);
+            OMElement opElement = soapFactory.createOMElement(operation, omNs);
+            Iterator it = map.keySet().iterator();
+
+            while (it.hasNext()) {
+                String name = (String) it.next();
+                String value = (String) map.get(name);
+                OMElement omEle = soapFactory.createOMElement(name, defualtNs);
+
+                omEle.setText(value);
+                opElement.addChild(omEle);
+            }
+
+            envelope.getBody().addChild(opElement);
+
+            return envelope;
+        } else {
+            return null;
+        }
+    }
+
+    public static boolean doWriteMTOM(MessageContext msgContext) {
+        boolean enableMTOM = false;
+
+        if (msgContext.getParameter(Constants.Configuration.ENABLE_MTOM) != null) {
+            enableMTOM = Constants.VALUE_TRUE.equals(
+                    msgContext.getParameter(Constants.Configuration.ENABLE_MTOM).getValue());
+        } else if (msgContext.getProperty(Constants.Configuration.ENABLE_MTOM) != null) {
+            enableMTOM = Constants.VALUE_TRUE.equals(
+                    msgContext.getProperty(Constants.Configuration.ENABLE_MTOM));
+        }
+
+        boolean forceMIME =
+                Constants.VALUE_TRUE.equals(msgContext.getProperty(Constants.Configuration.FORCE_MIME));
+
+        if (forceMIME) {
+            return true;
+        }
+
+        boolean envelopeContainsOptimise =
+                HTTPTransportUtils.checkEnvelopeForOptimise(msgContext.getEnvelope());
+
+        return enableMTOM && envelopeContainsOptimise;
+    }
+
+    public static boolean processHTTPGetRequest(MessageContext msgContext, InputStream in,
+                                                OutputStream out, String contentType, String soapAction, String requestURI,
+                                                ConfigurationContext configurationContext, Map requestParameters)
+            throws AxisFault {
+        if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
+            soapAction = soapAction.substring(1, soapAction.length() - 1);
+        }
+
+        msgContext.setWSAAction(soapAction);
+        msgContext.setSoapAction(soapAction);
+        msgContext.setTo(new EndpointReference(requestURI));
+        msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+        msgContext.setServerSide(true);
+
+        SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI,
+                requestParameters);
+
+        if (envelope == null) {
+            return false;
+        } else {
+            msgContext.setDoingREST(true);
+            msgContext.setEnvelope(envelope);
+
+            AxisEngine engine = new AxisEngine(configurationContext);
 
-    public static void processHTTPPostRequest(
-            MessageContext msgContext,
-            InputStream in,
-            OutputStream out,
-            String contentType,
-            String soapActionHeader,
-            String requestURI
-    )
+            engine.receive(msgContext);
+
+            return true;
+        }
+    }
+
+    public static void processHTTPPostRequest(MessageContext msgContext, InputStream in,
+                                              OutputStream out, String contentType, String soapActionHeader, String requestURI)
             throws AxisFault {
         boolean soap11 = false;
+
         try {
 
-            //remove the starting and trailing " from the SOAP Action
-            if (soapActionHeader != null
-                    && soapActionHeader.startsWith("\"")
+            // remove the starting and trailing " from the SOAP Action
+            if ((soapActionHeader != null) && soapActionHeader.startsWith("\"")
                     && soapActionHeader.endsWith("\"")) {
-
-                soapActionHeader =
-                        soapActionHeader.substring(
-                                1,
-                                soapActionHeader.length() - 1);
+                soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
             }
-            //fill up the Message Contexts
+
+            // fill up the Message Contexts
             msgContext.setWSAAction(soapActionHeader);
             msgContext.setSoapAction(soapActionHeader);
             msgContext.setTo(new EndpointReference(requestURI));
@@ -93,121 +174,108 @@
 
             SOAPEnvelope envelope = null;
             StAXBuilder builder = null;
+
             if (contentType != null) {
-                if (contentType
-                        .indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)
-                        > -1) {
-                    //It is MTOM
+                if (contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
+
+                    // It is MTOM
                     builder = selectBuilderForMIME(msgContext, in, contentType);
                     envelope = (SOAPEnvelope) builder.getDocumentElement();
                 } else {
                     Reader reader = new InputStreamReader(in);
-
                     XMLStreamReader xmlreader;
-                    //Figure out the char set encoding and create the reader
 
-                    //If charset is not specified
+                    // Figure out the char set encoding and create the reader
+
+                    // If charset is not specified
                     if (TransportUtils.getCharSetEncoding(contentType) == null) {
-                        xmlreader =
-                                XMLInputFactory
-                                        .newInstance()
-                                        .createXMLStreamReader(
-                                                in,
-                                                MessageContext.DEFAULT_CHAR_SET_ENCODING);
-                        //Set the encoding scheme in the message context
-                        msgContext.setProperty(
-                                MessageContext.CHARACTER_SET_ENCODING,
+                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
+                                MessageContext.DEFAULT_CHAR_SET_ENCODING);
+
+                        // Set the encoding scheme in the message context
+                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
                                 MessageContext.DEFAULT_CHAR_SET_ENCODING);
                     } else {
-                        //get the type of char encoding
+
+                        // get the type of char encoding
                         String charSetEnc = TransportUtils.getCharSetEncoding(contentType);
-                        xmlreader =
-                                XMLInputFactory
-                                        .newInstance()
-                                        .createXMLStreamReader(
-                                                in,
-                                                charSetEnc);
-
-                        //Setting the value in msgCtx
-                        msgContext.setProperty(
-                                MessageContext.CHARACTER_SET_ENCODING,
+
+                        xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,
                                 charSetEnc);
 
+                        // Setting the value in msgCtx
+                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEnc);
                     }
-                    if (contentType
-                            .indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
-                            > -1) {
+
+                    if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                         soap11 = false;
-                        //it is SOAP 1.2
+
+                        // it is SOAP 1.2
                         builder =
-                                new StAXSOAPModelBuilder(
-                                        xmlreader,
+                                new StAXSOAPModelBuilder(xmlreader,
                                         SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
                         envelope = (SOAPEnvelope) builder.getDocumentElement();
-                    } else if (
-                            contentType.indexOf(
-                                    SOAP11Constants.SOAP_11_CONTENT_TYPE)
-                                    > -1) {
+                    } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
                         soap11 = true;
-                        //it is SOAP 1.1
 
-//                            msgContext.getProperty(
-//                                Constants.Configuration.ENABLE_REST);
+                        // it is SOAP 1.1
+
+//                      msgContext.getProperty(
+//                          Constants.Configuration.ENABLE_REST);
+
                         /**
                          * Configuration via Deployment
                          */
+                        Parameter enable =
+                                msgContext.getParameter(Constants.Configuration.ENABLE_REST);
 
-                        Parameter enable = msgContext.getParameter(Constants.Configuration.ENABLE_REST);
+                        if (((soapActionHeader == null) || (soapActionHeader.length() == 0))
+                                && (enable != null)) {
+                            if (Constants.VALUE_TRUE.equals(enable.getValue())) {
 
-                        if ((soapActionHeader == null
-                                || soapActionHeader.length() == 0)
-                                && enable != null) {
-                            if (Constants.VALUE_TRUE
-                                    .equals(enable.getValue())) {
-                                //If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
-                                //the SOAP Action is absent it is rest !!
+                                // If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
+                                // the SOAP Action is absent it is rest !!
                                 msgContext.setDoingREST(true);
 
                                 SOAPFactory soapFactory = new SOAP11Factory();
+
                                 builder = new StAXOMBuilder(xmlreader);
                                 builder.setOmbuilderFactory(soapFactory);
                                 envelope = soapFactory.getDefaultEnvelope();
-                                envelope.getBody().addChild(
-                                        builder.getDocumentElement());
+                                envelope.getBody().addChild(builder.getDocumentElement());
                             }
                         } else {
-                            builder =
-                                    new StAXSOAPModelBuilder(
-                                            xmlreader,
-                                            SOAP11Constants
-                                                    .SOAP_ENVELOPE_NAMESPACE_URI);
-                            envelope =
-                                    (SOAPEnvelope) builder.getDocumentElement();
+                            builder = new StAXSOAPModelBuilder(
+                                    xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                            envelope = (SOAPEnvelope) builder.getDocumentElement();
                         }
                     }
-
                 }
-
             }
 
             String charsetEncoding = builder.getDocument().getCharsetEncoding();
-            if (charsetEncoding != null && !"".equals(charsetEncoding) &&
-                    !((String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING))
-                            .equalsIgnoreCase(charsetEncoding)) {
+
+            if ((charsetEncoding != null) && !"".equals(charsetEncoding)
+                    && !((String) msgContext.getProperty(
+                    MessageContext.CHARACTER_SET_ENCODING)).equalsIgnoreCase(charsetEncoding)) {
                 String faultCode;
-                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelope.getNamespace().getName())) {
+
+                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
+                        envelope.getNamespace().getName())) {
                     faultCode = SOAP12Constants.FAULT_CODE_SENDER;
                 } else {
                     faultCode = SOAP11Constants.FAULT_CODE_SENDER;
                 }
-                throw new AxisFault("Character Set Encoding from " +
-                        "transport information do not match with " +
-                        "character set encoding in the received SOAP message", faultCode);
-            }
 
+                throw new AxisFault(
+                        "Character Set Encoding from " + "transport information do not match with "
+                                + "character set encoding in the received SOAP message", faultCode);
+            }
 
             msgContext.setEnvelope(envelope);
+
             AxisEngine engine = new AxisEngine(msgContext.getConfigurationContext());
+
             if (envelope.getBody().hasFault()) {
                 engine.receiveFault(msgContext);
             } else {
@@ -215,9 +283,9 @@
             }
         } catch (SOAPProcessingException e) {
             throw new AxisFault(e);
-
         } catch (AxisFault e) {
-            //rethrow
+
+            // rethrow
             throw e;
         } catch (OMException e) {
             throw new AxisFault(e);
@@ -228,161 +296,87 @@
         } catch (UnsupportedEncodingException e) {
             throw new AxisFault(e);
         } finally {
-            if (msgContext.getEnvelope() == null && !soap11) {
-                msgContext.setEnvelope(
-                        new SOAP12Factory().createSOAPEnvelope());
+            if ((msgContext.getEnvelope() == null) && !soap11) {
+                msgContext.setEnvelope(new SOAP12Factory().createSOAPEnvelope());
             }
-
         }
     }
 
-    public static boolean processHTTPGetRequest(
-            MessageContext msgContext,
-            InputStream in,
-            OutputStream out,
-            String contentType,
-            String soapAction,
-            String requestURI,
-            ConfigurationContext configurationContext,
-            Map requestParameters)
-            throws AxisFault {
-        if (soapAction != null
-                && soapAction.startsWith("\"")
-                && soapAction.endsWith("\"")) {
-            soapAction = soapAction.substring(1, soapAction.length() - 1);
-        }
-        msgContext.setWSAAction(soapAction);
-        msgContext.setSoapAction(soapAction);
-        msgContext.setTo(new EndpointReference(requestURI));
-        msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
-        msgContext.setServerSide(true);
-        SOAPEnvelope envelope =
-                HTTPTransportUtils.createEnvelopeFromGetRequest(
-                        requestURI,
-                        requestParameters);
-        if (envelope == null) {
-            return false;
-        } else {
-            msgContext.setDoingREST(true);
-            msgContext.setEnvelope(envelope);
-            AxisEngine engine = new AxisEngine(configurationContext);
-            engine.receive(msgContext);
-            return true;
-        }
-    }
-
-    public static SOAPEnvelope createEnvelopeFromGetRequest(
-            String requestUrl,
-            Map map) {
-        String[] values =
-                Utils.parseRequestURLForServiceAndOperation(requestUrl);
-
-        if (values[1] != null && values[0] != null) {
-            String operation = values[1];
-            SOAPFactory soapFactory = new SOAP11Factory();
-            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-
-            OMNamespace omNs =
-                    soapFactory.createOMNamespace(values[0], "services");
-            OMNamespace defualtNs = new OMNamespaceImpl("", null);
-
-            OMElement opElement = soapFactory.createOMElement(operation, omNs);
-
-            Iterator it = map.keySet().iterator();
-            while (it.hasNext()) {
-                String name = (String) it.next();
-                String value = (String) map.get(name);
-                OMElement omEle = soapFactory.createOMElement(name, defualtNs);
-                omEle.setText(value);
-                opElement.addChild(omEle);
-            }
-
-            envelope.getBody().addChild(opElement);
-            return envelope;
-        } else {
-            return null;
-        }
-    }
-
-    public static StAXBuilder selectBuilderForMIME(
-            MessageContext msgContext,
-            InputStream inStream,
-            String contentTypeString)
-            throws OMException,
-            XMLStreamException, FactoryConfigurationError,
+    public static StAXBuilder selectBuilderForMIME(MessageContext msgContext, InputStream inStream,
+                                                   String contentTypeString)
+            throws OMException, XMLStreamException, FactoryConfigurationError,
             UnsupportedEncodingException {
         StAXBuilder builder = null;
-
-
-        Parameter parameter_cache_attachment = msgContext.getParameter(
-                Constants.Configuration.CACHE_ATTACHMENTS);
+        Parameter parameter_cache_attachment =
+                msgContext.getParameter(Constants.Configuration.CACHE_ATTACHMENTS);
         boolean fileCacheForAttachments;
+
         if (parameter_cache_attachment == null) {
             fileCacheForAttachments = false;
         } else {
             fileCacheForAttachments =
-                    (Constants
-                            .VALUE_TRUE
-                            .equals(
-                            parameter_cache_attachment.getValue()));
+                    (Constants.VALUE_TRUE.equals(parameter_cache_attachment.getValue()));
         }
+
         String attachmentRepoDir = null;
         String attachmentSizeThreshold = null;
         Parameter parameter;
-        if (fileCacheForAttachments) {
-            parameter = msgContext.getParameter(Constants.Configuration.ATTACHMENT_TEMP_DIR);
-            attachmentRepoDir = parameter == null ? "" : parameter.getValue().toString();
 
-            parameter = msgContext
-                    .getParameter(Constants.Configuration.FILE_SIZE_THRESHOLD);
-            attachmentSizeThreshold = parameter == null ? "" : parameter.getValue().toString();
+        if (fileCacheForAttachments) {
+            parameter =
+                    msgContext.getParameter(Constants.Configuration.ATTACHMENT_TEMP_DIR);
+            attachmentRepoDir = (parameter == null)
+                    ? ""
+                    : parameter.getValue().toString();
+            parameter =
+                    msgContext.getParameter(Constants.Configuration.FILE_SIZE_THRESHOLD);
+            attachmentSizeThreshold = (parameter == null)
+                    ? ""
+                    : parameter.getValue().toString();
         }
 
         MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString,
-                fileCacheForAttachments, attachmentRepoDir, attachmentSizeThreshold);
-
-        String charSetEncoding = TransportUtils.getCharSetEncoding(mimeHelper.getSOAPPartContentType());
+                fileCacheForAttachments, attachmentRepoDir,
+                attachmentSizeThreshold);
+        String charSetEncoding =
+                TransportUtils.getCharSetEncoding(mimeHelper.getSOAPPartContentType());
         XMLStreamReader streamReader;
-        if (charSetEncoding == null || "null".equalsIgnoreCase(charSetEncoding)) {
+
+        if ((charSetEncoding == null) || "null".equalsIgnoreCase(charSetEncoding)) {
             charSetEncoding = MessageContext.UTF_8;
         }
 
         try {
-            streamReader = XMLInputFactory.newInstance()
-                    .createXMLStreamReader(
-                            getReader(mimeHelper.getSOAPPartInputStream(), charSetEncoding));
+            streamReader = XMLInputFactory.newInstance().createXMLStreamReader(
+                    getReader(mimeHelper.getSOAPPartInputStream(), charSetEncoding));
         } catch (IOException e) {
             throw new XMLStreamException(e);
         }
+
         msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, charSetEncoding);
 
         /*
          * put a reference to Attachments in to the message context
          */
         msgContext.setProperty(MTOMConstants.ATTACHMENTS, mimeHelper);
+
         if (mimeHelper.getAttachmentSpecType().equals(MTOMConstants.MTOM_TYPE)) {
+
             /*
              * Creates the MTOM specific MTOMStAXSOAPModelBuilder
              */
-            builder =
-                    new MTOMStAXSOAPModelBuilder(
-                            streamReader,
-                            mimeHelper,
-                            null);
+            builder = new MTOMStAXSOAPModelBuilder(streamReader, mimeHelper, null);
         } else if (mimeHelper.getAttachmentSpecType().equals(MTOMConstants.SWA_TYPE)) {
-            builder =
-                    new StAXSOAPModelBuilder(
-                            streamReader,
-                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+            builder = new StAXSOAPModelBuilder(streamReader,
+                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
         }
+
         return builder;
     }
-    
-    private static final int BOM_SIZE = 4;
 
     /**
-     * Use the BOM Mark to identify the encoding to be used. Fall back to default encoding specified 
-     * 
+     * Use the BOM Mark to identify the encoding to be used. Fall back to default encoding specified
+     *
      * @param is
      * @param charSetEncoding
      * @return
@@ -390,14 +384,13 @@
      */
     private static Reader getReader(InputStream is, String charSetEncoding) throws IOException {
         PushbackInputStream is2 = new PushbackInputStream(is, BOM_SIZE);
-
         String encoding;
         byte bom[] = new byte[BOM_SIZE];
         int n, unread;
+
         n = is2.read(bom, 0, bom.length);
 
-        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) &&
-                (bom[2] == (byte) 0xBF)) {
+        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
             encoding = "UTF-8";
             unread = n - 3;
         } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
@@ -406,65 +399,26 @@
         } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
             encoding = "UTF-16LE";
             unread = n - 2;
-        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) &&
-                (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
+        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
+                && (bom[3] == (byte) 0xFF)) {
             encoding = "UTF-32BE";
             unread = n - 4;
-        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) &&
-                (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
+                && (bom[3] == (byte) 0x00)) {
             encoding = "UTF-32LE";
             unread = n - 4;
         } else {
+
             // Unicode BOM mark not found, unread all bytes
             encoding = charSetEncoding;
             unread = n;
         }
-        if (unread > 0) is2.unread(bom, (n - unread), unread);
-
-        return new BufferedReader(new InputStreamReader(is2,
-                encoding));
-    }
-
-    public static boolean checkEnvelopeForOptimise(SOAPEnvelope envelope) {
-        return isOptimised(envelope);
-    }
-
-    private static boolean isOptimised(OMElement element) {
-        Iterator childrenIter = element.getChildren();
-        boolean isOptimized = false;
-        while (childrenIter.hasNext() && !isOptimized) {
-            OMNode node = (OMNode) childrenIter.next();
-            if (OMNode.TEXT_NODE == node.getType()
-                    && ((OMText) node).isOptimized()) {
-                isOptimized = true;
-            } else if (OMNode.ELEMENT_NODE == node.getType()) {
-                isOptimized = isOptimised((OMElement) node);
-            }
-        }
-        return isOptimized;
-    }
 
-    public static boolean doWriteMTOM(MessageContext msgContext) {
-        boolean enableMTOM = false;
-        if (msgContext.getParameter(Constants.Configuration.ENABLE_MTOM)
-                != null) {
-            enableMTOM =
-                    Constants.VALUE_TRUE.equals(
-                            msgContext.getParameter(
-                                    Constants.Configuration.ENABLE_MTOM).getValue());
-        } else if (msgContext.getProperty(Constants.Configuration.ENABLE_MTOM) != null) {
-            enableMTOM =
-                    Constants.VALUE_TRUE.equals(
-                            msgContext.getProperty(
-                                    Constants.Configuration.ENABLE_MTOM));
+        if (unread > 0) {
+            is2.unread(bom, (n - unread), unread);
         }
 
-        boolean forceMIME = Constants.VALUE_TRUE.equals(msgContext.getProperty(Constants.Configuration.FORCE_MIME));
-        if (forceMIME) return true;
-
-        boolean envelopeContainsOptimise = HTTPTransportUtils.checkEnvelopeForOptimise(
-                msgContext.getEnvelope());
-        return enableMTOM && envelopeContainsOptimise;
+        return new BufferedReader(new InputStreamReader(is2, encoding));
     }
 
     public static boolean isDoingREST(MessageContext msgContext) {
@@ -476,19 +430,33 @@
         }
 
         Parameter parameter = msgContext.getParameter(Constants.Configuration.ENABLE_REST);
-        if (parameter
-                != null) {
-            enableREST =
-                    Constants.VALUE_TRUE.equals(
-                            parameter.getValue());
+
+        if (parameter != null) {
+            enableREST = Constants.VALUE_TRUE.equals(parameter.getValue());
         } else if (msgContext.getProperty(Constants.Configuration.ENABLE_REST) != null) {
-            enableREST =
-                    Constants.VALUE_TRUE.equals(
-                            msgContext.getProperty(
-                                    Constants.Configuration.ENABLE_REST));
+            enableREST = Constants.VALUE_TRUE.equals(
+                    msgContext.getProperty(Constants.Configuration.ENABLE_REST));
         }
+
         msgContext.setDoingREST(enableREST);
+
         return enableREST;
+    }
 
+    private static boolean isOptimised(OMElement element) {
+        Iterator childrenIter = element.getChildren();
+        boolean isOptimized = false;
+
+        while (childrenIter.hasNext() && !isOptimized) {
+            OMNode node = (OMNode) childrenIter.next();
+
+            if ((OMNode.TEXT_NODE == node.getType()) && ((OMText) node).isOptimized()) {
+                isOptimized = true;
+            } else if (OMNode.ELEMENT_NODE == node.getType()) {
+                isOptimized = isOptimised((OMElement) node);
+            }
+        }
+
+        return isOptimized;
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.http;
 
@@ -50,12 +51,13 @@
     protected Log log = LogFactory.getLog(getClass().getName());
     private ConfigurationContext configurationContext;
 
-
     public HTTPWorker(ConfigurationContext configurationContext) {
         this.configurationContext = configurationContext;
     }
 
-    public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
+    public boolean processRequest(final SimpleHttpServerConnection conn,
+                                  final SimpleRequest request)
+            throws IOException {
         MessageContext msgContext = null;
         SimpleResponse response = new SimpleResponse();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -66,123 +68,123 @@
             }
 
             InputStream inStream = request.getBody();
-
             TransportOutDescription transportOut =
                     configurationContext.getAxisConfiguration().getTransportOut(
                             new QName(Constants.TRANSPORT_HTTP));
-            msgContext =
-                    new MessageContext(
-                            configurationContext,
-                            configurationContext.getAxisConfiguration().getTransportIn(
-                                    new QName(Constants.TRANSPORT_HTTP)),
-                            transportOut);
+
+            msgContext = new MessageContext(
+                    configurationContext,
+                    configurationContext.getAxisConfiguration().getTransportIn(
+                            new QName(Constants.TRANSPORT_HTTP)), transportOut);
             msgContext.setServerSide(true);
 
             HttpVersion ver = request.getRequestLine().getHttpVersion();
+
             if (ver == null) {
                 throw new AxisFault("HTTP version can not be Null");
             }
+
             String httpVersion = null;
+
             if (HttpVersion.HTTP_1_0.equals(ver)) {
                 httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
             } else if (HttpVersion.HTTP_1_1.equals(ver)) {
                 httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+
                 /**
                  * Transport Sender configuration via axis2.xml
                  */
-                this.transportOutConfiguration(configurationContext,response);
+                this.transportOutConfiguration(configurationContext, response);
             } else {
                 throw new AxisFault("Unknown supported protocol version " + ver);
             }
 
-
             msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
 
-            //set the transport Headers
+            // set the transport Headers
             msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, getHeaders(request));
             msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
 
-            //This is way to provide access to the transport information to the transport Sender
-            msgContext.setProperty(
-                    Constants.OUT_TRANSPORT_INFO,
+            // This is way to provide access to the transport information to the transport Sender
+            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
                     new SimpleHTTPOutTransportInfo(response));
 
             String soapAction = null;
+
             if (request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION) != null) {
                 soapAction = request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION).getValue();
             }
+
             if (HTTPConstants.HEADER_GET.equals(request.getRequestLine().getMethod())) {
-                //It is GET handle the Get request
-                boolean processed =
-                        HTTPTransportUtils.processHTTPGetRequest(
-                                msgContext,
-                                inStream,
-                                baos,
-                                request.getContentType(),
-                                soapAction,
-                                request.getRequestLine().getUri(),
-                                configurationContext,
-                                HTTPTransportReceiver.getGetRequestParameters(
-                                        request.getRequestLine().getUri()));
+
+                // It is GET handle the Get request
+                boolean processed = HTTPTransportUtils.processHTTPGetRequest(
+                        msgContext, inStream, baos, request.getContentType(),
+                        soapAction, request.getRequestLine().getUri(),
+                        configurationContext,
+                        HTTPTransportReceiver.getGetRequestParameters(
+                                request.getRequestLine().getUri()));
+
                 if (!processed) {
                     response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
                     response.addHeader(new Header("Content-Type", "text/html"));
-                    response.setBodyString(HTTPTransportReceiver.getServicesHTML(configurationContext));
-                    setResponseHeaders(conn, request, response,0);
+                    response.setBodyString(
+                            HTTPTransportReceiver.getServicesHTML(configurationContext));
+                    setResponseHeaders(conn, request, response, 0);
                     conn.writeResponse(response);
+
                     return true;
                 }
             } else {
                 ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
-                byte[] bytes = new byte[8192];
+                byte[]                bytes = new byte[8192];
                 int size = 0;
+
                 while ((size = inStream.read(bytes)) > 0) {
                     baosIn.write(bytes, 0, size);
                 }
+
                 inStream = new ByteArrayInputStream(baosIn.toByteArray());
 
-                //It is POST, handle it
-                HTTPTransportUtils.processHTTPPostRequest(
-                        msgContext,
-                        inStream,
-                        baos,
-                        request.getContentType(),
-                        soapAction,
-                        request.getRequestLine().getUri()
-                );
+                // It is POST, handle it
+                HTTPTransportUtils.processHTTPPostRequest(msgContext, inStream, baos,
+                        request.getContentType(), soapAction, request.getRequestLine().getUri());
             }
 
             OperationContext operationContext = msgContext.getOperationContext();
-
             Object contextWritten = null;
-            if (operationContext!=null)
+
+            if (operationContext != null) {
                 contextWritten = operationContext.getProperty(Constants.RESPONSE_WRITTEN);
+            }
 
-            if (contextWritten != null &&
-                    Constants.VALUE_TRUE.equals(contextWritten)) {
-                response.setStatusLine(
-                        request.getRequestLine().getHttpVersion(), 200, "OK");
+            if ((contextWritten != null) && Constants.VALUE_TRUE.equals(contextWritten)) {
+                response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
             } else {
-                response.setStatusLine(
-                        request.getRequestLine().getHttpVersion(), 202, "OK");
+                response.setStatusLine(request.getRequestLine().getHttpVersion(), 202, "OK");
             }
+
             response.setBody(new ByteArrayInputStream(baos.toByteArray()));
-            setResponseHeaders(conn, request, response,
-                    baos.toByteArray().length);
+            setResponseHeaders(conn, request, response, baos.toByteArray().length);
             conn.writeResponse(response);
         } catch (Throwable e) {
-            if(!(e instanceof java.net.SocketException)) {
+            if (!(e instanceof java.net.SocketException)) {
                 log.debug(e.getMessage(), e);
             }
+
             try {
                 AxisEngine engine = new AxisEngine(configurationContext);
+
                 if (msgContext != null) {
                     msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
+
                     MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
-                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 500, "Internal server error");
+
+                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 500,
+                            "Internal server error");
                     engine.sendFault(faultContext);
                     response.setBody(new ByteArrayInputStream(baos.toByteArray()));
-                    setResponseHeaders(conn, request, response,baos.toByteArray().length);
+                    setResponseHeaders(conn, request, response, baos.toByteArray().length);
                     conn.writeResponse(response);
                 }
             } catch (SocketException e1) {
@@ -191,79 +193,43 @@
                 log.warn(e1.getMessage(), e1);
             }
         }
-        return true;
-    }
 
-    private void setResponseHeaders(final SimpleHttpServerConnection conn, SimpleRequest request, SimpleResponse response, long contentLength) {
-        if (!response.containsHeader("Connection")) {
-            // See if the the client explicitly handles connection persistence
-            Header connheader = request.getFirstHeader("Connection");
-            if (connheader != null) {
-                if (connheader.getValue().equalsIgnoreCase("keep-alive")) {
-                    Header header = new Header("Connection", "keep-alive");
-                    response.addHeader(header);
-                    conn.setKeepAlive(true);
-                }
-                if (connheader.getValue().equalsIgnoreCase("close")) {
-                    Header header = new Header("Connection", "close");
-                    response.addHeader(header);
-                    conn.setKeepAlive(false);
-                }
-            } else {
-                // Use protocol default connection policy
-                if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
-                    conn.setKeepAlive(true);
-                } else {
-                    conn.setKeepAlive(false);
-                }
-            }
-        }
-        if (!response.containsHeader("Transfer-Encoding")) {
-            if (contentLength != 0) {
-                Header header = new Header("Content-Length",
-                        String.valueOf(contentLength));
-                response.addHeader(header);
-            }
-        }
-    }
-
-    private Map getHeaders(SimpleRequest request) {
-        HashMap headerMap = new HashMap();
-        Header[] headers = request.getHeaders();
-        for (int i = 0; i < headers.length; i++) {
-            headerMap.put(headers[i].getName(), headers[i].getValue());
-        }
-        return headerMap;
+        return true;
     }
 
-
     /**
-     *   Simple Axis Transport Selection via deployment
+     * Simple Axis Transport Selection via deployment
+     *
      * @param configContext
      * @param response
-     *
      */
-
-    private void transportOutConfiguration(ConfigurationContext configContext, SimpleResponse response) {
+    private void transportOutConfiguration(ConfigurationContext configContext,
+                                           SimpleResponse response) {
         AxisConfiguration axisConf = configContext.getAxisConfiguration();
         HashMap trasportOuts = axisConf.getTransportsOut();
         Iterator values = trasportOuts.values().iterator();
-
         String httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+
         while (values.hasNext()) {
             TransportOutDescription transportOut = (TransportOutDescription) values.next();
+
             // reading axis2.xml for transport senders..
-            Parameter version =
-                    transportOut.getParameter(HTTPConstants.PROTOCOL_VERSION);
+            Parameter version = transportOut.getParameter(HTTPConstants.PROTOCOL_VERSION);
+
             if (version != null) {
                 if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
                     httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+
                     Parameter transferEncoding =
                             transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
-                    if (transferEncoding != null){
-                        if (HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding.getValue())) {
-                            response.setHeader(new Header(HTTPConstants.HEADER_TRANSFER_ENCODING,
-                                    HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED));
+
+                    if (transferEncoding != null) {
+                        if (HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(
+                                transferEncoding.getValue())) {
+                            response.setHeader(
+                                    new Header(
+                                            HTTPConstants.HEADER_TRANSFER_ENCODING,
+                                            HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED));
                         }
                     } else {
                         continue;
@@ -274,8 +240,58 @@
                     }
                 }
             }
+        }
+    }
 
+    private Map getHeaders(SimpleRequest request) {
+        HashMap headerMap = new HashMap();
+        Header[] headers = request.getHeaders();
+
+        for (int i = 0; i < headers.length; i++) {
+            headerMap.put(headers[i].getName(), headers[i].getValue());
         }
+
+        return headerMap;
     }
 
+    private void setResponseHeaders(final SimpleHttpServerConnection conn, SimpleRequest request,
+                                    SimpleResponse response, long contentLength) {
+        if (!response.containsHeader("Connection")) {
+
+            // See if the the client explicitly handles connection persistence
+            Header connheader = request.getFirstHeader("Connection");
+
+            if (connheader != null) {
+                if (connheader.getValue().equalsIgnoreCase("keep-alive")) {
+                    Header header = new Header("Connection", "keep-alive");
+
+                    response.addHeader(header);
+                    conn.setKeepAlive(true);
+                }
+
+                if (connheader.getValue().equalsIgnoreCase("close")) {
+                    Header header = new Header("Connection", "close");
+
+                    response.addHeader(header);
+                    conn.setKeepAlive(false);
+                }
+            } else {
+
+                // Use protocol default connection policy
+                if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
+                    conn.setKeepAlive(true);
+                } else {
+                    conn.setKeepAlive(false);
+                }
+            }
+        }
+
+        if (!response.containsHeader("Transfer-Encoding")) {
+            if (contentLength != 0) {
+                Header header = new Header("Content-Length", String.valueOf(contentLength));
+
+                response.addHeader(header);
+            }
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java Fri Dec 16 09:13:57 2005
@@ -1,4 +1,5 @@
 package org.apache.axis2.transport.http;
+
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
  *
@@ -25,87 +26,93 @@
     protected HttpVersion httpVersion;
     protected String protocol;
 
-    public HttpTransportProperties(){}
-
-    public void setChunked(boolean chunked){
-        this.chunked = chunked;
-    }
-    public void setHttpVersion(HttpVersion httpVerion){
-        this.httpVersion = httpVerion;
-    }
-    public void setProtocol(String protocol){
-        this.protocol = protocol;
+    public HttpTransportProperties() {
     }
 
-    public boolean getChunked(){
+    public boolean getChunked() {
         return chunked;
     }
-    public HttpVersion getHttpVersion(){
+
+    public HttpVersion getHttpVersion() {
         return httpVersion;
     }
-    public String getProtocol(){
+
+    public String getProtocol() {
         return protocol;
     }
 
+    public void setChunked(boolean chunked) {
+        this.chunked = chunked;
+    }
+
+    public void setHttpVersion(HttpVersion httpVerion) {
+        this.httpVersion = httpVerion;
+    }
+
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
     public class ProxyProperties {
-        protected String proxyHostName;
         protected int proxyPort = -1;
-
-        protected String userName;
         protected String domain;
         protected String passWord;
-        
-        public ProxyProperties() {}
+        protected String proxyHostName;
+        protected String userName;
 
-        public void setUserName(String userName){
-            this.userName = userName;
-        }
-        public void setDomain(String domain){
-            this.domain = domain;
-        }
-        public void setPassWord(String passWord){
-            this.passWord = passWord;
+        public ProxyProperties() {
         }
 
-        public void setProxyName(String proxyHostName){
-            this.proxyHostName = proxyHostName;
+        public String getDomain() {
+            if (domain.equals("") || (domain == null)) {
+                return "anonymous";
+            } else {
+                return domain;
+            }
         }
-        public void setProxyPort(int proxyPort){
-            this.proxyPort = proxyPort;
+
+        public String getPassWord() {
+            if (passWord.equals("") || (passWord == null)) {
+                return "anonymous";
+            } else {
+                return passWord;
+            }
         }
 
-        public String getProxyHostName(){
+        public String getProxyHostName() {
             return proxyHostName;
         }
-        public int getProxyPort(){
+
+        public int getProxyPort() {
             return proxyPort;
         }
 
         public String getUserName() {
-            if (userName.equals("") || userName == null) {
+            if (userName.equals("") || (userName == null)) {
                 return "anonymous";
             } else {
                 return userName;
             }
         }
 
-        public String getDomain() {
-            if (domain.equals("") || domain == null) {
-                return "anonymous";
-            } else {
-                return domain;
-            }
+        public void setDomain(String domain) {
+            this.domain = domain;
         }
 
-        public String getPassWord() {
-            if (passWord.equals("") || passWord == null) {
-                return "anonymous";
-            } else {
-                return passWord;
-            }
+        public void setPassWord(String passWord) {
+            this.passWord = passWord;
         }
 
-    }
+        public void setProxyName(String proxyHostName) {
+            this.proxyHostName = proxyHostName;
+        }
 
+        public void setProxyPort(int proxyPort) {
+            this.proxyPort = proxyPort;
+        }
 
+        public void setUserName(String userName) {
+            this.userName = userName;
+        }
+    }
 }