You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/08/11 15:23:40 UTC

svn commit: r1617273 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java

Author: olegk
Date: Mon Aug 11 13:23:40 2014
New Revision: 1617273

URL: http://svn.apache.org/r1617273
Log:
HTTPCLIENT-1538 : monitor contention in deprecated code

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java?rev=1617273&r1=1617272&r2=1617273&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java Mon Aug 11 13:23:40 2014
@@ -28,6 +28,7 @@
 package org.apache.http.impl.client;
 
 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -45,6 +46,17 @@ import org.apache.http.util.EntityUtils;
 @NotThreadSafe
 class CloseableHttpResponseProxy implements InvocationHandler {
 
+    private final static Constructor<?> CONSTRUCTOR;
+
+    static {
+        try {
+            CONSTRUCTOR = Proxy.getProxyClass(CloseableHttpResponseProxy.class.getClassLoader(),
+                    new Class<?>[] { CloseableHttpResponse.class }).getConstructor(new Class[] { InvocationHandler.class });
+        } catch (NoSuchMethodException ex) {
+            throw new IllegalStateException(ex);
+        }
+    }
+
     private final HttpResponse original;
 
     CloseableHttpResponseProxy(final HttpResponse original) {
@@ -79,10 +91,15 @@ class CloseableHttpResponseProxy impleme
     }
 
     public static CloseableHttpResponse newProxy(final HttpResponse original) {
-        return (CloseableHttpResponse) Proxy.newProxyInstance(
-                CloseableHttpResponseProxy.class.getClassLoader(),
-                new Class<?>[] { CloseableHttpResponse.class },
-                new CloseableHttpResponseProxy(original));
+        try {
+            return (CloseableHttpResponse) CONSTRUCTOR.newInstance(new CloseableHttpResponseProxy(original));
+        } catch (InstantiationException ex) {
+            throw new IllegalStateException(ex);
+        } catch (InvocationTargetException ex) {
+            throw new IllegalStateException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
 }