use of com.creditease.uav.apm.RewriteIvcResponseWrapper in project uavstack by uavorg.
the class ServerSpanAdapter method afterDoCap.
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
String url = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL);
Span span = this.spanFactory.getRemoveSpanFromContext(url);
if (span == null) {
return;
}
SlowOperContext slowOperContext = new SlowOperContext();
// 防止有没有拦截住的请求
if (RewriteIvcRequestWrapper.class.isAssignableFrom(args[0].getClass()) && RewriteIvcResponseWrapper.class.isAssignableFrom(args[1].getClass())) {
RewriteIvcRequestWrapper request = (RewriteIvcRequestWrapper) args[0];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_REQ_BODY, request.getContent().toString());
request.clearBodyContent();
RewriteIvcResponseWrapper response = (RewriteIvcResponseWrapper) args[1];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_HEADER, getResponHeaders(response));
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_BODY, response.getContent().toString());
response.clearBodyContent();
} else {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_REQ_BODY, "unsupported request");
HttpServletResponse response = (HttpServletResponse) args[1];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_HEADER, getResponHeaders(response));
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_BODY, "unsupported response");
}
Object[] params = { span, slowOperContext };
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
}
}
use of com.creditease.uav.apm.RewriteIvcResponseWrapper in project uavstack by uavorg.
the class JEEServiceRunGlobalFilterHandler method doRequest.
@Override
protected void doRequest(HttpServletRequest request, HttpServletResponse response, InterceptContext context) {
StringBuffer bf = request.getRequestURL();
if (bf == null) {
return;
}
String urlInfo = bf.toString();
if (!MonitorServerUtil.isIncludeMonitorURLForService(urlInfo) && !MonitorServerUtil.isIncludeMonitorURLForPage(urlInfo)) {
return;
}
if (logger.isDebugable()) {
logger.debug("JEEServiceStartInvokeChainHandler called for url:" + urlInfo, null);
}
Object[] args;
// 重调用链开启时添加warpper
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
RewriteIvcResponseWrapper responseWrapper = new RewriteIvcResponseWrapper(response, "IVC_DAT");
context.put(InterceptConstants.HTTPRESPONSE, responseWrapper);
// 由于application/x-www-form-urlencoded
// 形式传参时获取inputsteam会删除parameters,故在添加wrapper时先通过调用getParameterMap方法lock(tomcat源码进行)parameters
request.getParameterMap();
RewriteIvcRequestWrapper requestWrapper = new RewriteIvcRequestWrapper(request, "IVC_DAT");
context.put(InterceptConstants.HTTPREQUEST, requestWrapper);
args = new Object[] { requestWrapper, responseWrapper };
} else {
args = new Object[] { request, response };
}
Map<String, Object> params = new HashMap<String, Object>();
/**
* try to get SPAN_KEY_HEAD from http request header
*/
HttpServletRequest httprequest = (HttpServletRequest) context.get(InterceptConstants.HTTPREQUEST);
String traceContext = httprequest.getHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
String method = httprequest.getHeader(InvokeChainConstants.CLIENT_IT_METHOD);
if (!StringHelper.isEmpty(traceContext)) {
params.put(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, traceContext);
}
if (!StringHelper.isEmpty(method)) {
params.put(InvokeChainConstants.CLIENT_IT_METHOD, method);
}
String clientip = MonitorServerUtil.getClientIP(httprequest.getRemoteAddr(), httprequest.getHeader("X-Forwarded-For"));
// put intercept context
params.put(InvokeChainConstants.PARAM_INTECEPTCONTEXT, context);
params.put(InvokeChainConstants.PARAM_REMOTE_SRC_INFO, clientip);
// put request url
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL, request.getRequestURL().toString());
// register adapter
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", ServerSpanAdapter.class);
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_SERVICE, InvokeChainConstants.CapturePhase.PRECAP, params, ServerSpanAdapter.class, args);
}
Aggregations