-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Apache HttpClient integration #1436
Comments
I will finish it ⛽️ |
👍 |
大佬们 我遇到了问题 望帮忙指点 HttpContext context = new BasicHttpContext();
CloseableHttpResponse response;
try {
response = httpclient.execute(httpGet, context);
} catch (Exception e){
SentinelApacheHttpClientHandleException.handle(context, e);
//这里需要用户必须try-catch 去回收发送拦截器中的exit-entry
throw e;
}
try {
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity, "utf-8");
EntityUtils.consume(entity);
} finally {
response.close();
}
httpclient.close();
return result; 这里需要用户必须try-catch 去回收发送拦截器中的exit-entry |
@zhaoyuguang 也许可以利用 org.apache.http.impl.client.HttpClientBuilder#decorateMainExec 这个实现 |
3KS |
看了下 execChain 貌似没有给用户自定义增加节点的地方,对么? |
这个是哪些异常拦截不到?name resolving timeout? connect timeout这类? |
这个其实waves同学讲的是,使用自定义的Builder类,比如: private static class CustomBuilder extends HttpClientBuilder {
protected org.apache.http.impl.execchain.ClientExecChain decorateMainExec(final org.apache.http.impl.execchain.ClientExecChain mainExec) {
return new ClientExecChain() {
@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext clientContext,
HttpExecutionAware execAware) throws IOException, HttpException {
try {
return mainExec.execute(route, request, clientContext, execAware);
} catch (Exception e) {
System.out.println("exception");
}
return null;
}
};
}
} 相当于对外,就不需要暴露更多的东西,只需要要求用户使用SentinelHttpClientBuilder即可 |
Issue Description
Type: feature request
Describe what happened (or what feature you want)
Add integration module for Apache HttpClient (including async client). Contributions are welcomed!
The text was updated successfully, but these errors were encountered: