You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2015/08/21 21:55:59 UTC
cxf git commit: Try another "hack" that seems to allow the other
verbs to work on JDK7
Repository: cxf
Updated Branches:
refs/heads/master ed2c83d53 -> c9129aff7
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/c9129aff
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c9129aff
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c9129aff
Branch: refs/heads/master
Commit: c9129aff7c15de22b3ea1e92dc55a2c923ec1393
Parents: ed2c83d
Author: Daniel Kulp <dk...@apache.org>
Authored: Fri Aug 21 15:55:34 2015 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Fri Aug 21 15:55:34 2015 -0400
----------------------------------------------------------------------
.../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/c9129aff/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/c9129aff/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 8a1a1a5..a9c6e96 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");