Example usage for org.apache.http.message BasicHttpResponse BasicHttpResponse

List of usage examples for org.apache.http.message BasicHttpResponse BasicHttpResponse

Introduction

In this page you can find the example usage for org.apache.http.message BasicHttpResponse BasicHttpResponse.

Prototype

public BasicHttpResponse(ProtocolVersion protocolVersion, int i, String str) 

Source Link

Usage

From source file:com.comcast.cim.rest.client.xhtml.TestXhtmlResponseHandler.java

@Test
public void testDigestsValidXhtml() throws Exception {
    HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    resp.setHeader("Content-Type", "application/xhtml+xml;charset=utf-8");
    String xhtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML " + "1.0 Transitional//EN\" "
            + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
            + "<html xmlns=\"http://www.w3.org/1999/xhtml\" "
            + "xml:lang=\"en\" lang=\"en\"><head/><body/></html>";
    byte[] bytes = xhtml.getBytes();
    MockHttpEntity entity = new MockHttpEntity(bytes);
    resp.setEntity(entity);//from  www.  ja  v a  2  s.  c om
    resp.setHeader("Content-Length", "" + bytes.length);

    XhtmlApplicationState result = impl.handleResponse(resp);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getDocument());
    Assert.assertSame(resp, result.getHttpResponse());
}

From source file:org.deviceconnect.message.http.impl.factory.HttpResponseMessageFactory.java

@Override
public HttpResponse newPackagedMessage(final DConnectMessage message) {
    mLogger.entering(this.getClass().getName(), "newPackagedMessage", message);

    mLogger.fine("create http request from dmessage");
    HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
            EnglishReasonPhraseCatalog.INSTANCE.getReason(HttpStatus.SC_OK, null));

    mLogger.fine("put request headers");
    for (Header header : createHttpHeader(message)) {
        response.addHeader(header);/*from   w ww  .  ja v a 2s  . c  om*/
    }

    mLogger.fine("put request body");
    HttpEntity entity = createHttpEntity(message);
    response.addHeader(HTTP.CONTENT_LEN, "" + entity.getContentLength());
    response.setEntity(entity);

    mLogger.exiting(this.getClass().getName(), "newPackagedMessage", response);
    return response;
}

From source file:org.fao.geonet.MockCloseableHttpResponse.java

public MockCloseableHttpResponse(int responseCode, String statusReason, byte[] response) {
    _response = new BasicHttpResponse(HttpVersion.HTTP_1_1, responseCode, statusReason);
    _response.setEntity(new ByteArrayEntity(response));
}

From source file:org.esigate.test.http.HttpResponseBuilder.java

/**
 * Build the HTTP response using all data previously set on this builder and/or use defaults.
 * /*  ww w  . j  a  v a  2s.c  o  m*/
 * @return The HTTP response
 */
public CloseableHttpResponse build() {
    BasicHttpResponse response = new BasicHttpResponse(this.protocolVersion, this.status, this.reason);

    for (Header h : this.headers) {
        response.addHeader(h.getName(), h.getValue());
    }

    if (this.entity != null) {
        response.setEntity(this.entity);
    }
    return BasicCloseableHttpResponse.adapt(response);
}

From source file:org.fishwife.jrugged.httpclient.TestFailureExposingHttpClient.java

@Test
public void returns1XXResponseAsIs() throws Exception {
    for (int i = 100; i <= 199; i++) {
        resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, i, "1XX Thingy");
        backend.setResponse(resp);/*from w w  w .  j a v a2 s.  com*/
        assertSame(resp, impl.execute(host, req, ctx));
    }
}

From source file:org.ambraproject.wombat.util.HttpMessageUtilTest.java

@Test
public void testCopyResponseWithHeaders() throws IOException {
    byte[] testContent = "Test content".getBytes();

    HttpResponse input = new BasicHttpResponse(null, HttpStatus.OK.value(), "");
    BasicHttpEntity outputEntity = new BasicHttpEntity();
    outputEntity.setContent(new ByteArrayInputStream(testContent));
    input.setEntity(outputEntity);//from w  w  w  .j a  v a  2  s  .c  o m
    input.setHeader("includeMe", "foo");
    input.setHeader("excludeMe", "bar");
    input.setHeader("alterMe", "toBeAltered");

    HeaderFilter headerFilter = header -> {
        String name = header.getName();
        if ("includeMe".equalsIgnoreCase(name))
            return header.getValue();
        if ("alterMe".equalsIgnoreCase(name))
            return "altered";
        return null;
    };

    MockHttpServletResponse output = new MockHttpServletResponse();

    copyResponseWithHeaders(input, output, headerFilter);

    assertEquals(output.getContentAsByteArray(), testContent);

    assertEquals(output.getHeaderNames().size(), 2);
    assertEquals(output.getHeaders("includeMe"), ImmutableList.of("foo"));
    assertEquals(output.getHeaders("alterMe"), ImmutableList.of("altered"));
    assertEquals(output.getHeaders("excludeMe"), ImmutableList.of());
}

From source file:org.paolomoz.zehnkampf.utils.TestGenHTTPResponse.java

public void testWriteResponse() throws IOException {
    HttpEntity entity = new StringEntity(entityString);

    HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK");
    response.setHeader("Content-length", new Integer(entityString.length()).toString());
    response.setEntity(entity);/*from  w ww.j  a v a2  s  .c o  m*/

    assertEquals(1, response.getAllHeaders().length);
    assertEquals("HTTP/1.1 200 OK", response.getStatusLine().toString());

    OutputStream out = new ByteArrayOutputStream();
    genHTTPResp.writeResponse(response, out);

    assertEquals("HTTP/1.1 200 OK\r\n" + "Content-length: 4\r\n" + "\r\n" + "test", out.toString());
}

From source file:org.callimachusproject.server.chain.SecureChannelFilter.java

private BasicHttpResponse insecure() {
    String msg = "Cannot request secure resource over insecure channel";
    BasicHttpResponse resp;/*from   www. j  ava 2s  .c o  m*/
    resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, 400, msg);
    resp.setEntity(new StringEntity(msg, Charset.forName("UTF-8")));
    return resp;
}

From source file:com.autonomy.aci.client.services.impl.DocumentProcessorTest.java

@Test(expected = FactoryConfigurationError.class)
public void testConvertACIResponseToDOMInvalidDocumentBuilderFactory()
        throws AciErrorException, IOException, ProcessorException {
    // Set a duff property for the DocumentBuilderFactory...
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.autonomy.DuffDocumentBuilderFactory");

    try {/*from   w ww . j  a v a2 s . com*/
        // Setup with a proper XML response file...
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(new InputStreamEntity(getClass().getResourceAsStream("/GetVersion.xml"), -1));

        // Set the AciResponseInputStream...
        final AciResponseInputStream stream = new AciResponseInputStreamImpl(response);

        // Process...
        processor.process(stream);
        fail("Should have raised an ProcessorException.");
    } finally {
        // Remove the duff system property...
        System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
    }
}