hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1617272 - /httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java
Date Mon, 11 Aug 2014 13:14:11 GMT
Author: olegk
Date: Mon Aug 11 13:14:11 2014
New Revision: 1617272

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

Modified:
    httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java

Modified: httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java?rev=1617272&r1=1617271&r2=1617272&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java
(original)
+++ httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java
Mon Aug 11 13:14:11 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) {
@@ -78,10 +90,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);
+        }
     }
 
 }



Mime
View raw message