use of com.pamirs.pradar.internal.adapter.ExecutionForwardCall in project LinkAgent by shulieTech.
the class RealCallEnqueueV2Interceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) throws ProcessControlException {
Object target = advice.getTarget();
Request request = null;
try {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
} catch (ReflectException e) {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
}
final String url = request.urlString();
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
String check = request.header(OKHttpConstants.DYNAMIC_FIELD_HEADER);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, check);
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
final Request finalRequest = request;
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) throws ProcessControlException {
HttpUrl httpUrl = HttpUrl.parse(config.getForwarding());
Reflect.on(finalRequest).set("url", httpUrl);
return null;
}
@Override
public Object call(Object param) {
Headers header = Headers.of(new String[0]);
Buffer buffer = new Buffer();
try {
if (param instanceof String) {
buffer.write(String.valueOf(param).getBytes("UTF-8"));
} else {
buffer.write(JSONObject.toJSONBytes(param));
}
} catch (IOException e) {
}
return new Response.Builder().code(200).body(new RealResponseBody(header, buffer)).request(finalRequest).protocol(Protocol.HTTP_1_0).message("OK").build();
}
});
}
use of com.pamirs.pradar.internal.adapter.ExecutionForwardCall in project LinkAgent by shulieTech.
the class HttpClientv3MethodInterceptor method beforeLast.
@Override
public void beforeLast(Advice advice) throws ProcessControlException {
Object[] args = advice.getParameterArray();
try {
final HttpMethod method = (HttpMethod) args[1];
if (method == null) {
return;
}
int port = method.getURI().getPort();
String path = method.getURI().getPath();
String url = getService(method.getURI().getScheme(), method.getURI().getHost(), port, path);
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
Header header = method.getRequestHeader(PradarService.PRADAR_WHITE_LIST_CHECK);
if (header == null) {
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, true);
} else {
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, header.getValue());
}
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
if (config.getStrategy() instanceof JsonMockStrategy) {
config.addArgs("extraMethod", method);
fixJsonStrategy.processBlock(java.lang.String.class, advice.getClassLoader(), config);
}
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object call(Object param) throws ProcessControlException {
byte[] bytes = JSONObject.toJSONBytes(param);
Reflect.on(method).set("responseBody", bytes);
ProcessController.returnImmediately(int.class, 200);
return true;
}
@Override
public Object forward(Object param) throws ProcessControlException {
String forwarding = config.getForwarding();
try {
method.setURI(new URI(forwarding));
} catch (URIException e) {
}
return null;
}
});
} catch (URIException e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
} catch (ProcessControlException pce) {
throw pce;
} catch (Throwable t) {
LOGGER.error("", t);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(t);
}
}
}
use of com.pamirs.pradar.internal.adapter.ExecutionForwardCall in project LinkAgent by shulieTech.
the class ClientInterceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) throws ProcessControlException, MalformedURLException {
Object[] args = advice.getParameterArray();
if (!(args[0] instanceof ClientRequest)) {
return;
}
final ClientRequest clientRequest = (ClientRequest) args[0];
final String url = clientRequest.getUri().toURL().toString();
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, clientRequest.getHeaderString(PradarService.PRADAR_WHITE_LIST_CHECK));
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) {
clientRequest.setUri(URI.create(config.getForwarding()));
return null;
}
@Override
public Object call(Object param) {
return new ClientResponse(clientRequest, Response.ok(param).build());
}
});
}
use of com.pamirs.pradar.internal.adapter.ExecutionForwardCall in project LinkAgent by shulieTech.
the class HttpRequestExecuteMethodInterceptor method afterFirst.
@Override
public void afterFirst(Advice advice) throws ProcessControlException {
Object target = advice.getTarget();
final HttpRequest request = (HttpRequest) target;
String url = request.getUrl().build();
String whiteList = request.getHeaders().getFirstHeaderStringValue(PradarService.PRADAR_WHITE_LIST_CHECK);
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, whiteList);
config.addArgs("url", url);
config.addArgs("request", request);
config.addArgs("method", url);
config.addArgs("isInterface", Boolean.FALSE);
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) throws ProcessControlException {
GenericUrl url1 = new GenericUrl(config.getForwarding());
Reflect.on(request).set("url", url1);
return null;
}
@Override
public Object call(Object param) throws ProcessControlException {
return param;
}
});
}
use of com.pamirs.pradar.internal.adapter.ExecutionForwardCall in project LinkAgent by shulieTech.
the class ForwardStrategy method processBlock.
@Override
public Object processBlock(Class returnType, ClassLoader classLoader, Object params, ExecutionCall call) throws ProcessControlException {
if (call instanceof ExecutionForwardCall) {
ExecutionForwardCall forwardCall = (ExecutionForwardCall) call;
Object block = processBlock(returnType, classLoader, params);
return forwardCall.forward(block);
}
return processBlock(returnType, classLoader, params);
}
Aggregations