W3C home > Mailing lists > Public > ietf-http-wg@w3.org > January to March 2011

FYI: using extension methods with Java's HttpURLConnection

From: Julian Reschke <julian.reschke@gmx.de>
Date: Fri, 04 Feb 2011 14:13:02 +0100
Message-ID: <4D4BFB5E.60505@gmx.de>
To: HTTP Working Group <ietf-http-wg@w3.org>
 From <http://is.gd/nyWI5M>:

> Markus developed workaround which allows making requests with any method, but its dependent on current sun's HttpURLConnection implementation; We don't have much choice on solving this issue in different way, so I'm going to commit it into the trunk BUT users would have to enable some property (not sure yet about its name). I will update this after commit.
>
> proposed workaround:
>
> /**
>   * Workaround for a bug in <code>HttpURLConnection.setRequestMethod(String)</code>: The implementation of Sun Microsystems is throwing a
>   * <code>ProtocolException</code> when the method is other than the HTTP/1.1 default methods. So to use PROPFIND and others, we must apply this workaround.
>   */
>
> private static final void setRequestMethodUsingWorkaroundForJREBug(final HttpURLConnection httpURLConnection, final String method) {
>     try {
>         httpURLConnection.setRequestMethod(method); // Check whether we are running on a buggy JRE
>     } catch (final ProtocolException pe) {
>         try {
>             final Class<?> httpURLConnectionClass = httpURLConnection.getClass();
>             final Field methodField = httpURLConnectionClass.getSuperclass().getDeclaredField("method");
>             methodField.setAccessible(true);
>             methodField.set(httpURLConnection, method);
>         } catch (final Exception e) {
>             throw new RuntimeException(e);
>         }
>     }
> }
Received on Friday, 4 February 2011 13:13:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 27 April 2012 06:51:36 GMT