You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Saminda Abeyruwan <sa...@opensource.lk> on 2005/09/06 15:12:47 UTC

[Axis2] Upgraded transport sender

Hi all,

CommonsHttpTransportSender being changed to support chunking on/off, 
when optimized content is present. In order to switch on/off axis2.xml 
need to be modified as follows.

.....
<transportSender name="http" 
class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding" 
locked="false">chunked</parameter>
</transportSender>
....

Please apply this patch. Thanks

Saminda

Re: [Axis2] Upgraded transport sender

Posted by Davanum Srinivas <da...@gmail.com>.
thanks. much better.

-- dims

On 9/6/05, Saminda Abeyruwan <sa...@opensource.lk> wrote:
> Davanum Srinivas wrote:
> 
> >too many whitespaces :( can't really say what changed :( :(
> >
> >-- dims
> >
> >
> Sorry for the inconvenience caused with prior patch. More clearer path
> is apply herewith.
> 
> Thanks
> 
> Saminda
> 
> >On 9/6/05, Saminda Abeyruwan <sa...@opensource.lk> wrote:
> >
> >
> >>Hi all,
> >>
> >>CommonsHttpTransportSender being changed to support chunking on/off,
> >>when optimized content is present. In order to switch on/off axis2.xml
> >>need to be modified as follows.
> >>
> >>.....
> >><transportSender name="http"
> >>class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
> >>        <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
> >>        <parameter name="Transfer-Encoding"
> >>locked="false">chunked</parameter>
> >></transportSender>
> >>....
> >>
> >>Please apply this patch. Thanks
> >>
> >>Saminda
> >>
> >>
> >>Index: src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
> >>===================================================================
> >>--- src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (revision 278977)
> >>+++ src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (working copy)
> >>@@ -69,15 +69,17 @@
> >>     public void invoke(MessageContext msgContext) throws AxisFault {
> >>         try {
> >>             String charSetEnc =
> >>-                    (String) msgContext.getProperty(
> >>-                            MessageContext.CHARACTER_SET_ENCODING);
> >>+                    (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> >>             if (charSetEnc != null) {
> >>                 omOutput.setCharSetEncoding(charSetEnc);
> >>             } else {
> >>                 OperationContext opctx = msgContext.getOperationContext();
> >>-                if(opctx != null) {
> >>-                    charSetEnc = (String)opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> >>+
> >>+                if (opctx != null) {
> >>+                    charSetEnc =
> >>+                            (String) opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> >>                 }
> >>+
> >>             }
> >>             /**
> >>              * If the char set enc is still not found use the default
> >>@@ -85,10 +87,12 @@
> >>             if(charSetEnc == null) {
> >>                 charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
> >>             }
> >>+
> >>             msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
> >>             omOutput.setSoap11(msgContext.isSOAP11());
> >>             omOutput.setDoOptimize(msgContext.isDoingMTOM());
> >>
> >>+
> >>             omOutput.setCharSetEncoding(charSetEnc);
> >>
> >>             //Check for the REST behaviour, if you desire rest beahaviour
> >>@@ -96,10 +100,12 @@
> >>             // server.xml/client.xml file
> >>             EndpointReference epr = null;
> >>             if (msgContext.getTo() != null
> >>-                    && !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(
> >>-                            msgContext.getTo().getAddress())
> >>-                    && !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(
> >>-                            msgContext.getTo().getAddress())) {
> >>+                    &&
> >>+                    !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
> >>+                    .getAddress())
> >>+                    &&
> >>+                    !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
> >>+                    .getAddress())) {
> >>                 epr = msgContext.getTo();
> >>             }
> >>
> >>@@ -115,26 +121,24 @@
> >>                 writeMessageWithCommons(msgContext, epr, dataOut);
> >>             } else {
> >>                 OutputStream out =
> >>-                        (OutputStream) msgContext.getProperty(
> >>-                                MessageContext.TRANSPORT_OUT);
> >>+                        (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
> >>                 if (msgContext.isServerSide()) {
> >>                     HTTPOutTransportInfo transportInfo =
> >>-                            (HTTPOutTransportInfo) msgContext.getProperty(
> >>-                                    HTTPConstants.HTTPOutTransportInfo);
> >>+                            (HTTPOutTransportInfo) msgContext.getProperty(HTTPConstants.HTTPOutTransportInfo);
> >>                     if (transportInfo != null) {
> >>                         omOutput.setSoap11(msgContext.isSOAP11());
> >>                         transportInfo.setContentType(omOutput.getContentType());
> >>-                    }else{
> >>-                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo + " does not set");
> >>+                    } else {
> >>+                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo +
> >>+                                " does not set");
> >>                     }
> >>                 }
> >>                 omOutput.setOutputStream(out, msgContext.isDoingMTOM());
> >>                 dataOut.serialize(omOutput);
> >>                 omOutput.flush();
> >>             }
> >>-            if(msgContext.getOperationContext() != null){
> >>-                msgContext.getOperationContext().setProperty(
> >>-                        Constants.RESPONSE_WRITTEN,
> >>+            if (msgContext.getOperationContext() != null) {
> >>+                msgContext.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN,
> >>                         Constants.VALUE_TRUE);
> >>             }
> >>         } catch (XMLStreamException e) {
> >>@@ -146,16 +150,14 @@
> >>         }
> >>     }
> >>
> >>-    public void writeMessageWithToOutPutStream(
> >>-            MessageContext msgContext,
> >>-            OutputStream out) {
> >>+    public void writeMessageWithToOutPutStream(MessageContext msgContext,
> >>+                                               OutputStream out) {
> >>
> >>     }
> >>
> >>-    public void writeMessageWithCommons(
> >>-            MessageContext msgContext,
> >>-            EndpointReference toURL,
> >>-            OMElement dataout)
> >>+    public void writeMessageWithCommons(MessageContext msgContext,
> >>+                                        EndpointReference toURL,
> >>+                                        OMElement dataout)
> >>             throws AxisFault {
> >>         try {
> >>             URL url = new URL(toURL.getAddress());
> >>@@ -170,16 +172,14 @@
> >>             //supporting RESTFacility..
> >>
> >>             if (!msgContext.isDoingREST()) {
> >>-                this.transportConfigurationPOST(
> >>-                        msgContext,
> >>+                this.transportConfigurationPOST(msgContext,
> >>                         dataout,
> >>                         url,
> >>                         soapActionString);
> >>             }
> >>             if (msgContext.isDoingREST()) {
> >>                 if (msgContext.isRestThroughPOST()) {
> >>-                    this.transportConfigurationPOST(
> >>-                            msgContext,
> >>+                    this.transportConfigurationPOST(msgContext,
> >>                             dataout,
> >>                             url,
> >>                             soapActionString);
> >>@@ -196,13 +196,12 @@
> >>         }
> >>
> >>     }
> >>-    protected HostConfiguration getHostConfiguration(
> >>-            MessageContext context,
> >>-            URL targetURL) {
> >>+
> >>+    protected HostConfiguration getHostConfiguration(MessageContext context,
> >>+                                                     URL targetURL) {
> >>         //TODO cheaking wheather the host is a proxy
> >>         HostConfiguration config = new HostConfiguration();
> >>-        config.setHost(
> >>-                targetURL.getHost(),
> >>+        config.setHost(targetURL.getHost(),
> >>                 targetURL.getPort() == -1 ? 80 : targetURL.getPort());
> >>         return config;
> >>     }
> >>@@ -220,11 +219,10 @@
> >>
> >>         private boolean doingMTOM = false;
> >>
> >>-        public AxisRequestEntity(
> >>-                OMElement element,
> >>-                boolean chuncked,
> >>-                boolean doingMTOM,
> >>-                String charSetEncoding) {
> >>+        public AxisRequestEntity(OMElement element,
> >>+                                 boolean chuncked,
> >>+                                 boolean doingMTOM,
> >>+                                 String charSetEncoding) {
> >>             this.element = element;
> >>             this.chuncked = chuncked;
> >>             this.doingMTOM = doingMTOM;
> >>@@ -237,16 +235,26 @@
> >>
> >>         public byte[] writeBytes() throws AxisFault {
> >>             try {
> >>+
> >>                 ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
> >>-                XMLStreamWriter outputWriter =
> >>-                        XMLOutputFactory.newInstance().createXMLStreamWriter(
> >>-                                bytesOut,
> >>-                                charSetEnc);
> >>-                OMOutputImpl out = new OMOutputImpl(outputWriter);
> >>-                out.setCharSetEncoding(charSetEnc);
> >>-                element.serialize(out);
> >>-                out.flush();
> >>-                return bytesOut.toByteArray();
> >>+
> >>+                if (!doingMTOM) {
> >>+                    XMLStreamWriter outputWriter =
> >>+                            XMLOutputFactory.newInstance()
> >>+                            .createXMLStreamWriter(bytesOut,
> >>+                                    charSetEnc);
> >>+                    OMOutputImpl output = new OMOutputImpl(outputWriter);
> >>+                    output.setCharSetEncoding(charSetEnc);
> >>+                    element.serialize(output);
> >>+                    output.flush();
> >>+                    return bytesOut.toByteArray();
> >>+                } else {
> >>+                    omOutput.setCharSetEncoding(charSetEnc);
> >>+                    omOutput.setOutputStream(bytesOut, true);  //changed...
> >>+                    element.serialize(omOutput);
> >>+                    omOutput.flush();
> >>+                    return bytesOut.toByteArray();
> >>+                }
> >>             } catch (XMLStreamException e) {
> >>                 throw new AxisFault(e);
> >>             } catch (FactoryConfigurationError e) {
> >>@@ -254,20 +262,36 @@
> >>             }
> >>         }
> >>
> >>+        private void handleOMOutput(OutputStream out, boolean doingMTOM)
> >>+                throws XMLStreamException {
> >>+            omOutput.setOutputStream(out, doingMTOM);
> >>+            element.serialize(omOutput);
> >>+            omOutput.flush();
> >>+        }
> >>+
> >>         public void writeRequest(OutputStream out) throws IOException {
> >>             try {
> >>-                if (chuncked || doingMTOM) {
> >>-                    omOutput.setOutputStream(out, doingMTOM);
> >>-                    element.serialize(omOutput);
> >>-                    omOutput.flush();
> >>+                if (doingMTOM) { //chagened ..
> >>+                    if (chuncked) {
> >>+                        this.handleOMOutput(out, doingMTOM);
> >>+                    } else {
> >>+                        if (bytes == null) {
> >>+                            bytes = writeBytes();
> >>+                        }
> >>+                        out.write(bytes);
> >>+                    }
> >>
> >>                 } else {
> >>-                    if (bytes == null) {
> >>-                        bytes = writeBytes();
> >>+                    if (chuncked) {
> >>+                        this.handleOMOutput(out, doingMTOM);
> >>+                    } else {
> >>+                        if (bytes == null) {
> >>+                            bytes = writeBytes();
> >>+                        }
> >>+                        out.write(bytes);
> >>                     }
> >>-                    out.write(bytes);
> >>                 }
> >>-               out.flush();
> >>+                out.flush();
> >>             } catch (XMLStreamException e) {
> >>                 throw new AxisFault(e);
> >>             } catch (FactoryConfigurationError e) {
> >>@@ -279,13 +303,24 @@
> >>
> >>         public long getContentLength() {
> >>             try {
> >>-                if (chuncked || doingMTOM) {
> >>-                    return -1;
> >>+                if (doingMTOM) {    //chagened
> >>+                    if (chuncked) {
> >>+                        return -1;
> >>+                    } else {
> >>+                        if (bytes == null) {
> >>+                            bytes = writeBytes();
> >>+                        }
> >>+                        return bytes.length;
> >>+                    }
> >>                 } else {
> >>-                    if (bytes == null) {
> >>-                        bytes = writeBytes();
> >>+                    if (chuncked) {
> >>+                        return -1;
> >>+                    } else {
> >>+                        if (bytes == null) {
> >>+                            bytes = writeBytes();
> >>+                        }
> >>+                        return bytes.length;
> >>                     }
> >>-                    return bytes.length;
> >>                 }
> >>             } catch (AxisFault e) {
> >>                 return -1;
> >>@@ -311,9 +346,8 @@
> >>
> >>     }
> >>
> >>-    public void init(
> >>-            ConfigurationContext confContext,
> >>-            TransportOutDescription transportOut)
> >>+    public void init(ConfigurationContext confContext,
> >>+                     TransportOutDescription transportOut)
> >>             throws AxisFault {
> >>         //<parameter name="PROTOCOL" locked="false">HTTP/1.0</parameter> or
> >>         //<parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> is
> >>@@ -324,19 +358,17 @@
> >>             if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
> >>                 this.httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
> >>                 Parameter transferEncoding =
> >>-                        transportOut.getParameter(
> >>-                                HTTPConstants.HEADER_TRANSFER_ENCODING);
> >>+                        transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
> >>                 if (transferEncoding != null
> >>-                        && HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(
> >>-                                transferEncoding.getValue())) {
> >>+                        &&
> >>+                        HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding.getValue())) {
> >>                     this.chuncked = true;
> >>                 }
> >>             } else if (
> >>                     HTTPConstants.HEADER_PROTOCOL_10.equals(version.getValue())) {
> >>                 this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
> >>             } else {
> >>-                throw new AxisFault(
> >>-                        "Parameter "
> >>+                throw new AxisFault("Parameter "
> >>                         + HTTPConstants.PROTOCOL_VERSION
> >>                         + " Can have values only HTTP/1.0 or HTTP/1.1");
> >>             }
> >>@@ -344,11 +376,10 @@
> >>
> >>     }
> >>
> >>-    private void transportConfigurationPOST(
> >>-            MessageContext msgContext,
> >>-            OMElement dataout,
> >>-            URL url,
> >>-            String soapActionString)
> >>+    private void transportConfigurationPOST(MessageContext msgContext,
> >>+                                            OMElement dataout,
> >>+                                            URL url,
> >>+                                            String soapActionString)
> >>             throws MalformedURLException, AxisFault, IOException {
> >>
> >>         //execuite the HtttpMethodBase - a connection manager can be given for handle multiple
> >>@@ -367,29 +398,24 @@
> >>         msgContext.setProperty(HTTP_METHOD, postMethod);
> >>
> >>         String charEncoding =
> >>-                (String) msgContext.getProperty(
> >>-                        MessageContext.CHARACTER_SET_ENCODING);
> >>-        if(charEncoding == null){
> >>+                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> >>+        if (charEncoding == null) {
> >>             charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
> >>         }
> >>
> >>-        postMethod.setRequestEntity(
> >>-                new AxisRequestEntity(
> >>-                        dataout,
> >>-                        chuncked,
> >>-                        msgContext.isDoingMTOM(),
> >>-                        charEncoding));
> >>+        postMethod.setRequestEntity(new AxisRequestEntity(dataout,
> >>+                chuncked,
> >>+                msgContext.isDoingMTOM(),
> >>+                charEncoding));
> >>
> >>         if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)
> >>                 && chuncked) {
> >>             postMethod.setContentChunked(true);
> >>         }
> >>-        postMethod.setRequestHeader(
> >>-                HTTPConstants.HEADER_USER_AGENT,
> >>+        postMethod.setRequestHeader(HTTPConstants.HEADER_USER_AGENT,
> >>                 "Axis/2.0");
> >>         if (!msgContext.isDoingREST()) {
> >>-            postMethod.setRequestHeader(
> >>-                    HTTPConstants.HEADER_SOAP_ACTION,
> >>+            postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION,
> >>                     soapActionString);
> >>         }
> >>         postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
> >>@@ -397,57 +423,53 @@
> >>             if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
> >>                 //postMethod.setHttp11(false); todo method to findout the transport version...
> >>                 //allowing keep-alive for 1.0
> >>-                postMethod.setRequestHeader(
> >>-                        HTTPConstants.HEADER_CONNECTION,
> >>+                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
> >>                         HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
> >>             } else {
> >>                 // allowing keep-alive for 1.1
> >>-                postMethod.setRequestHeader(
> >>-                        HTTPConstants.HEADER_CONNECTION,
> >>+                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
> >>                         HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
> >>-                postMethod.setRequestHeader(
> >>-                        HTTPConstants.HEADER_EXPECT,
> >>+                postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
> >>                         HTTPConstants.HEADER_EXPECT_100_Continue);
> >>             }
> >>         }
> >>-
> >>+
> >>         this.httpClient.executeMethod(postMethod);
> >>
> >>         if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
> >>             processResponse(postMethod, msgContext);
> >>         } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
> >>             return;
> >>-        } else  if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
> >>+        } else if (postMethod.getStatusCode() ==
> >>+                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
> >>
> >>-            Header contenttypeHheader = postMethod.getResponseHeader(
> >>-                    HTTPConstants.HEADER_CONTENT_TYPE);
> >>+            Header contenttypeHheader = postMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
> >>
> >>             String value = contenttypeHheader.getValue();
> >>-            if(value != null){
> >>-                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
> >>-                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
> >>+            if (value != null) {
> >>+                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
> >>+                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
> >>+                        0) {
> >>                     processResponse(postMethod, msgContext);
> >>                 }
> >>             }
> >>-        }else{
> >>-            throw new AxisFault(
> >>-                    Messages.getMessage(
> >>-                            "transportError",
> >>-                            String.valueOf(postMethod.getStatusCode()),
> >>-                            postMethod.getResponseBodyAsString()));
> >>+        } else {
> >>+            throw new AxisFault(Messages.getMessage("transportError",
> >>+                    String.valueOf(postMethod.getStatusCode()),
> >>+                    postMethod.getResponseBodyAsString()));
> >>         }
> >>
> >>     }
> >>
> >>-    private void processResponse(HttpMethodBase httpMethod, MessageContext msgContext) throws IOException {
> >>+    private void processResponse(HttpMethodBase httpMethod,
> >>+                                 MessageContext msgContext) throws IOException {
> >>         obatainHTTPHeaderInformation(httpMethod, msgContext);
> >>         InputStream in = httpMethod.getResponseBodyAsStream();
> >>         if (in == null) {
> >>-            throw new AxisFault(
> >>-                    Messages.getMessage("canNotBeNull", "InputStream"));
> >>+            throw new AxisFault(Messages.getMessage("canNotBeNull",
> >>+                    "InputStream"));
> >>         }
> >>-        msgContext.getOperationContext().setProperty(
> >>-                MessageContext.TRANSPORT_IN,
> >>+        msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN,
> >>                 in);
> >>     }
> >>
> >>@@ -457,16 +479,13 @@
> >>         getMethod.setPath(url.getFile());
> >>
> >>         String charEncoding =
> >>-                (String) msgContext.getProperty(
> >>-                        MessageContext.CHARACTER_SET_ENCODING);
> >>+                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> >>         if (charEncoding == null) //Default encoding scheme
> >>-            getMethod.setRequestHeader(
> >>-                    HTTPConstants.HEADER_CONTENT_TYPE,
> >>+            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
> >>                     "text/xml; charset="
> >>                     + MessageContext.DEFAULT_CHAR_SET_ENCODING);
> >>         else
> >>-            getMethod.setRequestHeader(
> >>-                    HTTPConstants.HEADER_CONTENT_TYPE,
> >>+            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
> >>                     "text/xml; charset=" + charEncoding);
> >>
> >>         this.httpClient = new HttpClient();
> >>@@ -490,34 +509,35 @@
> >> //                    in);
> >>         } else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
> >>             return;
> >>-        }else  if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
> >>+        } else if (getMethod.getStatusCode() ==
> >>+                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
> >>
> >>-            Header contenttypeHheader = getMethod.getResponseHeader(
> >>-                    HTTPConstants.HEADER_CONTENT_TYPE);
> >>+            Header contenttypeHheader = getMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
> >>
> >>-             String value = contenttypeHheader.getValue();
> >>-            if(value != null){
> >>-                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
> >>-                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
> >>+            String value = contenttypeHheader.getValue();
> >>+            if (value != null) {
> >>+                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
> >>+                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
> >>+                        0) {
> >>                     processResponse(getMethod, msgContext);
> >>                 }
> >>
> >>             }
> >>-        }else{
> >>-            throw new AxisFault(
> >>-                    Messages.getMessage(
> >>-                            "transportError",
> >>-                            String.valueOf(getMethod.getStatusCode()),
> >>-                            getMethod.getResponseBodyAsString()));
> >>+        } else {
> >>+            throw new AxisFault(Messages.getMessage("transportError",
> >>+                    String.valueOf(getMethod.getStatusCode()),
> >>+                    getMethod.getResponseBodyAsString()));
> >>         }
> >>     }
> >>
> >>     /**
> >>      * Collect the HTTP header information and set them in the message context
> >>+     *
> >>      * @param method
> >>      * @param msgContext
> >>      */
> >>-    private void obatainHTTPHeaderInformation(HttpMethodBase method,MessageContext msgContext) {
> >>+    private void obatainHTTPHeaderInformation(HttpMethodBase method,
> >>+                                              MessageContext msgContext) {
> >>         Header header =
> >>                 method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
> >>         if (header != null) {
> >>@@ -527,20 +547,22 @@
> >>                         .getParameterByName(HTTPConstants.CHAR_SET_ENCODING);
> >>                 if (headers[i]
> >>                         .getName()
> >>-                        .equalsIgnoreCase(
> >>-                                HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
> >>+                        .equalsIgnoreCase(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
> >>                     OperationContext opContext =
> >>                             msgContext.getOperationContext();
> >>                     if (opContext != null) {
> >>-                        opContext.setProperty(
> >>-                                HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
> >>+                        opContext.setProperty(HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
> >>                                 header.getValue());
> >>                     }
> >>+                    if (charsetEnc != null) {
> >>+                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
> >>+                                charsetEnc);
> >>+                    }
> >>+
> >>                 } else if (charsetEnc != null) {
> >>
> >>                     msgContext
> >>-                            .setProperty(
> >>-                                    MessageContext.CHARACTER_SET_ENCODING,
> >>+                            .setProperty(MessageContext.CHARACTER_SET_ENCODING,
> >>                                     charsetEnc);
> >>                 }
> >>             }
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> 
> 
> 
> Index: src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
> ===================================================================
> --- src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (revision 278997)
> +++ src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (working copy)
> @@ -237,16 +237,26 @@
> 
>          public byte[] writeBytes() throws AxisFault {
>              try {
> +
>                  ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
> -                XMLStreamWriter outputWriter =
> -                        XMLOutputFactory.newInstance().createXMLStreamWriter(
> -                                bytesOut,
> -                                charSetEnc);
> -                OMOutputImpl out = new OMOutputImpl(outputWriter);
> -                out.setCharSetEncoding(charSetEnc);
> -                element.serialize(out);
> -                out.flush();
> -                return bytesOut.toByteArray();
> +
> +                if (!doingMTOM) {
> +                    XMLStreamWriter outputWriter =
> +                            XMLOutputFactory.newInstance()
> +                            .createXMLStreamWriter(bytesOut,
> +                                    charSetEnc);
> +                    OMOutputImpl output = new OMOutputImpl(outputWriter);
> +                    output.setCharSetEncoding(charSetEnc);
> +                    element.serialize(output);
> +                    output.flush();
> +                    return bytesOut.toByteArray();
> +                } else {
> +                    omOutput.setCharSetEncoding(charSetEnc);
> +                    omOutput.setOutputStream(bytesOut, true);  //changed...
> +                    element.serialize(omOutput);
> +                    omOutput.flush();
> +                    return bytesOut.toByteArray();
> +                }
>              } catch (XMLStreamException e) {
>                  throw new AxisFault(e);
>              } catch (FactoryConfigurationError e) {
> @@ -254,20 +264,36 @@
>              }
>          }
> 
> +        private void handleOMOutput(OutputStream out, boolean doingMTOM)
> +                throws XMLStreamException {
> +            omOutput.setOutputStream(out, doingMTOM);
> +            element.serialize(omOutput);
> +            omOutput.flush();
> +        }
> +
>          public void writeRequest(OutputStream out) throws IOException {
>              try {
> -                if (chuncked || doingMTOM) {
> -                    omOutput.setOutputStream(out, doingMTOM);
> -                    element.serialize(omOutput);
> -                    omOutput.flush();
> +                if (doingMTOM) { //chagened ..
> +                    if (chuncked) {
> +                        this.handleOMOutput(out, doingMTOM);
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        out.write(bytes);
> +                    }
> 
>                  } else {
> -                    if (bytes == null) {
> -                        bytes = writeBytes();
> +                    if (chuncked) {
> +                        this.handleOMOutput(out, doingMTOM);
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        out.write(bytes);
>                      }
> -                    out.write(bytes);
>                  }
> -               out.flush();
> +                out.flush();
>              } catch (XMLStreamException e) {
>                  throw new AxisFault(e);
>              } catch (FactoryConfigurationError e) {
> @@ -279,13 +305,24 @@
> 
>          public long getContentLength() {
>              try {
> -                if (chuncked || doingMTOM) {
> -                    return -1;
> +                if (doingMTOM) {    //chagened
> +                    if (chuncked) {
> +                        return -1;
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        return bytes.length;
> +                    }
>                  } else {
> -                    if (bytes == null) {
> -                        bytes = writeBytes();
> +                    if (chuncked) {
> +                        return -1;
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        return bytes.length;
>                      }
> -                    return bytes.length;
>                  }
>              } catch (AxisFault e) {
>                  return -1;
> 
> 
> 


-- 
Davanum Srinivas : http://wso2.com/ - Oxygenating The Web Service Platform

Re: [Axis2] Upgraded transport sender

Posted by Saminda Abeyruwan <sa...@opensource.lk>.
Davanum Srinivas wrote:

>too many whitespaces :( can't really say what changed :( :(
> 
>-- dims
>  
>
Sorry for the inconvenience caused with prior patch. More clearer path 
is apply herewith.

Thanks

Saminda

>On 9/6/05, Saminda Abeyruwan <sa...@opensource.lk> wrote:
>  
>
>>Hi all,
>>
>>CommonsHttpTransportSender being changed to support chunking on/off,
>>when optimized content is present. In order to switch on/off axis2.xml
>>need to be modified as follows.
>>
>>.....
>><transportSender name="http"
>>class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
>>        <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
>>        <parameter name="Transfer-Encoding"
>>locked="false">chunked</parameter>
>></transportSender>
>>....
>>
>>Please apply this patch. Thanks
>>
>>Saminda
>>
>>
>>Index: src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
>>===================================================================
>>--- src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (revision 278977)
>>+++ src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (working copy)
>>@@ -69,15 +69,17 @@
>>     public void invoke(MessageContext msgContext) throws AxisFault {
>>         try {
>>             String charSetEnc =
>>-                    (String) msgContext.getProperty(
>>-                            MessageContext.CHARACTER_SET_ENCODING);
>>+                    (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>>             if (charSetEnc != null) {
>>                 omOutput.setCharSetEncoding(charSetEnc);
>>             } else {
>>                 OperationContext opctx = msgContext.getOperationContext();
>>-                if(opctx != null) {
>>-                    charSetEnc = (String)opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>>+
>>+                if (opctx != null) {
>>+                    charSetEnc =
>>+                            (String) opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>>                 }
>>+
>>             }
>>             /**
>>              * If the char set enc is still not found use the default
>>@@ -85,10 +87,12 @@
>>             if(charSetEnc == null) {
>>                 charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
>>             }
>>+
>>             msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
>>             omOutput.setSoap11(msgContext.isSOAP11());
>>             omOutput.setDoOptimize(msgContext.isDoingMTOM());
>>
>>+
>>             omOutput.setCharSetEncoding(charSetEnc);
>>
>>             //Check for the REST behaviour, if you desire rest beahaviour
>>@@ -96,10 +100,12 @@
>>             // server.xml/client.xml file
>>             EndpointReference epr = null;
>>             if (msgContext.getTo() != null
>>-                    && !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(
>>-                            msgContext.getTo().getAddress())
>>-                    && !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(
>>-                            msgContext.getTo().getAddress())) {
>>+                    &&
>>+                    !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
>>+                    .getAddress())
>>+                    &&
>>+                    !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
>>+                    .getAddress())) {
>>                 epr = msgContext.getTo();
>>             }
>>
>>@@ -115,26 +121,24 @@
>>                 writeMessageWithCommons(msgContext, epr, dataOut);
>>             } else {
>>                 OutputStream out =
>>-                        (OutputStream) msgContext.getProperty(
>>-                                MessageContext.TRANSPORT_OUT);
>>+                        (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
>>                 if (msgContext.isServerSide()) {
>>                     HTTPOutTransportInfo transportInfo =
>>-                            (HTTPOutTransportInfo) msgContext.getProperty(
>>-                                    HTTPConstants.HTTPOutTransportInfo);
>>+                            (HTTPOutTransportInfo) msgContext.getProperty(HTTPConstants.HTTPOutTransportInfo);
>>                     if (transportInfo != null) {
>>                         omOutput.setSoap11(msgContext.isSOAP11());
>>                         transportInfo.setContentType(omOutput.getContentType());
>>-                    }else{
>>-                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo + " does not set");
>>+                    } else {
>>+                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo +
>>+                                " does not set");
>>                     }
>>                 }
>>                 omOutput.setOutputStream(out, msgContext.isDoingMTOM());
>>                 dataOut.serialize(omOutput);
>>                 omOutput.flush();
>>             }
>>-            if(msgContext.getOperationContext() != null){
>>-                msgContext.getOperationContext().setProperty(
>>-                        Constants.RESPONSE_WRITTEN,
>>+            if (msgContext.getOperationContext() != null) {
>>+                msgContext.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN,
>>                         Constants.VALUE_TRUE);
>>             }
>>         } catch (XMLStreamException e) {
>>@@ -146,16 +150,14 @@
>>         }
>>     }
>>
>>-    public void writeMessageWithToOutPutStream(
>>-            MessageContext msgContext,
>>-            OutputStream out) {
>>+    public void writeMessageWithToOutPutStream(MessageContext msgContext,
>>+                                               OutputStream out) {
>>
>>     }
>>
>>-    public void writeMessageWithCommons(
>>-            MessageContext msgContext,
>>-            EndpointReference toURL,
>>-            OMElement dataout)
>>+    public void writeMessageWithCommons(MessageContext msgContext,
>>+                                        EndpointReference toURL,
>>+                                        OMElement dataout)
>>             throws AxisFault {
>>         try {
>>             URL url = new URL(toURL.getAddress());
>>@@ -170,16 +172,14 @@
>>             //supporting RESTFacility..
>>
>>             if (!msgContext.isDoingREST()) {
>>-                this.transportConfigurationPOST(
>>-                        msgContext,
>>+                this.transportConfigurationPOST(msgContext,
>>                         dataout,
>>                         url,
>>                         soapActionString);
>>             }
>>             if (msgContext.isDoingREST()) {
>>                 if (msgContext.isRestThroughPOST()) {
>>-                    this.transportConfigurationPOST(
>>-                            msgContext,
>>+                    this.transportConfigurationPOST(msgContext,
>>                             dataout,
>>                             url,
>>                             soapActionString);
>>@@ -196,13 +196,12 @@
>>         }
>>
>>     }
>>-    protected HostConfiguration getHostConfiguration(
>>-            MessageContext context,
>>-            URL targetURL) {
>>+
>>+    protected HostConfiguration getHostConfiguration(MessageContext context,
>>+                                                     URL targetURL) {
>>         //TODO cheaking wheather the host is a proxy
>>         HostConfiguration config = new HostConfiguration();
>>-        config.setHost(
>>-                targetURL.getHost(),
>>+        config.setHost(targetURL.getHost(),
>>                 targetURL.getPort() == -1 ? 80 : targetURL.getPort());
>>         return config;
>>     }
>>@@ -220,11 +219,10 @@
>>
>>         private boolean doingMTOM = false;
>>
>>-        public AxisRequestEntity(
>>-                OMElement element,
>>-                boolean chuncked,
>>-                boolean doingMTOM,
>>-                String charSetEncoding) {
>>+        public AxisRequestEntity(OMElement element,
>>+                                 boolean chuncked,
>>+                                 boolean doingMTOM,
>>+                                 String charSetEncoding) {
>>             this.element = element;
>>             this.chuncked = chuncked;
>>             this.doingMTOM = doingMTOM;
>>@@ -237,16 +235,26 @@
>>
>>         public byte[] writeBytes() throws AxisFault {
>>             try {
>>+
>>                 ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
>>-                XMLStreamWriter outputWriter =
>>-                        XMLOutputFactory.newInstance().createXMLStreamWriter(
>>-                                bytesOut,
>>-                                charSetEnc);
>>-                OMOutputImpl out = new OMOutputImpl(outputWriter);
>>-                out.setCharSetEncoding(charSetEnc);
>>-                element.serialize(out);
>>-                out.flush();
>>-                return bytesOut.toByteArray();
>>+
>>+                if (!doingMTOM) {
>>+                    XMLStreamWriter outputWriter =
>>+                            XMLOutputFactory.newInstance()
>>+                            .createXMLStreamWriter(bytesOut,
>>+                                    charSetEnc);
>>+                    OMOutputImpl output = new OMOutputImpl(outputWriter);
>>+                    output.setCharSetEncoding(charSetEnc);
>>+                    element.serialize(output);
>>+                    output.flush();
>>+                    return bytesOut.toByteArray();
>>+                } else {
>>+                    omOutput.setCharSetEncoding(charSetEnc);
>>+                    omOutput.setOutputStream(bytesOut, true);  //changed...
>>+                    element.serialize(omOutput);
>>+                    omOutput.flush();
>>+                    return bytesOut.toByteArray();
>>+                }
>>             } catch (XMLStreamException e) {
>>                 throw new AxisFault(e);
>>             } catch (FactoryConfigurationError e) {
>>@@ -254,20 +262,36 @@
>>             }
>>         }
>>
>>+        private void handleOMOutput(OutputStream out, boolean doingMTOM)
>>+                throws XMLStreamException {
>>+            omOutput.setOutputStream(out, doingMTOM);
>>+            element.serialize(omOutput);
>>+            omOutput.flush();
>>+        }
>>+
>>         public void writeRequest(OutputStream out) throws IOException {
>>             try {
>>-                if (chuncked || doingMTOM) {
>>-                    omOutput.setOutputStream(out, doingMTOM);
>>-                    element.serialize(omOutput);
>>-                    omOutput.flush();
>>+                if (doingMTOM) { //chagened ..
>>+                    if (chuncked) {
>>+                        this.handleOMOutput(out, doingMTOM);
>>+                    } else {
>>+                        if (bytes == null) {
>>+                            bytes = writeBytes();
>>+                        }
>>+                        out.write(bytes);
>>+                    }
>>
>>                 } else {
>>-                    if (bytes == null) {
>>-                        bytes = writeBytes();
>>+                    if (chuncked) {
>>+                        this.handleOMOutput(out, doingMTOM);
>>+                    } else {
>>+                        if (bytes == null) {
>>+                            bytes = writeBytes();
>>+                        }
>>+                        out.write(bytes);
>>                     }
>>-                    out.write(bytes);
>>                 }
>>-               out.flush();
>>+                out.flush();
>>             } catch (XMLStreamException e) {
>>                 throw new AxisFault(e);
>>             } catch (FactoryConfigurationError e) {
>>@@ -279,13 +303,24 @@
>>
>>         public long getContentLength() {
>>             try {
>>-                if (chuncked || doingMTOM) {
>>-                    return -1;
>>+                if (doingMTOM) {    //chagened
>>+                    if (chuncked) {
>>+                        return -1;
>>+                    } else {
>>+                        if (bytes == null) {
>>+                            bytes = writeBytes();
>>+                        }
>>+                        return bytes.length;
>>+                    }
>>                 } else {
>>-                    if (bytes == null) {
>>-                        bytes = writeBytes();
>>+                    if (chuncked) {
>>+                        return -1;
>>+                    } else {
>>+                        if (bytes == null) {
>>+                            bytes = writeBytes();
>>+                        }
>>+                        return bytes.length;
>>                     }
>>-                    return bytes.length;
>>                 }
>>             } catch (AxisFault e) {
>>                 return -1;
>>@@ -311,9 +346,8 @@
>>
>>     }
>>
>>-    public void init(
>>-            ConfigurationContext confContext,
>>-            TransportOutDescription transportOut)
>>+    public void init(ConfigurationContext confContext,
>>+                     TransportOutDescription transportOut)
>>             throws AxisFault {
>>         //<parameter name="PROTOCOL" locked="false">HTTP/1.0</parameter> or
>>         //<parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> is
>>@@ -324,19 +358,17 @@
>>             if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
>>                 this.httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
>>                 Parameter transferEncoding =
>>-                        transportOut.getParameter(
>>-                                HTTPConstants.HEADER_TRANSFER_ENCODING);
>>+                        transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
>>                 if (transferEncoding != null
>>-                        && HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(
>>-                                transferEncoding.getValue())) {
>>+                        &&
>>+                        HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding.getValue())) {
>>                     this.chuncked = true;
>>                 }
>>             } else if (
>>                     HTTPConstants.HEADER_PROTOCOL_10.equals(version.getValue())) {
>>                 this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
>>             } else {
>>-                throw new AxisFault(
>>-                        "Parameter "
>>+                throw new AxisFault("Parameter "
>>                         + HTTPConstants.PROTOCOL_VERSION
>>                         + " Can have values only HTTP/1.0 or HTTP/1.1");
>>             }
>>@@ -344,11 +376,10 @@
>>
>>     }
>>
>>-    private void transportConfigurationPOST(
>>-            MessageContext msgContext,
>>-            OMElement dataout,
>>-            URL url,
>>-            String soapActionString)
>>+    private void transportConfigurationPOST(MessageContext msgContext,
>>+                                            OMElement dataout,
>>+                                            URL url,
>>+                                            String soapActionString)
>>             throws MalformedURLException, AxisFault, IOException {
>>
>>         //execuite the HtttpMethodBase - a connection manager can be given for handle multiple
>>@@ -367,29 +398,24 @@
>>         msgContext.setProperty(HTTP_METHOD, postMethod);
>>
>>         String charEncoding =
>>-                (String) msgContext.getProperty(
>>-                        MessageContext.CHARACTER_SET_ENCODING);
>>-        if(charEncoding == null){
>>+                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>>+        if (charEncoding == null) {
>>             charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
>>         }
>>
>>-        postMethod.setRequestEntity(
>>-                new AxisRequestEntity(
>>-                        dataout,
>>-                        chuncked,
>>-                        msgContext.isDoingMTOM(),
>>-                        charEncoding));
>>+        postMethod.setRequestEntity(new AxisRequestEntity(dataout,
>>+                chuncked,
>>+                msgContext.isDoingMTOM(),
>>+                charEncoding));
>>
>>         if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)
>>                 && chuncked) {
>>             postMethod.setContentChunked(true);
>>         }
>>-        postMethod.setRequestHeader(
>>-                HTTPConstants.HEADER_USER_AGENT,
>>+        postMethod.setRequestHeader(HTTPConstants.HEADER_USER_AGENT,
>>                 "Axis/2.0");
>>         if (!msgContext.isDoingREST()) {
>>-            postMethod.setRequestHeader(
>>-                    HTTPConstants.HEADER_SOAP_ACTION,
>>+            postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION,
>>                     soapActionString);
>>         }
>>         postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
>>@@ -397,57 +423,53 @@
>>             if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
>>                 //postMethod.setHttp11(false); todo method to findout the transport version...
>>                 //allowing keep-alive for 1.0
>>-                postMethod.setRequestHeader(
>>-                        HTTPConstants.HEADER_CONNECTION,
>>+                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
>>                         HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
>>             } else {
>>                 // allowing keep-alive for 1.1
>>-                postMethod.setRequestHeader(
>>-                        HTTPConstants.HEADER_CONNECTION,
>>+                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
>>                         HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
>>-                postMethod.setRequestHeader(
>>-                        HTTPConstants.HEADER_EXPECT,
>>+                postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
>>                         HTTPConstants.HEADER_EXPECT_100_Continue);
>>             }
>>         }
>>-
>>+
>>         this.httpClient.executeMethod(postMethod);
>>
>>         if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
>>             processResponse(postMethod, msgContext);
>>         } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
>>             return;
>>-        } else  if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
>>+        } else if (postMethod.getStatusCode() ==
>>+                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
>>
>>-            Header contenttypeHheader = postMethod.getResponseHeader(
>>-                    HTTPConstants.HEADER_CONTENT_TYPE);
>>+            Header contenttypeHheader = postMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
>>
>>             String value = contenttypeHheader.getValue();
>>-            if(value != null){
>>-                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
>>-                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
>>+            if (value != null) {
>>+                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
>>+                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
>>+                        0) {
>>                     processResponse(postMethod, msgContext);
>>                 }
>>             }
>>-        }else{
>>-            throw new AxisFault(
>>-                    Messages.getMessage(
>>-                            "transportError",
>>-                            String.valueOf(postMethod.getStatusCode()),
>>-                            postMethod.getResponseBodyAsString()));
>>+        } else {
>>+            throw new AxisFault(Messages.getMessage("transportError",
>>+                    String.valueOf(postMethod.getStatusCode()),
>>+                    postMethod.getResponseBodyAsString()));
>>         }
>>
>>     }
>>
>>-    private void processResponse(HttpMethodBase httpMethod, MessageContext msgContext) throws IOException {
>>+    private void processResponse(HttpMethodBase httpMethod,
>>+                                 MessageContext msgContext) throws IOException {
>>         obatainHTTPHeaderInformation(httpMethod, msgContext);
>>         InputStream in = httpMethod.getResponseBodyAsStream();
>>         if (in == null) {
>>-            throw new AxisFault(
>>-                    Messages.getMessage("canNotBeNull", "InputStream"));
>>+            throw new AxisFault(Messages.getMessage("canNotBeNull",
>>+                    "InputStream"));
>>         }
>>-        msgContext.getOperationContext().setProperty(
>>-                MessageContext.TRANSPORT_IN,
>>+        msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN,
>>                 in);
>>     }
>>
>>@@ -457,16 +479,13 @@
>>         getMethod.setPath(url.getFile());
>>
>>         String charEncoding =
>>-                (String) msgContext.getProperty(
>>-                        MessageContext.CHARACTER_SET_ENCODING);
>>+                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>>         if (charEncoding == null) //Default encoding scheme
>>-            getMethod.setRequestHeader(
>>-                    HTTPConstants.HEADER_CONTENT_TYPE,
>>+            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
>>                     "text/xml; charset="
>>                     + MessageContext.DEFAULT_CHAR_SET_ENCODING);
>>         else
>>-            getMethod.setRequestHeader(
>>-                    HTTPConstants.HEADER_CONTENT_TYPE,
>>+            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
>>                     "text/xml; charset=" + charEncoding);
>>
>>         this.httpClient = new HttpClient();
>>@@ -490,34 +509,35 @@
>> //                    in);
>>         } else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
>>             return;
>>-        }else  if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
>>+        } else if (getMethod.getStatusCode() ==
>>+                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
>>
>>-            Header contenttypeHheader = getMethod.getResponseHeader(
>>-                    HTTPConstants.HEADER_CONTENT_TYPE);
>>+            Header contenttypeHheader = getMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
>>
>>-             String value = contenttypeHheader.getValue();
>>-            if(value != null){
>>-                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
>>-                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
>>+            String value = contenttypeHheader.getValue();
>>+            if (value != null) {
>>+                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
>>+                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
>>+                        0) {
>>                     processResponse(getMethod, msgContext);
>>                 }
>>
>>             }
>>-        }else{
>>-            throw new AxisFault(
>>-                    Messages.getMessage(
>>-                            "transportError",
>>-                            String.valueOf(getMethod.getStatusCode()),
>>-                            getMethod.getResponseBodyAsString()));
>>+        } else {
>>+            throw new AxisFault(Messages.getMessage("transportError",
>>+                    String.valueOf(getMethod.getStatusCode()),
>>+                    getMethod.getResponseBodyAsString()));
>>         }
>>     }
>>
>>     /**
>>      * Collect the HTTP header information and set them in the message context
>>+     *
>>      * @param method
>>      * @param msgContext
>>      */
>>-    private void obatainHTTPHeaderInformation(HttpMethodBase method,MessageContext msgContext) {
>>+    private void obatainHTTPHeaderInformation(HttpMethodBase method,
>>+                                              MessageContext msgContext) {
>>         Header header =
>>                 method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
>>         if (header != null) {
>>@@ -527,20 +547,22 @@
>>                         .getParameterByName(HTTPConstants.CHAR_SET_ENCODING);
>>                 if (headers[i]
>>                         .getName()
>>-                        .equalsIgnoreCase(
>>-                                HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
>>+                        .equalsIgnoreCase(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
>>                     OperationContext opContext =
>>                             msgContext.getOperationContext();
>>                     if (opContext != null) {
>>-                        opContext.setProperty(
>>-                                HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
>>+                        opContext.setProperty(HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
>>                                 header.getValue());
>>                     }
>>+                    if (charsetEnc != null) {
>>+                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
>>+                                charsetEnc);
>>+                    }
>>+
>>                 } else if (charsetEnc != null) {
>>
>>                     msgContext
>>-                            .setProperty(
>>-                                    MessageContext.CHARACTER_SET_ENCODING,
>>+                            .setProperty(MessageContext.CHARACTER_SET_ENCODING,
>>                                     charsetEnc);
>>                 }
>>             }
>>
>>
>>
>>    
>>
>
>
>  
>


Re: [Axis2] Upgraded transport sender

Posted by Davanum Srinivas <da...@gmail.com>.
too many whitespaces :( can't really say what changed :( :(
 
-- dims

On 9/6/05, Saminda Abeyruwan <sa...@opensource.lk> wrote:
> Hi all,
> 
> CommonsHttpTransportSender being changed to support chunking on/off,
> when optimized content is present. In order to switch on/off axis2.xml
> need to be modified as follows.
> 
> .....
> <transportSender name="http"
> class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
>         <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
>         <parameter name="Transfer-Encoding"
> locked="false">chunked</parameter>
> </transportSender>
> ....
> 
> Please apply this patch. Thanks
> 
> Saminda
> 
> 
> Index: src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
> ===================================================================
> --- src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (revision 278977)
> +++ src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (working copy)
> @@ -69,15 +69,17 @@
>      public void invoke(MessageContext msgContext) throws AxisFault {
>          try {
>              String charSetEnc =
> -                    (String) msgContext.getProperty(
> -                            MessageContext.CHARACTER_SET_ENCODING);
> +                    (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>              if (charSetEnc != null) {
>                  omOutput.setCharSetEncoding(charSetEnc);
>              } else {
>                  OperationContext opctx = msgContext.getOperationContext();
> -                if(opctx != null) {
> -                    charSetEnc = (String)opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> +
> +                if (opctx != null) {
> +                    charSetEnc =
> +                            (String) opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>                  }
> +
>              }
>              /**
>               * If the char set enc is still not found use the default
> @@ -85,10 +87,12 @@
>              if(charSetEnc == null) {
>                  charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
>              }
> +
>              msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
>              omOutput.setSoap11(msgContext.isSOAP11());
>              omOutput.setDoOptimize(msgContext.isDoingMTOM());
> 
> +
>              omOutput.setCharSetEncoding(charSetEnc);
> 
>              //Check for the REST behaviour, if you desire rest beahaviour
> @@ -96,10 +100,12 @@
>              // server.xml/client.xml file
>              EndpointReference epr = null;
>              if (msgContext.getTo() != null
> -                    && !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(
> -                            msgContext.getTo().getAddress())
> -                    && !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(
> -                            msgContext.getTo().getAddress())) {
> +                    &&
> +                    !AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
> +                    .getAddress())
> +                    &&
> +                    !AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(msgContext.getTo()
> +                    .getAddress())) {
>                  epr = msgContext.getTo();
>              }
> 
> @@ -115,26 +121,24 @@
>                  writeMessageWithCommons(msgContext, epr, dataOut);
>              } else {
>                  OutputStream out =
> -                        (OutputStream) msgContext.getProperty(
> -                                MessageContext.TRANSPORT_OUT);
> +                        (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
>                  if (msgContext.isServerSide()) {
>                      HTTPOutTransportInfo transportInfo =
> -                            (HTTPOutTransportInfo) msgContext.getProperty(
> -                                    HTTPConstants.HTTPOutTransportInfo);
> +                            (HTTPOutTransportInfo) msgContext.getProperty(HTTPConstants.HTTPOutTransportInfo);
>                      if (transportInfo != null) {
>                          omOutput.setSoap11(msgContext.isSOAP11());
>                          transportInfo.setContentType(omOutput.getContentType());
> -                    }else{
> -                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo + " does not set");
> +                    } else {
> +                        throw new AxisFault(HTTPConstants.HTTPOutTransportInfo +
> +                                " does not set");
>                      }
>                  }
>                  omOutput.setOutputStream(out, msgContext.isDoingMTOM());
>                  dataOut.serialize(omOutput);
>                  omOutput.flush();
>              }
> -            if(msgContext.getOperationContext() != null){
> -                msgContext.getOperationContext().setProperty(
> -                        Constants.RESPONSE_WRITTEN,
> +            if (msgContext.getOperationContext() != null) {
> +                msgContext.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN,
>                          Constants.VALUE_TRUE);
>              }
>          } catch (XMLStreamException e) {
> @@ -146,16 +150,14 @@
>          }
>      }
> 
> -    public void writeMessageWithToOutPutStream(
> -            MessageContext msgContext,
> -            OutputStream out) {
> +    public void writeMessageWithToOutPutStream(MessageContext msgContext,
> +                                               OutputStream out) {
> 
>      }
> 
> -    public void writeMessageWithCommons(
> -            MessageContext msgContext,
> -            EndpointReference toURL,
> -            OMElement dataout)
> +    public void writeMessageWithCommons(MessageContext msgContext,
> +                                        EndpointReference toURL,
> +                                        OMElement dataout)
>              throws AxisFault {
>          try {
>              URL url = new URL(toURL.getAddress());
> @@ -170,16 +172,14 @@
>              //supporting RESTFacility..
> 
>              if (!msgContext.isDoingREST()) {
> -                this.transportConfigurationPOST(
> -                        msgContext,
> +                this.transportConfigurationPOST(msgContext,
>                          dataout,
>                          url,
>                          soapActionString);
>              }
>              if (msgContext.isDoingREST()) {
>                  if (msgContext.isRestThroughPOST()) {
> -                    this.transportConfigurationPOST(
> -                            msgContext,
> +                    this.transportConfigurationPOST(msgContext,
>                              dataout,
>                              url,
>                              soapActionString);
> @@ -196,13 +196,12 @@
>          }
> 
>      }
> -    protected HostConfiguration getHostConfiguration(
> -            MessageContext context,
> -            URL targetURL) {
> +
> +    protected HostConfiguration getHostConfiguration(MessageContext context,
> +                                                     URL targetURL) {
>          //TODO cheaking wheather the host is a proxy
>          HostConfiguration config = new HostConfiguration();
> -        config.setHost(
> -                targetURL.getHost(),
> +        config.setHost(targetURL.getHost(),
>                  targetURL.getPort() == -1 ? 80 : targetURL.getPort());
>          return config;
>      }
> @@ -220,11 +219,10 @@
> 
>          private boolean doingMTOM = false;
> 
> -        public AxisRequestEntity(
> -                OMElement element,
> -                boolean chuncked,
> -                boolean doingMTOM,
> -                String charSetEncoding) {
> +        public AxisRequestEntity(OMElement element,
> +                                 boolean chuncked,
> +                                 boolean doingMTOM,
> +                                 String charSetEncoding) {
>              this.element = element;
>              this.chuncked = chuncked;
>              this.doingMTOM = doingMTOM;
> @@ -237,16 +235,26 @@
> 
>          public byte[] writeBytes() throws AxisFault {
>              try {
> +
>                  ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
> -                XMLStreamWriter outputWriter =
> -                        XMLOutputFactory.newInstance().createXMLStreamWriter(
> -                                bytesOut,
> -                                charSetEnc);
> -                OMOutputImpl out = new OMOutputImpl(outputWriter);
> -                out.setCharSetEncoding(charSetEnc);
> -                element.serialize(out);
> -                out.flush();
> -                return bytesOut.toByteArray();
> +
> +                if (!doingMTOM) {
> +                    XMLStreamWriter outputWriter =
> +                            XMLOutputFactory.newInstance()
> +                            .createXMLStreamWriter(bytesOut,
> +                                    charSetEnc);
> +                    OMOutputImpl output = new OMOutputImpl(outputWriter);
> +                    output.setCharSetEncoding(charSetEnc);
> +                    element.serialize(output);
> +                    output.flush();
> +                    return bytesOut.toByteArray();
> +                } else {
> +                    omOutput.setCharSetEncoding(charSetEnc);
> +                    omOutput.setOutputStream(bytesOut, true);  //changed...
> +                    element.serialize(omOutput);
> +                    omOutput.flush();
> +                    return bytesOut.toByteArray();
> +                }
>              } catch (XMLStreamException e) {
>                  throw new AxisFault(e);
>              } catch (FactoryConfigurationError e) {
> @@ -254,20 +262,36 @@
>              }
>          }
> 
> +        private void handleOMOutput(OutputStream out, boolean doingMTOM)
> +                throws XMLStreamException {
> +            omOutput.setOutputStream(out, doingMTOM);
> +            element.serialize(omOutput);
> +            omOutput.flush();
> +        }
> +
>          public void writeRequest(OutputStream out) throws IOException {
>              try {
> -                if (chuncked || doingMTOM) {
> -                    omOutput.setOutputStream(out, doingMTOM);
> -                    element.serialize(omOutput);
> -                    omOutput.flush();
> +                if (doingMTOM) { //chagened ..
> +                    if (chuncked) {
> +                        this.handleOMOutput(out, doingMTOM);
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        out.write(bytes);
> +                    }
> 
>                  } else {
> -                    if (bytes == null) {
> -                        bytes = writeBytes();
> +                    if (chuncked) {
> +                        this.handleOMOutput(out, doingMTOM);
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        out.write(bytes);
>                      }
> -                    out.write(bytes);
>                  }
> -               out.flush();
> +                out.flush();
>              } catch (XMLStreamException e) {
>                  throw new AxisFault(e);
>              } catch (FactoryConfigurationError e) {
> @@ -279,13 +303,24 @@
> 
>          public long getContentLength() {
>              try {
> -                if (chuncked || doingMTOM) {
> -                    return -1;
> +                if (doingMTOM) {    //chagened
> +                    if (chuncked) {
> +                        return -1;
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        return bytes.length;
> +                    }
>                  } else {
> -                    if (bytes == null) {
> -                        bytes = writeBytes();
> +                    if (chuncked) {
> +                        return -1;
> +                    } else {
> +                        if (bytes == null) {
> +                            bytes = writeBytes();
> +                        }
> +                        return bytes.length;
>                      }
> -                    return bytes.length;
>                  }
>              } catch (AxisFault e) {
>                  return -1;
> @@ -311,9 +346,8 @@
> 
>      }
> 
> -    public void init(
> -            ConfigurationContext confContext,
> -            TransportOutDescription transportOut)
> +    public void init(ConfigurationContext confContext,
> +                     TransportOutDescription transportOut)
>              throws AxisFault {
>          //<parameter name="PROTOCOL" locked="false">HTTP/1.0</parameter> or
>          //<parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter> is
> @@ -324,19 +358,17 @@
>              if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
>                  this.httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
>                  Parameter transferEncoding =
> -                        transportOut.getParameter(
> -                                HTTPConstants.HEADER_TRANSFER_ENCODING);
> +                        transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
>                  if (transferEncoding != null
> -                        && HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(
> -                                transferEncoding.getValue())) {
> +                        &&
> +                        HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding.getValue())) {
>                      this.chuncked = true;
>                  }
>              } else if (
>                      HTTPConstants.HEADER_PROTOCOL_10.equals(version.getValue())) {
>                  this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
>              } else {
> -                throw new AxisFault(
> -                        "Parameter "
> +                throw new AxisFault("Parameter "
>                          + HTTPConstants.PROTOCOL_VERSION
>                          + " Can have values only HTTP/1.0 or HTTP/1.1");
>              }
> @@ -344,11 +376,10 @@
> 
>      }
> 
> -    private void transportConfigurationPOST(
> -            MessageContext msgContext,
> -            OMElement dataout,
> -            URL url,
> -            String soapActionString)
> +    private void transportConfigurationPOST(MessageContext msgContext,
> +                                            OMElement dataout,
> +                                            URL url,
> +                                            String soapActionString)
>              throws MalformedURLException, AxisFault, IOException {
> 
>          //execuite the HtttpMethodBase - a connection manager can be given for handle multiple
> @@ -367,29 +398,24 @@
>          msgContext.setProperty(HTTP_METHOD, postMethod);
> 
>          String charEncoding =
> -                (String) msgContext.getProperty(
> -                        MessageContext.CHARACTER_SET_ENCODING);
> -        if(charEncoding == null){
> +                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> +        if (charEncoding == null) {
>              charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
>          }
> 
> -        postMethod.setRequestEntity(
> -                new AxisRequestEntity(
> -                        dataout,
> -                        chuncked,
> -                        msgContext.isDoingMTOM(),
> -                        charEncoding));
> +        postMethod.setRequestEntity(new AxisRequestEntity(dataout,
> +                chuncked,
> +                msgContext.isDoingMTOM(),
> +                charEncoding));
> 
>          if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)
>                  && chuncked) {
>              postMethod.setContentChunked(true);
>          }
> -        postMethod.setRequestHeader(
> -                HTTPConstants.HEADER_USER_AGENT,
> +        postMethod.setRequestHeader(HTTPConstants.HEADER_USER_AGENT,
>                  "Axis/2.0");
>          if (!msgContext.isDoingREST()) {
> -            postMethod.setRequestHeader(
> -                    HTTPConstants.HEADER_SOAP_ACTION,
> +            postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION,
>                      soapActionString);
>          }
>          postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
> @@ -397,57 +423,53 @@
>              if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
>                  //postMethod.setHttp11(false); todo method to findout the transport version...
>                  //allowing keep-alive for 1.0
> -                postMethod.setRequestHeader(
> -                        HTTPConstants.HEADER_CONNECTION,
> +                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
>                          HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
>              } else {
>                  // allowing keep-alive for 1.1
> -                postMethod.setRequestHeader(
> -                        HTTPConstants.HEADER_CONNECTION,
> +                postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
>                          HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
> -                postMethod.setRequestHeader(
> -                        HTTPConstants.HEADER_EXPECT,
> +                postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
>                          HTTPConstants.HEADER_EXPECT_100_Continue);
>              }
>          }
> -
> +
>          this.httpClient.executeMethod(postMethod);
> 
>          if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
>              processResponse(postMethod, msgContext);
>          } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
>              return;
> -        } else  if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
> +        } else if (postMethod.getStatusCode() ==
> +                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
> 
> -            Header contenttypeHheader = postMethod.getResponseHeader(
> -                    HTTPConstants.HEADER_CONTENT_TYPE);
> +            Header contenttypeHheader = postMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
> 
>              String value = contenttypeHheader.getValue();
> -            if(value != null){
> -                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
> -                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
> +            if (value != null) {
> +                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
> +                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
> +                        0) {
>                      processResponse(postMethod, msgContext);
>                  }
>              }
> -        }else{
> -            throw new AxisFault(
> -                    Messages.getMessage(
> -                            "transportError",
> -                            String.valueOf(postMethod.getStatusCode()),
> -                            postMethod.getResponseBodyAsString()));
> +        } else {
> +            throw new AxisFault(Messages.getMessage("transportError",
> +                    String.valueOf(postMethod.getStatusCode()),
> +                    postMethod.getResponseBodyAsString()));
>          }
> 
>      }
> 
> -    private void processResponse(HttpMethodBase httpMethod, MessageContext msgContext) throws IOException {
> +    private void processResponse(HttpMethodBase httpMethod,
> +                                 MessageContext msgContext) throws IOException {
>          obatainHTTPHeaderInformation(httpMethod, msgContext);
>          InputStream in = httpMethod.getResponseBodyAsStream();
>          if (in == null) {
> -            throw new AxisFault(
> -                    Messages.getMessage("canNotBeNull", "InputStream"));
> +            throw new AxisFault(Messages.getMessage("canNotBeNull",
> +                    "InputStream"));
>          }
> -        msgContext.getOperationContext().setProperty(
> -                MessageContext.TRANSPORT_IN,
> +        msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN,
>                  in);
>      }
> 
> @@ -457,16 +479,13 @@
>          getMethod.setPath(url.getFile());
> 
>          String charEncoding =
> -                (String) msgContext.getProperty(
> -                        MessageContext.CHARACTER_SET_ENCODING);
> +                (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
>          if (charEncoding == null) //Default encoding scheme
> -            getMethod.setRequestHeader(
> -                    HTTPConstants.HEADER_CONTENT_TYPE,
> +            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
>                      "text/xml; charset="
>                      + MessageContext.DEFAULT_CHAR_SET_ENCODING);
>          else
> -            getMethod.setRequestHeader(
> -                    HTTPConstants.HEADER_CONTENT_TYPE,
> +            getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
>                      "text/xml; charset=" + charEncoding);
> 
>          this.httpClient = new HttpClient();
> @@ -490,34 +509,35 @@
>  //                    in);
>          } else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
>              return;
> -        }else  if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
> +        } else if (getMethod.getStatusCode() ==
> +                HttpStatus.SC_INTERNAL_SERVER_ERROR) {
> 
> -            Header contenttypeHheader = getMethod.getResponseHeader(
> -                    HTTPConstants.HEADER_CONTENT_TYPE);
> +            Header contenttypeHheader = getMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
> 
> -             String value = contenttypeHheader.getValue();
> -            if(value != null){
> -                if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
> -                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
> +            String value = contenttypeHheader.getValue();
> +            if (value != null) {
> +                if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
> +                        value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=
> +                        0) {
>                      processResponse(getMethod, msgContext);
>                  }
> 
>              }
> -        }else{
> -            throw new AxisFault(
> -                    Messages.getMessage(
> -                            "transportError",
> -                            String.valueOf(getMethod.getStatusCode()),
> -                            getMethod.getResponseBodyAsString()));
> +        } else {
> +            throw new AxisFault(Messages.getMessage("transportError",
> +                    String.valueOf(getMethod.getStatusCode()),
> +                    getMethod.getResponseBodyAsString()));
>          }
>      }
> 
>      /**
>       * Collect the HTTP header information and set them in the message context
> +     *
>       * @param method
>       * @param msgContext
>       */
> -    private void obatainHTTPHeaderInformation(HttpMethodBase method,MessageContext msgContext) {
> +    private void obatainHTTPHeaderInformation(HttpMethodBase method,
> +                                              MessageContext msgContext) {
>          Header header =
>                  method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
>          if (header != null) {
> @@ -527,20 +547,22 @@
>                          .getParameterByName(HTTPConstants.CHAR_SET_ENCODING);
>                  if (headers[i]
>                          .getName()
> -                        .equalsIgnoreCase(
> -                                HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
> +                        .equalsIgnoreCase(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
>                      OperationContext opContext =
>                              msgContext.getOperationContext();
>                      if (opContext != null) {
> -                        opContext.setProperty(
> -                                HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
> +                        opContext.setProperty(HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
>                                  header.getValue());
>                      }
> +                    if (charsetEnc != null) {
> +                        msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
> +                                charsetEnc);
> +                    }
> +
>                  } else if (charsetEnc != null) {
> 
>                      msgContext
> -                            .setProperty(
> -                                    MessageContext.CHARACTER_SET_ENCODING,
> +                            .setProperty(MessageContext.CHARACTER_SET_ENCODING,
>                                      charsetEnc);
>                  }
>              }
> 
> 
> 


-- 
Davanum Srinivas : http://wso2.com/ - Oxygenating The Web Service Platform