Example usage for org.apache.http.client.methods CloseableHttpResponse setHeader

List of usage examples for org.apache.http.client.methods CloseableHttpResponse setHeader

Introduction

In this page you can find the example usage for org.apache.http.client.methods CloseableHttpResponse setHeader.

Prototype

void setHeader(Header header);

Source Link

Usage

From source file:com.polydeucesys.eslogging.testutils.MockCloseableHttpClient.java

public static CloseableHttpResponse responseWithBody(final int statusCode, final String body) {
    CloseableHttpResponse resp = new BasicCloseableHttpResponse(new StatusLine() {
        @Override/*from   w w w  . j  a  v  a  2s. co m*/
        public int getStatusCode() {
            // TODO Auto-generated method stub
            return statusCode;
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getReasonPhrase() {
            // TODO Auto-generated method stub
            return null;
        }
    });
    resp.setEntity(new AbstractHttpEntity() {

        @Override
        public boolean isRepeatable() {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public long getContentLength() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public InputStream getContent() throws IOException, IllegalStateException {
            return new ByteArrayInputStream(body.getBytes());
        }

        @Override
        public void writeTo(OutputStream outstream) throws IOException {
            // TODO Auto-generated method stub

        }

        @Override
        public boolean isStreaming() {
            // TODO Auto-generated method stub
            return false;
        }

    });
    resp.setHeader(new BasicHeader("Content-Type", "text"));
    return resp;
}