cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject cxf git commit: Add a "hack" setting that will allow unrecognized verbs to be used with the HttpURLConnection based Conduit
Date Thu, 20 Aug 2015 18:00:42 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ae95e49c5 -> f16a65393


Add a "hack" setting that will allow unrecognized verbs to be used with the HttpURLConnection
based Conduit


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f16a6539
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f16a6539
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f16a6539

Branch: refs/heads/master
Commit: f16a6539342d0c3ed0e97201872b61e4e3445eb4
Parents: ae95e49
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Aug 20 13:59:59 2015 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu Aug 20 13:59:59 2015 -0400

----------------------------------------------------------------------
 .../http/URLConnectionHTTPConduit.java          | 30 +++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f16a6539/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
index 22fdcd3..1c55ac4 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
@@ -32,10 +32,13 @@ import java.net.URLConnection;
 import java.util.logging.Level;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.ReflectionUtil;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CacheAndWriteOutputStream;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.https.HttpsURLConnectionFactory;
 import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
@@ -46,7 +49,13 @@ import org.apache.cxf.ws.addressing.EndpointReferenceType;
  * 
  */
 public class URLConnectionHTTPConduit extends HTTPConduit {
+    public static final String HTTPURL_CONNECTION_METHOD_HACK = "httpurlconnection.method.hack";
 
+    private static final boolean DEFAULT_USE_HACK;
+    static {
+        DEFAULT_USE_HACK = Boolean.valueOf(SystemPropertyAction.getProperty(HTTPURL_CONNECTION_METHOD_HACK,
"false"));
+    }
+    
     /**
      * This field holds the connection factory, which primarily is used to 
      * factor out SSL specific code from this implementation.
@@ -125,7 +134,26 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
             httpRequestMethod = "POST";
             message.put(Message.HTTP_REQUEST_METHOD, "POST");
         }
-        connection.setRequestMethod(httpRequestMethod);
+        try {
+            connection.setRequestMethod(httpRequestMethod);
+        } catch (java.net.ProtocolException ex) {
+            Object o = message.getContextualProperty(HTTPURL_CONNECTION_METHOD_HACK);
+            boolean b = DEFAULT_USE_HACK;
+            if (o != null) {
+                b = MessageUtils.isTrue(o);
+            }
+            if (b) {
+                try {
+                    java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class,
"method");
+                    ReflectionUtil.setAccessible(f).set(connection, httpRequestMethod);
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                    throw ex;
+                }
+            } else {
+                throw ex;
+            }
+        }
         
         // We place the connection on the message to pick it up
         // in the WrappedOutputStream.


Mime
View raw message