cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Try another "hack" that seems to allow the other verbs to work on JDK7
Date Fri, 21 Aug 2015 20:36:05 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 939374043 -> 0d8d92c90


Try another "hack" that seems to allow the other verbs to work on JDK7


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

Branch: refs/heads/3.0.x-fixes
Commit: 0d8d92c90f0b02b08892838c69a365b453314206
Parents: 9393740
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Aug 21 15:55:34 2015 -0400
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 21 21:33:17 2015 +0100

----------------------------------------------------------------------
 .../http/URLConnectionHTTPConduit.java          | 34 ++++++++++++++++++--
 .../jaxrs/JAXRSClientServerBookTest.java        |  5 ---
 2 files changed, 31 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0d8d92c9/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 954db7a..b3d9a2d 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
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
+import java.net.ProtocolException;
 import java.net.Proxy;
 import java.net.SocketException;
 import java.net.URI;
@@ -147,6 +148,7 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
                 try {
                     java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class,
"method");
                     ReflectionUtil.setAccessible(f).set(connection, httpRequestMethod);
+                    message.put(HTTPURL_CONNECTION_METHOD_REFLECTION, true);
                 } catch (Throwable t) {
                     t.printStackTrace();
                     throw ex;
@@ -205,16 +207,41 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
             super(wos);
             this.connection = wos.connection;
         }
+        private OutputStream connectAndGetOutputStream(Boolean b) throws IOException {
+            OutputStream cout = null;
+
+            if (b != null && b) {
+                String method = connection.getRequestMethod();
+                connection.connect();
+                try {
+                    java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class,
"method");
+                    ReflectionUtil.setAccessible(f).set(connection, "POST");
+                    cout = connection.getOutputStream();
+                    ReflectionUtil.setAccessible(f).set(connection, method);            
           
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                }
+                
+            } else {
+                cout = connection.getOutputStream(); 
+            }
+            return cout;
+        }
         protected void setupWrappedStream() throws IOException {
             // If we need to cache for retransmission, store data in a
             // CacheAndWriteOutputStream. Otherwise write directly to the output stream.
             OutputStream cout = null;
             try {
-                cout = connection.getOutputStream();
+                try {
+                    cout = connection.getOutputStream();
+                } catch (ProtocolException pe) {
+                    Boolean b =  (Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION);
+                    cout = connectAndGetOutputStream(b); 
+                }
             } catch (SocketException e) {
                 if ("Socket Closed".equals(e.getMessage())) {
                     connection.connect();
-                    cout = connection.getOutputStream();
+                    cout = connectAndGetOutputStream((Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION));

                 } else {
                     throw e;
                 }
@@ -341,7 +368,8 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
 
         @Override
         protected void retransmitStream() throws IOException {
-            OutputStream out = connection.getOutputStream();
+            Boolean b =  (Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION);
+            OutputStream out = connectAndGetOutputStream(b); 
             cachedStream.writeCacheTo(out);
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/0d8d92c9/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 5e987fb..f63c4a8 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -59,7 +59,6 @@ import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
@@ -93,10 +92,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     
     @Test
     public void testRetrieveBookCustomMethodReflection() throws Exception {
-        double version = ClassHelper.getJavaVersion();
-        if (version < 1.8) {
-            return;
-        }
         try {
             doRetrieveBook(false);
             fail("HTTPUrlConnection does not support custom verbs without the reflection");


Mime
View raw message