Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/285#discussion_r77535388
  
    --- Diff: core/src/main/java/org/apache/brooklyn/feed/http/HttpFeed.java ---
    @@ -331,52 +366,55 @@ 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);
    +                    UsernamePassword creds = null;
    +                    if (pollInfo.credentials.isPresent()) {
    +                        creds =  new UsernamePassword(
    +                                
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)
    +                            .config(HttpConfig.builder()
    +                                    .trustSelfSigned(true)
    +                                    .trustAll(true)
    +                                    .laxRedirect(true)
    +                                    .build())
    +                            .build());
    +                    return createHttpToolRespose(response);
    +                }};
    +                getPoller().scheduleAtFixedRate(pollJob, new 
DelegatingPollHandler(handlers), minPeriod);
             }
    -        return builder.build();
         }
     
         @SuppressWarnings("unchecked")
         protected Poller<HttpToolResponse> getPoller() {
    -        return (Poller<HttpToolResponse>) super.getPoller();
    +        return  (Poller<HttpToolResponse>) super.getPoller();
    +    }
    +
    +    @SuppressWarnings("unchecked")
    +    private HttpToolResponse createHttpToolRespose(HttpResponse response) 
throws IOException {
    +        int responseCode = response.code();
    +
    +        Map<String,? extends List<String>> headers = (Map<String, 
List<String>>) (Map<?, ?>) response.headers().asMap();
    +
    +        byte[] content = null;
    +        if (response.getContentLength() > 0) {
    --- End diff --
    
    Better copy the current logic from 
[HttpToolResponse](https://github.com/apache/brooklyn-server/blob/master/utils/common/src/main/java/org/apache/brooklyn/util/http/HttpToolResponse.java#L69-L81)
 as it's been battle-tested.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to