brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #285: Adding HttpExecutor to be used for interc...
Date Mon, 05 Sep 2016 12:10:35 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/285#discussion_r77512748
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/http/executor/apacheclient/HttpResponseWrapper.java
---
    @@ -0,0 +1,109 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.http.executor.apacheclient;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.io.ByteArrayInputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.util.List;
    +import java.util.Map;
    +
    +import org.apache.brooklyn.util.guava.Maybe;
    +import org.apache.brooklyn.util.http.HttpToolResponse;
    +import org.apache.brooklyn.util.http.executor.HttpResponse;
    +import org.apache.http.HttpEntity;
    +import org.apache.http.util.EntityUtils;
    +
    +import com.google.common.annotations.Beta;
    +import com.google.common.collect.ArrayListMultimap;
    +import com.google.common.collect.Multimap;
    +import com.google.common.collect.Multimaps;
    +
    +@Beta
    +public class HttpResponseWrapper implements HttpResponse {
    +
    +    private final HttpToolResponse delegate;
    +    private transient volatile byte[] content;
    +    private transient volatile Multimap<String, String> headers;
    +    
    +    public HttpResponseWrapper(HttpToolResponse delegate) {
    +        this.delegate = checkNotNull(delegate, "response");
    +    }
    +
    +    @Override
    +    public void close() throws IOException {
    +        Maybe<org.apache.http.HttpResponse> apacheResponse = delegate.getResponse();
    +        if (apacheResponse.isPresent()) {
    +            HttpEntity entity = apacheResponse.get().getEntity();
    +            if (entity != null) {
    +                EntityUtils.consumeQuietly(apacheResponse.get().getEntity());
    +            }
    +        }
    +    }
    +
    +    @Override
    +    public int code() {
    +        return delegate.getResponseCode();
    +    }
    +
    +    @Override
    +    public String reasonPhrase() {
    +        return delegate.getReasonPhrase();
    +    }
    +
    +    @Override
    +    public Multimap<String, String> headers() {
    +        return headersImpl();
    +        
    +    }
    +
    +    @Override
    +    public long getContentLength() {
    +        byte[] content = getContentImpl();
    +        return (content == null) ? -1 : content.length;
    +    }
    +
    +    @Override
    +    public InputStream getContent() {
    +        byte[] content = getContentImpl();
    +        return (content == null) ? null : new ByteArrayInputStream(content);
    --- End diff --
    
    Isn't there API to get the stream directly?


---
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