Search in sources :

Example 1 with ExecutionStrategy

use of com.pamirs.pradar.internal.adapter.ExecutionStrategy in project LinkAgent by shulieTech.

the class HttpURLConnectionGetInputStreamInterceptor method beforeLast.

@Override
public void beforeLast(Advice advice) throws ProcessControlException {
    if (!Pradar.isClusterTest()) {
        return;
    }
    Object target = advice.getTarget();
    final HttpURLConnection request = (HttpURLConnection) target;
    final URL url = request.getURL();
    String fullPath = getService(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
    String whiteList = request.getRequestProperty(PradarService.PRADAR_WHITE_LIST_CHECK);
    MatchConfig config = ClusterTestUtils.httpClusterTest(fullPath);
    ExecutionStrategy strategy = config.getStrategy();
    // 仅mock在getInputStream里执行
    if (!(strategy instanceof JsonMockStrategy) && !(strategy instanceof MockStrategy)) {
        return;
    }
    config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, whiteList);
    // 白名单需要的信息
    config.addArgs("url", fullPath);
    // mock转发需要信息
    config.addArgs("request", request);
    config.addArgs("method", "url");
    config.addArgs("isInterface", Boolean.FALSE);
    config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
Also used : JsonMockStrategy(com.pamirs.pradar.pressurement.mock.JsonMockStrategy) HttpURLConnection(java.net.HttpURLConnection) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig) ExecutionStrategy(com.pamirs.pradar.internal.adapter.ExecutionStrategy) URL(java.net.URL) MockStrategy(com.pamirs.pradar.pressurement.mock.MockStrategy) JsonMockStrategy(com.pamirs.pradar.pressurement.mock.JsonMockStrategy)

Example 2 with ExecutionStrategy

use of com.pamirs.pradar.internal.adapter.ExecutionStrategy in project LinkAgent by shulieTech.

the class HttpURLConnectionInterceptor method beforeLast.

@Override
public void beforeLast(Advice advice) throws ProcessControlException {
    if (!Pradar.isClusterTest()) {
        return;
    }
    /**
     * 保持trace一致
     */
    boolean connecting = advice.hasMark(MARK_CONNECTING);
    boolean connected = advice.hasMark(MARK_CONNECTED);
    if (connected || connecting) {
        return;
    }
    Object target = advice.getTarget();
    final HttpURLConnection request = (HttpURLConnection) target;
    final URL url = request.getURL();
    String fullPath = getService(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
    String whiteList = request.getRequestProperty(PradarService.PRADAR_WHITE_LIST_CHECK);
    MatchConfig config = ClusterTestUtils.httpClusterTest(fullPath);
    ExecutionStrategy strategy = config.getStrategy();
    // mock不在connect里执行
    if (strategy instanceof JsonMockStrategy || strategy instanceof MockStrategy) {
        return;
    }
    config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, whiteList);
    // 白名单需要的信息
    config.addArgs("url", fullPath);
    // mock转发需要信息
    config.addArgs("request", request);
    config.addArgs("method", "url");
    config.addArgs("isInterface", Boolean.FALSE);
    config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
Also used : JsonMockStrategy(com.pamirs.pradar.pressurement.mock.JsonMockStrategy) HttpURLConnection(java.net.HttpURLConnection) MatchConfig(com.pamirs.pradar.internal.config.MatchConfig) ExecutionStrategy(com.pamirs.pradar.internal.adapter.ExecutionStrategy) URL(java.net.URL) JsonMockStrategy(com.pamirs.pradar.pressurement.mock.JsonMockStrategy) MockStrategy(com.pamirs.pradar.pressurement.mock.MockStrategy)

Aggregations

ExecutionStrategy (com.pamirs.pradar.internal.adapter.ExecutionStrategy)2 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)2 JsonMockStrategy (com.pamirs.pradar.pressurement.mock.JsonMockStrategy)2 MockStrategy (com.pamirs.pradar.pressurement.mock.MockStrategy)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2