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

    https://github.com/apache/brooklyn-server/pull/285#discussion_r77348884
  
    --- Diff: core/src/main/java/org/apache/brooklyn/feed/http/HttpFeed.java ---
    @@ -331,52 +365,54 @@ 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)
    +                            .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();
    +        if (responseCode == 400) { // Unprocessable Entity - 
https://stackoverflow.com/questions/6123425/rest-response-code-for-invalid-data
    +            throw new IOException(" Unprocessable Entity: " + 
response.reasonPhrase());
    +        }
    --- End diff --
    
    Why are you interpreting the response here? Let the caller do it - 400 is 
not any special than other responses. Don't understand the error message as 
well - which entity are you referring to?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to