Author: midon
Date: Wed Nov 26 17:25:06 2008
New Revision: 721062

URL: http://svn.apache.org/viewvc?rev=721062&view=rev
Log:
ODE-409: user properties are now applied to the HTTP method

Modified:
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/Properties.java
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java

Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/Properties.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/Properties.java?rev=721062&r1=721061&r2=721062&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/Properties.java 
(original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/Properties.java Wed Nov 
26 17:25:06 2008
@@ -64,6 +64,9 @@
     public static final String PROP_HTTP_PROXY_DOMAIN = PROP_HTTP_PROXY_PREFIX 
+ "domain";
     public static final String PROP_HTTP_PROXY_USER = PROP_HTTP_PROXY_PREFIX + 
"user";
     public static final String PROP_HTTP_PROXY_PASSWORD = 
PROP_HTTP_PROXY_PREFIX + "password";
+    /**
+     * @deprecated use 
org.apache.commons.httpclient.params.HttpMethodParams#HTTP_CONTENT_CHARSET 
(="http.protocol.content-charset")
+     */
     public static final String PROP_HTTP_PROTOCOL_ENCODING = 
"http.protocol.encoding";
 
     // Httpclient specific
@@ -107,8 +110,8 @@
             String host = proxy.getProxyHostName();
             if (host == null || host.length() == 0) {
                 // disable proxy if the host is not null
-                proxy=null;
-                if(log.isDebugEnabled()) log.debug("Proxy host is null. Proxy 
will not be taken into account.");
+                proxy = null;
+                if (log.isDebugEnabled()) log.debug("Proxy host is null. Proxy 
will not be taken into account.");
             }
         }
 
@@ -125,12 +128,16 @@
             if (log.isDebugEnabled()) log.debug("Translating Properties for 
Axis2");
             if (properties.isEmpty()) return options;
 
-            /*first add all property pairs so that new properties (with string 
value)
-             *              are automatically handled (i.e no translation 
needed) */
+            // First set any default values to make sure they can be overwriten
+            // set the default encoding for HttpClient (HttpClient uses 
ISO-8859-1 by default)
+            
options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
+
+            /*then add all property pairs so that new properties (with string 
value)
+*              are automatically handled (i.e no translation needed) */
             for (Map.Entry<String, String> e : properties.entrySet()) {
-                 options.setProperty(e.getKey(), e.getValue());
+                options.setProperty(e.getKey(), e.getValue());
             }
-            
+
             if (properties.containsKey(PROP_HTTP_CONNECTION_TIMEOUT)) {
                 final String value = 
properties.get(PROP_HTTP_CONNECTION_TIMEOUT);
                 try {
@@ -150,8 +157,13 @@
                 }
             }
             if (properties.containsKey(PROP_HTTP_PROTOCOL_ENCODING)) {
+                if (log.isWarnEnabled())
+                    log.warn("Deprecated property: http.protocol.encoding. Use 
http.protocol.content-charset");
                 
options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, 
properties.get(PROP_HTTP_PROTOCOL_ENCODING));
             }
+            if (properties.containsKey(HttpMethodParams.HTTP_CONTENT_CHARSET)) 
{
+                
options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, 
properties.get(HttpMethodParams.HTTP_CONTENT_CHARSET));
+            }
             if (properties.containsKey(PROP_HTTP_PROTOCOL_VERSION)) {
                 options.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, 
properties.get(PROP_HTTP_PROTOCOL_VERSION));
             }
@@ -198,10 +210,15 @@
         }
 
         public static HttpParams translate(Map<String, String> properties, 
HttpParams p) {
-            if (log.isDebugEnabled()) log.debug("Translating Properties for 
HttpClient. Properties size="+properties.size());
+            if (log.isDebugEnabled())
+                log.debug("Translating Properties for HttpClient. Properties 
size=" + properties.size());
             if (properties.isEmpty()) return p;
 
-            /*first add all property pairs so that new properties (with string 
value)
+            // First set any default values to make sure they can be overwriten
+            // set the default encoding for HttpClient (HttpClient uses 
ISO-8859-1 by default)
+            p.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
+
+            /*then all property pairs so that new properties (with string 
value)
 *              are automatically handled (i.e no translation needed) */
             for (Map.Entry<String, String> e : properties.entrySet()) {
                 p.setParameter(e.getKey(), e.getValue());
@@ -229,16 +246,24 @@
                 }
             }
 
-            // set the default encoding for HttpClient (HttpClient uses 
ISO-8859-1 by default)
-            p.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
             if (properties.containsKey(PROP_HTTP_PROTOCOL_ENCODING)) {
+                if (log.isWarnEnabled())
+                    log.warn("Deprecated property: http.protocol.encoding. Use 
http.protocol.content-charset");
                 p.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 
properties.get(PROP_HTTP_PROTOCOL_ENCODING));
             }
+            // the next one is redundant because 
HttpMethodParams.HTTP_CONTENT_CHARSET accepts a string and we use the same 
property name
+            // so the property has already been added.
+            if (properties.containsKey(HttpMethodParams.HTTP_CONTENT_CHARSET)) 
{
+                p.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, 
properties.get(HttpMethodParams.HTTP_CONTENT_CHARSET));
+            }
+
             if (properties.containsKey(PROP_HTTP_PROTOCOL_VERSION)) {
                 try {
                     p.setParameter(HttpMethodParams.PROTOCOL_VERSION, 
HttpVersion.parse(properties.get(PROP_HTTP_PROTOCOL_VERSION)));
                 } catch (ProtocolException e) {
                     if (log.isWarnEnabled())
+
+
                         log.warn("Mal-formatted Property: [" + 
PROP_HTTP_PROTOCOL_VERSION + "]", e);
                 }
             }

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java?rev=721062&r1=721061&r2=721062&view=diff
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
 (original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpMethodConverter.java
 Wed Nov 26 17:25:06 2008
@@ -30,6 +30,7 @@
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.commons.httpclient.params.HostParams;
 import org.apache.commons.httpclient.params.HttpParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -170,6 +171,7 @@
             } else if ("DELETE".equalsIgnoreCase(verb)) {
                 method = new DeleteMethod();
             }
+            method.getParams().setDefaults(params);
             if (useUrlEncoded) {
                 queryPath = encodedParams;
             }
@@ -185,7 +187,7 @@
             } else if ("PUT".equalsIgnoreCase(verb)) {
                 method = new PutMethod();
             }
-
+            method.getParams().setDefaults(params);
             // some body-building...
             final String contentCharset = 
method.getParams().getContentCharset();
             if (log.isDebugEnabled()) log.debug("Content-Type [" + contentType 
+ "] Charset [" + contentCharset + "]");


Reply via email to