Skip to content
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

Closed
sczyh30 opened this issue Apr 26, 2020 · 8 comments · Fixed by #1455
Closed

Add Apache HttpClient integration #1436

sczyh30 opened this issue Apr 26, 2020 · 8 comments · Fixed by #1455
Assignees
Labels
area/integrations Issues or PRs related to integrations with open-source components good first issue Good for newcomers kind/feature Category issues or prs related to feature request.
Milestone

Comments

@sczyh30
Copy link
Member

sczyh30 commented Apr 26, 2020

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!

@sczyh30 sczyh30 added good first issue Good for newcomers kind/feature Category issues or prs related to feature request. area/integrations Issues or PRs related to integrations with open-source components labels Apr 26, 2020
@zhaoyuguang
Copy link
Collaborator

zhaoyuguang commented Apr 29, 2020

I will finish it ⛽️

@sczyh30
Copy link
Member Author

sczyh30 commented Apr 29, 2020

I will finish it ⛽️

👍

@zhaoyuguang
Copy link
Collaborator

大佬们 我遇到了问题 望帮忙指点
Apache HttpClient拦截器有两个拦截器,
HttpRequestInterceptor and HttpResponseInterceptor
在发送前和相应后进行拦截,但是如果远端异常并不会进入响应拦截器
所以如果插件的使用变成了这样

        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
还有什么更好的设计么?

@wavesZh
Copy link
Contributor

wavesZh commented May 6, 2020

@zhaoyuguang 也许可以利用 org.apache.http.impl.client.HttpClientBuilder#decorateMainExec 这个实现

@zhaoyuguang
Copy link
Collaborator

@zhaoyuguang 也许可以利用 org.apache.http.impl.client.HttpClientBuilder#decorateMainExec 这个实现

3KS

@sczyh30 sczyh30 added this to the 1.8.0 milestone May 7, 2020
@zhaoyuguang
Copy link
Collaborator

@zhaoyuguang 也许可以利用 org.apache.http.impl.client.HttpClientBuilder#decorateMainExec 这个实现

看了下 execChain 貌似没有给用户自定义增加节点的地方,对么?
看起来需要用反射修改下 httpclient的execChain增加节点?

@jasonjoo2010
Copy link
Collaborator

这个是哪些异常拦截不到?name resolving timeout? connect timeout这类?

@jasonjoo2010
Copy link
Collaborator

decorateMainExec

这个其实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即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/integrations Issues or PRs related to integrations with open-source components good first issue Good for newcomers kind/feature Category issues or prs related to feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants