brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bostko <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #285: Adding HttpExecutor to be used for interc...
Date Tue, 23 Aug 2016 18:50:00 GMT
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/285#discussion_r75928110
  
    --- Diff: core/src/main/java/org/apache/brooklyn/feed/http/HttpFeed.java ---
    @@ -331,52 +366,45 @@ protected void preStart() {
                 }
     
                 Callable<HttpToolResponse> pollJob;
    -            
    -            if (pollInfo.method.equals("get")) {
    -                pollJob = new Callable<HttpToolResponse>() {
    -                    public HttpToolResponse call() throws Exception {
    -                        if (log.isTraceEnabled()) log.trace("http polling for {} sensors
at {}", entity, pollInfo);
    -                        return HttpTool.httpGet(httpClient, pollInfo.uriProvider.get(),
pollInfo.headers);
    -                    }};
    -            } else if (pollInfo.method.equals("post")) {
    -                pollJob = new Callable<HttpToolResponse>() {
    -                    public HttpToolResponse call() throws Exception {
    -                        if (log.isTraceEnabled()) log.trace("http polling for {} sensors
at {}", entity, pollInfo);
    -                        return HttpTool.httpPost(httpClient, pollInfo.uriProvider.get(),
pollInfo.headers, pollInfo.body);
    -                    }};
    -            } else if (pollInfo.method.equals("head")) {
    -                pollJob = new Callable<HttpToolResponse>() {
    -                    public HttpToolResponse call() throws Exception {
    -                        if (log.isTraceEnabled()) log.trace("http polling for {} sensors
at {}", entity, pollInfo);
    -                        return HttpTool.httpHead(httpClient, pollInfo.uriProvider.get(),
pollInfo.headers);
    -                    }};
    -            } else {
    -                throw new IllegalStateException("Unexpected http method: "+pollInfo.method);
    -            }
    -            
    -            getPoller().scheduleAtFixedRate(pollJob, new DelegatingPollHandler<HttpToolResponse>(handlers),
minPeriod);
    -        }
    -    }
    +            pollJob = new Callable<HttpToolResponse>() {
    +                public HttpToolResponse call() throws Exception {
    +                    if (log.isTraceEnabled()) log.trace("http polling for {} sensors
at {}", entity, pollInfo);
     
    -    // TODO Should we really trustAll for https? Make configurable?
    -    private HttpClient createHttpClient(HttpPollIdentifier pollIdentifier) {
    -        URI uri = pollIdentifier.uriProvider.get();
    -        HttpClientBuilder builder = HttpTool.httpClientBuilder()
    -                .trustAll()
    -                .laxRedirect(true);
    -        if (uri != null) builder.uri(uri);
    -        if (uri != null) builder.credential(pollIdentifier.credentials);
    -        if (pollIdentifier.connectionTimeout != null) {
    -            builder.connectionTimeout(pollIdentifier.connectionTimeout);
    -        }
    -        if (pollIdentifier.socketTimeout != null) {
    -            builder.socketTimeout(pollIdentifier.socketTimeout);
    +                    BasicAuth creds = null;
    +                    if (pollInfo.credentials.isPresent()) {
    +                        creds =  org.apache.brooklyn.util.http.executor.Credentials.basic(
    +                                pollInfo.credentials.get().getUserPrincipal().getName(),
    +                                pollInfo.credentials.get().getPassword());
    +                    }
    +
    +                    HttpResponse response =  pollInfo.httpExecutor.execute(new HttpRequest.Builder()
    +                            .headers(pollInfo.headers)
    +                            .uri(pollInfo.uriProvider.get())
    +                            .credentials(creds)
    +                            .method(pollInfo.method)
    +                            .body(pollInfo.body)
    +                            .build());
    +                    return createHttpToolRespose(response);
    +                }};
    +                getPoller().scheduleAtFixedRate(pollJob, new DelegatingPollHandler(handlers),
minPeriod);
    --- End diff --
    
    Wrong indentation here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message