Search in sources :

Example 1 with ContextTransfer

use of com.pamirs.pradar.interceptor.ContextTransfer in project LinkAgent by shulieTech.

the class HttpRequestExecuteMethodInterceptor method getContextTransfer.

@Override
protected ContextTransfer getContextTransfer(Advice advice) {
    Object target = advice.getTarget();
    final HttpRequest request = (HttpRequest) target;
    final HttpHeaders headers = request.getHeaders();
    return new ContextTransfer() {

        @Override
        public void transfer(String key, String value) {
            headers.set(key, Collections.singletonList(value));
        }
    };
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) HttpHeaders(com.google.api.client.http.HttpHeaders) ContextTransfer(com.pamirs.pradar.interceptor.ContextTransfer)

Example 2 with ContextTransfer

use of com.pamirs.pradar.interceptor.ContextTransfer in project LinkAgent by shulieTech.

the class HttpEncoderInterceptor method getContextTransfer.

@Override
protected ContextTransfer getContextTransfer(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpMessage httpMessage = (HttpMessage) args[1];
    Map<String, String> context = manager.getDynamicField(httpMessage, NettyConstants.DYNAMIC_FIELD_ASYNC_CONTEXT);
    InvokeContext invokeContext_ = Pradar.fromMap(context);
    if (Pradar.hasInvokeContext(context) || Pradar.hasInvokeContext()) {
        return new ContextTransfer() {

            @Override
            public void transfer(String key, String value) {
                HttpHeaders headers = httpMessage.headers();
                if (headers != null && !headers.contains(key)) {
                    headers.set(key, value);
                }
            }
        };
    }
    return null;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) InvokeContext(com.pamirs.pradar.InvokeContext) ContextTransfer(com.pamirs.pradar.interceptor.ContextTransfer) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 3 with ContextTransfer

use of com.pamirs.pradar.interceptor.ContextTransfer in project LinkAgent by shulieTech.

the class HttpClientv3MethodInterceptor method getContextTransfer.

@Override
protected ContextTransfer getContextTransfer(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpMethod method = (HttpMethod) args[1];
    if (method == null) {
        return null;
    }
    return new ContextTransfer() {

        @Override
        public void transfer(String key, String value) {
            method.setRequestHeader(key, value);
        }
    };
}
Also used : ContextTransfer(com.pamirs.pradar.interceptor.ContextTransfer) JSONObject(com.alibaba.fastjson.JSONObject) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 4 with ContextTransfer

use of com.pamirs.pradar.interceptor.ContextTransfer in project LinkAgent by shulieTech.

the class HttpClientv5MethodInterceptor method getContextTransfer.

@Override
protected ContextTransfer getContextTransfer(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpHost httpHost = (HttpHost) args[0];
    final HttpRequest request = (HttpRequest) args[1];
    if (httpHost == null) {
        return null;
    }
    return new ContextTransfer() {

        @Override
        public void transfer(String key, String value) {
            if (request.getHeaders(HeaderMark.DONT_MODIFY_HEADER) == null || request.getHeaders(HeaderMark.DONT_MODIFY_HEADER).length == 0) {
                request.setHeader(key, value);
            }
        }
    };
}
Also used : ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) ContextTransfer(com.pamirs.pradar.interceptor.ContextTransfer) HttpHost(org.apache.hc.core5.http.HttpHost) JSONObject(com.alibaba.fastjson.JSONObject)

Example 5 with ContextTransfer

use of com.pamirs.pradar.interceptor.ContextTransfer in project LinkAgent by shulieTech.

the class HttpURLConnectionInterceptor method getContextTransfer.

@Override
protected ContextTransfer getContextTransfer(Advice advice) {
    Object target = advice.getTarget();
    final HttpURLConnection request = (HttpURLConnection) target;
    boolean connecting = advice.hasMark(MARK_CONNECTING);
    boolean connected = advice.hasMark(MARK_CONNECTED);
    if (connected || connecting) {
        return null;
    }
    return new ContextTransfer() {

        @Override
        public void transfer(String key, String value) {
            request.setRequestProperty(key, value);
        }
    };
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ContextTransfer(com.pamirs.pradar.interceptor.ContextTransfer)

Aggregations

ContextTransfer (com.pamirs.pradar.interceptor.ContextTransfer)11 JSONObject (com.alibaba.fastjson.JSONObject)2 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HeaderProcessor (com.pamirs.attach.plugin.apache.kafka.header.HeaderProcessor)1 InvokeContext (com.pamirs.pradar.InvokeContext)1 Request (com.weibo.api.motan.rpc.Request)1 Metadata (io.grpc.Metadata)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 HttpMessage (io.netty.handler.codec.http.HttpMessage)1 HttpURLConnection (java.net.HttpURLConnection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MimeHeaders (javax.xml.soap.MimeHeaders)1 Call (org.apache.axis.client.Call)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 Message (org.apache.cxf.message.Message)1 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)1 HttpHost (org.apache.hc.core5.http.HttpHost)1