Search in sources :

Example 1 with JDKProxyInvokeProcessor

use of com.creditease.monitor.proxy.spi.JDKProxyInvokeProcessor in project uavstack by uavorg.

the class ApacheAsyncHttpClientIT method makeConsumer.

@SuppressWarnings("rawtypes")
public HttpAsyncResponseConsumer makeConsumer(final HttpAsyncResponseConsumer r) {
    return JDKProxyInvokeUtil.newProxyInstance(HttpContext.class.getClassLoader(), new Class<?>[] { HttpAsyncResponseConsumer.class }, new JDKProxyInvokeHandler<HttpAsyncResponseConsumer>(r, new JDKProxyInvokeProcessor<HttpAsyncResponseConsumer>() {

        @Override
        public void preProcess(HttpAsyncResponseConsumer t, Object proxy, Method method, Object[] args) {
        }

        @Override
        public Object postProcess(Object res, HttpAsyncResponseConsumer t, Object proxy, Method method, Object[] args) {
            if (method.getName().equals("responseReceived")) {
                HttpResponse response = (HttpResponse) args[0];
                Header sheader = response.getLastHeader("Server");
                if (sheader != null) {
                    targetServer = sheader.getValue();
                }
            }
            return null;
        }
    }));
}
Also used : JDKProxyInvokeProcessor(com.creditease.monitor.proxy.spi.JDKProxyInvokeProcessor) Header(org.apache.http.Header) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpAsyncResponseConsumer(org.apache.http.nio.protocol.HttpAsyncResponseConsumer) Method(java.lang.reflect.Method)

Aggregations

JDKProxyInvokeProcessor (com.creditease.monitor.proxy.spi.JDKProxyInvokeProcessor)1 Method (java.lang.reflect.Method)1 Header (org.apache.http.Header)1 HttpResponse (org.apache.http.HttpResponse)1 HttpAsyncResponseConsumer (org.apache.http.nio.protocol.HttpAsyncResponseConsumer)1 HttpContext (org.apache.http.protocol.HttpContext)1