use of com.alibaba.csp.sentinel.adapter.apache.httpclient.SentinelApacheHttpClientBuilder 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.SentinelApacheHttpClientBuilder 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);
}
Aggregations