Search in sources :

Example 1 with SentinelApacheHttpClientBuilder

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClientResourceExtractor(com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor) SentinelApacheHttpClientConfig(com.alibaba.csp.sentinel.adapter.apache.httpclient.config.SentinelApacheHttpClientConfig) HttpGet(org.apache.http.client.methods.HttpGet) HttpRequestWrapper(org.apache.http.client.methods.HttpRequestWrapper) SentinelApacheHttpClientBuilder(com.alibaba.csp.sentinel.adapter.apache.httpclient.SentinelApacheHttpClientBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SentinelApacheHttpClientBuilder

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClientResourceExtractor(com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor) SentinelApacheHttpClientConfig(com.alibaba.csp.sentinel.adapter.apache.httpclient.config.SentinelApacheHttpClientConfig) HttpGet(org.apache.http.client.methods.HttpGet) HttpRequestWrapper(org.apache.http.client.methods.HttpRequestWrapper) SentinelApacheHttpClientBuilder(com.alibaba.csp.sentinel.adapter.apache.httpclient.SentinelApacheHttpClientBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SentinelApacheHttpClientBuilder (com.alibaba.csp.sentinel.adapter.apache.httpclient.SentinelApacheHttpClientBuilder)2 SentinelApacheHttpClientConfig (com.alibaba.csp.sentinel.adapter.apache.httpclient.config.SentinelApacheHttpClientConfig)2 ApacheHttpClientResourceExtractor (com.alibaba.csp.sentinel.adapter.apache.httpclient.extractor.ApacheHttpClientResourceExtractor)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpRequestWrapper (org.apache.http.client.methods.HttpRequestWrapper)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2