axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thil...@apache.org
Subject svn commit: r492427 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http: CommonsHTTPTransportSender.java HTTPTransportUtils.java RESTRequestEntity.java SOAPOverHTTPSender.java SOAPRequestEntity.java
Date Thu, 04 Jan 2007 06:41:47 GMT
Author: thilina
Date: Wed Jan  3 22:41:46 2007
New Revision: 492427

URL: http://svn.apache.org/viewvc?view=rev&rev=492427
Log:
Improved and moved the logic to find charSetEncoding in to a Utils 
method.
Removed redundent tries to get CharSetEncoding from the message context, 
when we have it handy in the OMOutputFormat..

Removed unnecessary property look ups when the information is already 
present in OMOutputFormat....    


Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?view=diff&rev=492427&r1=492426&r2=492427
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
Wed Jan  3 22:41:46 2007
@@ -139,35 +139,13 @@
     public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
         try {
             OMOutputFormat format = new OMOutputFormat();
-            String charSetEnc =
-                    (String) msgContext
-                            .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-
-            if (charSetEnc != null) {
-                format.setCharSetEncoding(charSetEnc);
-            } else {
-                OperationContext opctx = msgContext.getOperationContext();
-
-                if (opctx != null) {
-                    charSetEnc = (String) opctx
-                            .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
-                }
-            }
-
-            /**
-             * If the char set enc is still not found use the default
-             */
-            if (charSetEnc == null) {
-                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
-            }
-
             msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
             msgContext.setDoingSwA(HTTPTransportUtils.doWriteSwA(msgContext));
             msgContext.setDoingREST(HTTPTransportUtils.isDoingREST(msgContext));
             format.setSOAP11(msgContext.isSOAP11());
             format.setDoOptimize(msgContext.isDoingMTOM());
             format.setDoingSWA(msgContext.isDoingSwA());
-            format.setCharSetEncoding(charSetEnc);
+            format.setCharSetEncoding(HTTPTransportUtils.getCharSetEncoding(msgContext));
 
             // Trasnport URL can be different from the WSA-To. So processing
             // that now.
@@ -208,7 +186,7 @@
                 if (msgContext.getProperty(MessageContext.TRANSPORT_OUT) != null) {
                     sendUsingOutputStream(msgContext, format, dataOut);
                 } else {
-                    throw new AxisFault("Both the TO and Property MessageContext.TRANSPORT_OUT
is Null, No where to send");
+                    throw new AxisFault("Both the TO and MessageContext.TRANSPORT_OUT property
are Null, No where to send");
                 }
             }
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?view=diff&rev=492427&r1=492426&r2=492427
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
Wed Jan  3 22:41:46 2007
@@ -42,6 +42,7 @@
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisEngine;
@@ -123,6 +124,34 @@
         }
         return enableSwA;
     }
+    
+    /**
+	 * Utility method to query CharSetEncoding. First look in the
+	 * MessageContext. If it's not there look in the OpContext. Use the defualt,
+	 * if it's not given in either contexts.
+	 * 
+	 * @param msgContext
+	 * @return CharSetEncoding
+	 */
+    public static String getCharSetEncoding(MessageContext msgContext) {
+		String charSetEnc = (String) msgContext
+				.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+
+		if (charSetEnc == null) {
+			OperationContext opctx = msgContext.getOperationContext();
+			if (opctx != null) {
+				charSetEnc = (String) opctx
+						.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+			}
+			/**
+			 * If the char set enc is still not found use the default
+			 */
+			if (charSetEnc == null) {
+				charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+			}
+		}
+		return charSetEnc;
+	}
 
     public static boolean processHTTPGetRequest(MessageContext msgContext,
                                                 OutputStream out, String soapAction, String
requestURI,

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java?view=diff&rev=492427&r1=492426&r2=492427
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
Wed Jan  3 22:41:46 2007
@@ -30,7 +30,6 @@
 import org.apache.commons.httpclient.methods.RequestEntity;
 
 public class RESTRequestEntity implements RequestEntity {
-    private boolean doingMTOM = false;
     private byte[] bytes;
     private String charSetEnc;
     private boolean chunked;
@@ -47,7 +46,6 @@
         this.element = element;
         this.chunked = chunked;
         this.msgCtxt = msgCtxt;
-        this.doingMTOM = msgCtxt.isDoingMTOM();
         this.charSetEnc = charSetEncoding;
         this.soapActionString = soapActionString;
         this.format = format;
@@ -62,7 +60,7 @@
     public byte[] writeBytes() throws AxisFault {
         try {
             ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
-            if (!doingMTOM) {
+            if (!format.isOptimized()) {
                 OMOutputFormat format2 = new OMOutputFormat();
                 format2.setCharSetEncoding(charSetEnc);
                 element.serializeAndConsume(bytesOut, format2);
@@ -83,7 +81,7 @@
     public void writeRequest(OutputStream out) throws IOException {
         try {
             if (chunked) {
-                this.handleOMOutput(out, doingMTOM);
+                this.handleOMOutput(out, format.isDoingSWA());
             } else {
                 if (bytes == null) {
                     bytes = writeBytes();
@@ -125,8 +123,7 @@
         // action header is not mandated in SOAP 1.2. So putting it, if available
         if (!msgCtxt.isSOAP11() && (soapActionString != null)
                 && !"".equals(soapActionString.trim()) && !"\"\"".equals(soapActionString.trim()))
{
-            contentType =
-                    contentType + ";action=\"" + soapActionString + "\";";
+            contentType =contentType + ";action=\"" + soapActionString + "\";";
         }
         return contentType;
     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?view=diff&rev=492427&r1=492426&r2=492427
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
Wed Jan  3 22:41:46 2007
@@ -56,7 +56,7 @@
 
         postMethod.setPath(url.getPath());
         postMethod.setRequestEntity(new SOAPRequestEntity(dataout, chunked, msgContext,
-                charEncoding, soapActionString, format, isAllowedRetry));
+                soapActionString, format, isAllowedRetry));
 
         if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
             postMethod.setContentChunked(true);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java?view=diff&rev=492427&r1=492426&r2=492427
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java
Wed Jan  3 22:41:46 2007
@@ -34,10 +34,7 @@
 import org.apache.commons.httpclient.methods.RequestEntity;
 
 public class SOAPRequestEntity implements RequestEntity {
-    private boolean doingMTOM = false;
-    private boolean doingSWA = false;
     private byte[] bytes;
-    private String charSetEnc;
     private boolean chunked;
     private OMElement element;
     private MessageContext msgCtxt;
@@ -46,25 +43,20 @@
     private boolean isAllowedRetry;
 
     public SOAPRequestEntity(OMElement element, boolean chunked, MessageContext msgCtxt,
-                             String charSetEncoding, String soapActionString,
+                             String soapActionString,
                              OMOutputFormat format,
                              boolean isAllowedRetry) {
         this.element = element;
         this.chunked = chunked;
         this.msgCtxt = msgCtxt;
-        this.doingMTOM = msgCtxt.isDoingMTOM();
-        this.doingSWA = msgCtxt.isDoingSwA();
-        this.charSetEnc = charSetEncoding;
         this.soapActionString = soapActionString;
         this.format = format;
         this.isAllowedRetry = isAllowedRetry;
     }
 
-    private void handleOMOutput(OutputStream out, boolean doingMTOM)
+    private void handleOMOutput(OutputStream out)
             throws XMLStreamException {
-        format.setDoOptimize(doingMTOM);
-        format.setDoingSWA(doingSWA);
-        if (!doingMTOM & doingSWA) {
+        if (!(format.isOptimized()) & format.isDoingSWA()) {
             StringWriter bufferedSOAPBody = new StringWriter();
             if (isAllowedRetry) {
                 element.serialize(bufferedSOAPBody, format);
@@ -84,11 +76,11 @@
     public byte[] writeBytes() throws AxisFault {
         try {
             ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
-            if (!doingMTOM) {
+            if (!format.isOptimized()) {
                 // why are we creating a new OMOutputFormat
                 OMOutputFormat format2 = new OMOutputFormat();
-                format2.setCharSetEncoding(charSetEnc);
-                if (doingSWA) {
+                format2.setCharSetEncoding(format.getCharSetEncoding());
+                if (format.isDoingSWA()) {
                     StringWriter bufferedSOAPBody = new StringWriter();
                     element.serializeAndConsume(bufferedSOAPBody, format2);
                     MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody, bytesOut,
msgCtxt.getAttachmentMap(), format2);
@@ -97,8 +89,6 @@
                 }
                 return bytesOut.toByteArray();
             } else {
-                format.setCharSetEncoding(charSetEnc);
-                format.setDoOptimize(true);
                 element.serializeAndConsume(bytesOut, format);
                 return bytesOut.toByteArray();
             }
@@ -116,7 +106,7 @@
         }
         try {
             if (chunked) {
-                this.handleOMOutput(out, doingMTOM);
+                this.handleOMOutput(out);
             } else {
                 if (bytes == null) {
                     bytes = writeBytes();



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message