Repository: cxf Updated Branches: refs/heads/3.0.x-fixes eaa74091e -> 636424b0b
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/7316ee18 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7316ee18 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7316ee18 Branch: refs/heads/3.0.x-fixes Commit: 7316ee18022415ba78a736fbfe42020ae3f726f7 Parents: eaa7409 Author: Daniel Kulp <[email protected]> Authored: Thu Aug 20 13:59:59 2015 -0400 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Aug 21 16:43:33 2015 +0100 ---------------------------------------------------------------------- .../http/URLConnectionHTTPConduit.java | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/7316ee18/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.
