HTTPCLIENT-1538 : monitor contention in deprecated code
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1617273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f5bf414adc
commit
caae4ef049
|
@ -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 implements InvocationHandler {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue