use of com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor in project Sentinel by alibaba.
the class ApacheHttpClientTestController method sync.
@RequestMapping("/httpclient/sync")
public String sync() throws Exception {
SentinelApacheHttpClientConfig config = new SentinelApacheHttpClientConfig();
config.setExtractor(new ApacheHttpClientResourceExtractor() {
@Override
public String extractor(HttpRequestWrapper request) {
String contains = "/httpclient/back/";
String uri = request.getRequestLine().getUri();
if (uri.startsWith(contains)) {
uri = uri.substring(0, uri.indexOf(contains) + contains.length()) + "{id}";
}
return request.getMethod() + ":" + uri;
}
});
CloseableHttpClient httpclient = new SentinelApacheHttpClientBuilder(config).build();
HttpGet httpGet = new HttpGet("http://localhost:" + port + "/httpclient/back");
return getRemoteString(httpclient, httpGet);
}
use of com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor in project Sentinel by alibaba.
the class ApacheHttpClientTestController method sync.
@RequestMapping("/httpclient/sync/{id}")
public String sync(@PathVariable String id) throws Exception {
SentinelApacheHttpClientConfig config = new SentinelApacheHttpClientConfig();
config.setExtractor(new ApacheHttpClientResourceExtractor() {
@Override
public String extractor(HttpRequestWrapper request) {
String contains = "/httpclient/back/";
String uri = request.getRequestLine().getUri();
if (uri.startsWith(contains)) {
uri = uri.substring(0, uri.indexOf(contains) + contains.length()) + "{id}";
}
return request.getMethod() + ":" + uri;
}
});
CloseableHttpClient httpclient = new SentinelApacheHttpClientBuilder(config).build();
HttpGet httpGet = new HttpGet("http://localhost:" + port + "/httpclient/back/" + id);
return getRemoteString(httpclient, httpGet);
}
use of com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor in project Sentinel by alibaba.
the class SentinelApacheHttpClientTest method testSentinelOkHttpInterceptor1.
@Test
public void testSentinelOkHttpInterceptor1() throws Exception {
SentinelApacheHttpClientConfig config = new SentinelApacheHttpClientConfig();
config.setExtractor(new ApacheHttpClientResourceExtractor() {
@Override
public String extractor(HttpRequestWrapper request) {
String contains = "/httpclient/back/";
String uri = request.getRequestLine().getUri();
if (uri.startsWith(contains)) {
uri = uri.substring(0, uri.indexOf(contains) + contains.length()) + "{id}";
}
return request.getMethod() + ":" + uri;
}
});
CloseableHttpClient httpclient = new SentinelApacheHttpClientBuilder(config).build();
HttpGet httpGet = new HttpGet("http://localhost:" + port + "/httpclient/back/1");
System.out.println(getRemoteString(httpclient, httpGet));
ClusterNode cn = ClusterBuilderSlot.getClusterNode("httpclient:GET:/httpclient/back/{id}");
assertNotNull(cn);
Constants.ROOT.removeChildList();
ClusterBuilderSlot.getClusterNodeMap().clear();
}
Aggregations