Search in sources :

Example 6 with JDKProxyInvokeHandler

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

the class JettyPlusIT method onServletRegist.

/**
 * onServletRegist
 *
 * @param args
 * @return
 */
public ServletContext onServletRegist(Object... args) {
    ServletContext servletContext;
    ServletContextEvent sce;
    if (ServletContextEvent.class.isAssignableFrom(args[0].getClass())) {
        sce = (ServletContextEvent) args[0];
        servletContext = sce.getServletContext();
    } else {
        servletContext = (ServletContext) args[0];
    }
    ServletContext scProxy = (ServletContext) servletContext.getAttribute("com.creditease.uav.mof.tomcat.servletcontext");
    if (scProxy == null) {
        scProxy = JDKProxyInvokeUtil.newProxyInstance(ServletContext.class.getClassLoader(), new Class<?>[] { ServletContext.class }, new JDKProxyInvokeHandler<ServletContext>(servletContext, new DynamicServletContextProcessor()));
        servletContext.setAttribute("com.creditease.uav.mof.tomcat.servletcontext", scProxy);
    }
    return scProxy;
}
Also used : JDKProxyInvokeHandler(com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler) DynamicServletContextProcessor(com.creditease.monitor.jee.servlet30.DynamicServletContextProcessor) ServletContext(javax.servlet.ServletContext) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 7 with JDKProxyInvokeHandler

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

the class ApacheAsyncHttpClientIT method doAsyncStart.

/**
 * for async http client
 *
 * @param args
 * @return
 */
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
public FutureCallback doAsyncStart(Object[] args) {
    HttpAsyncRequestProducer requestProducer = null;
    HttpAsyncResponseConsumer responseConsumer = null;
    HttpContext context = null;
    FutureCallback callback = null;
    Map mObj = null;
    if (args.length == 4) {
        requestProducer = (HttpAsyncRequestProducer) args[0];
        responseConsumer = (HttpAsyncResponseConsumer) args[1];
        context = (HttpContext) args[2];
        callback = (FutureCallback) args[3];
    } else if (args.length == 5) {
        requestProducer = (HttpAsyncRequestProducer) args[1];
        responseConsumer = (HttpAsyncResponseConsumer) args[2];
        context = (HttpContext) args[3];
        callback = (FutureCallback) args[4];
    }
    String httpAction = null;
    try {
        HttpRequest hr = requestProducer.generateRequest();
        /**
         * 呵呵,就是把UAV的客户端标记加到http header里面,接收方就知道是哪个东东调用的了,便于实现来源快速匹配,这个模式只适合直连模式
         *
         * 对于代理模式,只匹配代理源即可
         */
        hr.addHeader("UAV-Client-Src", MonitorServerUtil.getUAVClientSrc(this.applicationId));
        RequestLine rl = hr.getRequestLine();
        httpAction = rl.getMethod();
        targetURL = rl.getUri();
        // 部分HttpRequest中没有ip:port,需要从httpHost中拿到再拼接
        if (!targetURL.startsWith("http")) {
            targetURL = requestProducer.getTarget().toURI() + targetURL;
        }
    } catch (IOException e) {
        // ignore thie exception
        return null;
    } catch (HttpException e) {
        // ignore thie exception
        return null;
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, httpAction);
    params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "apache.http.AsyncClient");
    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + targetURL + "," + httpAction + "," + this.applicationId, null);
    }
    /**
     * for async, as not in the same thread
     */
    ccMap = UAVServer.instance().runMonitorAsyncCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params, null);
    // register invokechain adapter
    UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", ApacheAsyncHttpClientAdapter.class);
    ccMap4Chain = (Map<String, Object>) UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, ApacheAsyncHttpClientAdapter.class, args);
    if (callback == null) {
        return null;
    }
    callback = JDKProxyInvokeUtil.newProxyInstance(HttpContext.class.getClassLoader(), new Class<?>[] { FutureCallback.class }, new JDKProxyInvokeHandler<FutureCallback>(callback, new FutureCallbackProxyInvokeProcessor(ccMap4Chain)));
    return callback;
}
Also used : HttpRequest(org.apache.http.HttpRequest) HashMap(java.util.HashMap) JDKProxyInvokeHandler(com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpAsyncResponseConsumer(org.apache.http.nio.protocol.HttpAsyncResponseConsumer) IOException(java.io.IOException) RequestLine(org.apache.http.RequestLine) HttpAsyncRequestProducer(org.apache.http.nio.protocol.HttpAsyncRequestProducer) HttpException(org.apache.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) FutureCallback(org.apache.http.concurrent.FutureCallback)

Example 8 with JDKProxyInvokeHandler

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

the class TomcatPlusIT method onServletRegist.

/**
 * onServletRegist
 *
 * @param args
 * @return
 */
public ServletContext onServletRegist(Object... args) {
    ServletContext servletContext = (ServletContext) args[0];
    // uav's inner app doesn't need Profiling,just return origin servletContext here.
    if ("/com.creditease.uav".equals(servletContext.getContextPath())) {
        return servletContext;
    }
    ServletContext scProxy = (ServletContext) servletContext.getAttribute("com.creditease.uav.mof.tomcat.servletcontext");
    if (scProxy == null) {
        scProxy = JDKProxyInvokeUtil.newProxyInstance(ServletContext.class.getClassLoader(), new Class<?>[] { ServletContext.class }, new JDKProxyInvokeHandler<ServletContext>(servletContext, new DynamicServletContextProcessor()));
        servletContext.setAttribute("com.creditease.uav.mof.tomcat.servletcontext", scProxy);
    }
    return scProxy;
}
Also used : JDKProxyInvokeHandler(com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler) DynamicServletContextProcessor(com.creditease.monitor.jee.servlet30.DynamicServletContextProcessor) ServletContext(javax.servlet.ServletContext)

Example 9 with JDKProxyInvokeHandler

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

the class TransportIT method doAsyncStart.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object doAsyncStart(Object[] args) {
    DiscoveryNode node = (DiscoveryNode) args[0];
    esAction = (String) args[1];
    TransportResponseHandler handler = (TransportResponseHandler) args[4];
    String address = node.getHostAddress();
    Integer port = node.getAddress().getPort();
    targetURL = "elasticsearch://" + address + ":" + port;
    if (logger.isDebugable()) {
        logger.debug("Elastaicsearch INVOKE START: " + targetURL + " action: " + esAction, null);
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, esAction);
    params.put(CaptureConstants.INFO_CLIENT_APPID, appid);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "elasticsearch.client");
    ccMap = UAVServer.instance().runMonitorAsyncCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params, null);
    // register adapter
    UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", TransportAdapter.class);
    ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, TransportAdapter.class, args);
    if (handler == null) {
        return null;
    }
    handler = JDKProxyInvokeUtil.newProxyInstance(TransportResponseHandler.class.getClassLoader(), new Class<?>[] { TransportResponseHandler.class }, new JDKProxyInvokeHandler<TransportResponseHandler>(handler, new ESHandlerProxyInvokeProcessor()));
    return handler;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) JDKProxyInvokeHandler(com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler)

Example 10 with JDKProxyInvokeHandler

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

the class JaxWSHookIT method createDispatch.

@SuppressWarnings("rawtypes")
public Dispatch createDispatch(Dispatch d, Service s, Object[] args) {
    Binding binding = ((BindingProvider) d).getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(this.handler);
    binding.setHandlerChain(handlerChain);
    final String wsdlLocation = getServiceURL(s);
    Dispatch tProxy = JDKProxyInvokeUtil.newProxyInstance(this.getClass().getClassLoader(), new Class[] { Dispatch.class }, new JDKProxyInvokeHandler<Dispatch>(d, new DispatchProcessor(wsdlLocation.toString(), this.handler)));
    return tProxy;
}
Also used : Binding(javax.xml.ws.Binding) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) Handler(javax.xml.ws.handler.Handler) JDKProxyInvokeHandler(com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler) Dispatch(javax.xml.ws.Dispatch) BindingProvider(javax.xml.ws.BindingProvider)

Aggregations

JDKProxyInvokeHandler (com.creditease.monitor.proxy.spi.JDKProxyInvokeHandler)11 HashMap (java.util.HashMap)3 Binding (javax.xml.ws.Binding)3 BindingProvider (javax.xml.ws.BindingProvider)3 Handler (javax.xml.ws.handler.Handler)3 DynamicServletContextProcessor (com.creditease.monitor.jee.servlet30.DynamicServletContextProcessor)2 Future (java.util.concurrent.Future)2 ServletContext (javax.servlet.ServletContext)2 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)2 PullCallback (com.alibaba.rocketmq.client.consumer.PullCallback)1 RocketMQProducerAdapter (com.creditease.uav.hook.rocketmq.adapter.RocketMQProducerAdapter)1 RocketMQPullConsumerAdapter (com.creditease.uav.hook.rocketmq.adapter.RocketMQPullConsumerAdapter)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Map (java.util.Map)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 Dispatch (javax.xml.ws.Dispatch)1 HttpException (org.apache.http.HttpException)1 HttpRequest (org.apache.http.HttpRequest)1 RequestLine (org.apache.http.RequestLine)1