Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 01B611814F for ; Fri, 21 Aug 2015 19:56:00 +0000 (UTC) Received: (qmail 69546 invoked by uid 500); 21 Aug 2015 19:55:59 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 69480 invoked by uid 500); 21 Aug 2015 19:55:59 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 69471 invoked by uid 99); 21 Aug 2015 19:55:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Aug 2015 19:55:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A08A7E0283; Fri, 21 Aug 2015 19:55:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@cxf.apache.org Message-Id: <3cec418761b2463c9ae942f36cc9ba31@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: Try another "hack" that seems to allow the other verbs to work on JDK7 Date: Fri, 21 Aug 2015 19:55:59 +0000 (UTC) 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 Authored: Fri Aug 21 15:55:34 2015 -0400 Committer: Daniel Kulp 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");