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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.vikingbrain.nmt.test.util.MockUtils.java

public static HttpResponse prepareHttpResponse(int expectedResponseStatus, String expectedResponseBody) {
    HttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), expectedResponseStatus, ""));
    response.setStatusCode(expectedResponseStatus);
    try {/*  ww  w. j  a v  a  2  s .  co m*/
        response.setEntity(new StringEntity(expectedResponseBody));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    return response;
}

From source file:com.microsoft.alm.plugin.mocks.MockCatalogService.java

public void addResponse(String response) throws HttpException {
    final HttpResponse httpResponse = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("https", 1, 0), HttpStatus.SC_OK, "reason"));
    final BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream(response.getBytes()));
    httpResponse.setEntity(entity);/* w ww. j  av a2 s .  com*/
    responses.add(httpResponse);
}

From source file:com.couchbase.cbadmin.client.RestApiException.java

static private StatusLine defaultStatusLine(String s, int code) {
    if (s == null) {
        s = "Client Error";
    }//from  w w  w .j  av a 2s  .  co  m

    return new BasicStatusLine(new ProtocolVersion("HTTP", 1, 0), code, s);
}

From source file:org.apache.kylin.jdbc.TestUtil.java

public static HttpResponse mockHttpResponse(int statusCode, String message, String body) {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusLine())
            .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, message));
    Mockito.when(response.getEntity()).thenReturn(new StringEntity(body, StandardCharsets.UTF_8));
    return response;
}

From source file:gov.nasa.arc.geocam.memo.service.test.SiteAuthCookieImplementationTest.java

private void prepLoginResponse(boolean successful) {
    int statusCode = successful ? 302 : 200;
    StatusLine sl = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 0), statusCode, "some reason");
    HttpResponse response = new BasicHttpResponse(sl);

    response.addHeader("Set-Cookie", " sessionid=value2; Expires=Sat, 01 Jan 2050 10:18:14 GMT");

    Robolectric.addPendingHttpResponse(response);
}

From source file:com.betfair.testing.utils.cougar.manager.CougarTestDAO.java

public org.apache.http.HttpResponse executeHttpMethodBaseCall(HttpUriRequest method) {
    // TODO Auto-generated method stub
    methods.add(method);//w  w w .j  a  va2s. co  m
    final BasicHttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""));
    try {
        response.setEntity(new StringEntity("test"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    return response;
}

From source file:com.nesscomputing.httpclient.factory.httpclient4.InternalResponseTest.java

@Test
public void testCaseInsensitiveHeaders() {
    HttpRequestBase req = new HttpGet();
    HttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
    response.setHeaders(new Header[] { new BasicHeader("namE1", "val1"), new BasicHeader("Name1", "val2"),
            new BasicHeader("NAME1", "val3") });

    HttpClientResponse clientResponse = new InternalResponse(req, response);

    Map<String, List<String>> expectedAllHeaders = Maps.newHashMap();
    List<String> values = Lists.newArrayList("val1", "val2", "val3");

    expectedAllHeaders.put("namE1", values);

    assertEquals(values, clientResponse.getHeaders("name1"));
    assertEquals(values, clientResponse.getHeaders("naMe1"));

    assertEquals(expectedAllHeaders, clientResponse.getAllHeaders());
}

From source file:org.esigate.servlet.impl.ResponseSenderTest.java

public void testSendResponseAlreadySent() throws Exception {
    MockHttpServletResponse httpServletResponse = new MockHttpServletResponse();
    PrintWriter writer = httpServletResponse.getWriter();
    writer.write("Test");
    writer.close();/*from  w w  w .j a  v  a2s  .c  o  m*/
    CloseableHttpResponse httpClientResponse = BasicCloseableHttpResponse
            .adapt(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK")));
    httpClientResponse.setEntity(new StringEntity("Abcdefg"));
    renderer.sendResponse(httpClientResponse, null, httpServletResponse);
}

From source file:org.llorllale.youtrack.api.mock.http.response.MockForbiddenResponse.java

/**
 * Ctor./*  w ww  .  j  ava2s  . c  o m*/
 *
 * @since 0.4.0
 */
@SuppressWarnings("checkstyle:MagicNumber")
public MockForbiddenResponse() {
    this.statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 403, "Forbidden");
}

From source file:es.tid.fiware.rss.oauth.test.ResponseHandlerTest.java

/**
 * /*from w w  w  .  j  a va  2  s  .  c o  m*/
 */
@Test
public void handleResponseTest() throws Exception {
    ResponseHandler handler = new ResponseHandler();
    HttpResponseFactory factory = new DefaultHttpResponseFactory();
    HttpResponse responseSent = factory
            .newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "reason"), null);
    HttpResponse response = handler.handleResponse(responseSent);
    Assert.assertEquals(handler.getStatus(), HttpStatus.SC_OK);
    Assert.assertFalse(handler.hasContent());
    // response with content.
    BasicHttpEntity entity = new BasicHttpEntity();
    InputStream inputStream = new ByteArrayInputStream("new content".getBytes());
    entity.setContent(inputStream);
    entity.setContentLength("new content".length()); // sets the length
    response.setEntity(entity);
    response = handler.handleResponse(responseSent);
    Assert.assertEquals("new content", handler.getResponseContent());
}