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.intuit.elves.network.mock.MockHttpClient.java

@Override
public HttpResponse execute(HttpUriRequest request)
        throws java.io.IOException, org.apache.http.client.ClientProtocolException {
    if (mException != null) {
        throw mException;
    }/*www  .j  a va  2 s .  c  om*/
    requestExecuted = request;
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    if (mHeader != null) {
        response.addHeader(mHeader);
    }
    if (responseEntity != null) {
        response.setEntity(responseEntity);
    } else if (request instanceof HttpPost) { // put the request body back to response
        response.setEntity(((HttpPost) request).getEntity());
    }

    return response;
}

From source file:com.nominanuda.web.http.SerializeDeserializeTest.java

@Test
public void testResponse() throws IOException, HttpException {
    HttpResponse resp = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    resp.addHeader("h1", "v1");
    resp.setEntity(new StringEntity(PAYLOAD, ContentType.create("text/plain", "UTF-8")));
    byte[] serialized = HTTP.serialize(resp);
    //System.err.println(new String(serialized, "UTF-8"));
    HttpResponse m = (HttpResponse) HTTP.deserialize(new ByteArrayInputStream(serialized));
    //System.err.println(new String(HTTP.serialize(m), "UTF-8"));
    assertEquals(200, m.getStatusLine().getStatusCode());
    assertEquals(PAYLOAD.getBytes(HttpProtocol.CS_UTF_8).length,
            ((ByteArrayEntity) m.getEntity()).getContentLength());
    assertEquals("v1", m.getFirstHeader("h1").getValue());
}

From source file:org.apache.trafficcontrol.client.trafficops.TOSessionTest.java

@Test(expected = LoginException.class)
public void test401Response() throws Throwable {
    HttpResponse resp = Mockito.mock(HttpResponse.class);
    Mockito.when(resp.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_0, 401, "Not Auth"));

    final CompletableFuture<HttpResponse> f = new CompletableFuture<>();
    f.complete(resp);// w w  w  . ja  v a 2  s.  co m

    Mockito.doReturn(f).when(sessionMock).execute(Mockito.any(RequestBuilder.class));

    TOSession session = TOSession.builder().fromURI(baseUri).setRestClient(sessionMock).build();

    try {
        session.getDeliveryServices().get();
    } catch (Throwable e) {
        throw e.getCause();
    }
}

From source file:com.thistech.spotlink.AbstractSpotlinkTest.java

protected HttpResponse prepareResponse(int expectedResponseStatus, String expectedResponseBody) {
    HttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), expectedResponseStatus, ""));
    response.setStatusCode(expectedResponseStatus);
    try {/*w  ww.j  ava 2s .c  o m*/
        response.setEntity(new StringEntity(expectedResponseBody));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    return response;
}

From source file:org.onehippo.cms7.brokenlinks.TestHttpClient.java

@Override
public HttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException {
    final URI uri = request.getURI();
    final BasicStatusLine statusline;
    if (!"good".equals(uri.getHost())) {
        statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found");
    } else {//w w  w.  ja  v a  2s  .c om
        statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    }
    return new BasicHttpResponse(statusline);
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPingTest.java

@Before
public void setUp() throws Exception {
    httpClient = mock(HttpClient.class);
    response = mock(HttpResponse.class);
    crypto = mock(Crypto.class);
    when(response.getStatusLine())/*  w w w . ja v  a 2 s .  c  o  m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
    String responseBody = "{\"date_stamp\" : \"2001-01-01 01:01:01\","
            + "\"launchkey_time\" : \"2002-02-02 02:02:02\"," + "\"key\" : \"Expected Public Key\"}";
    when(response.getEntity()).thenReturn(
            EntityBuilder.create().setStream(new ByteArrayInputStream(responseBody.getBytes("UTF-8"))).build());
    transport = new ApacheHttpClientTransport(httpClient, "https://api.launchkey.com/v1", crypto);
    when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(response);
}

From source file:co.cask.cdap.client.rest.RestClientTest.java

@Test
public void testBadRequestResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_BAD_REQUEST,
            "Bad Request");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_BAD_REQUEST, response);
    verify(response).getStatusLine();//  w  w w .  java 2s.  co  m
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java

@Before
public void setUp() throws Exception {
    httpClient = mock(HttpClient.class);
    response = mock(HttpResponse.class);
    crypto = mock(Crypto.class);
    when(response.getStatusLine())/*  w  w  w.j av a  2s . co m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
    String responseBody = "{\"user_hash\": \"User Hash\", \"auth\": \"Auth\", \"organization_user\": \"Org User\", \"user_push_id\": \"Push ID\"}";
    when(response.getEntity()).thenReturn(
            EntityBuilder.create().setStream(new ByteArrayInputStream(responseBody.getBytes("UTF-8"))).build());
    transport = new ApacheHttpClientTransport(httpClient, "https://api.launchkey.com/v1", crypto);
    when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(response);
}

From source file:bit.changepurse.wdk.http.MockedApacheResponse.java

@Override
public void setReasonPhrase(String reason) throws IllegalStateException {
    if (statusLine == null) {
        statusLine = new BasicStatusLine(DEFAULT_PROTOCOL_VERSION, 200, reason);
    } else {/*  w w  w  .j  a v  a2  s .com*/
        statusLine = new BasicStatusLine(statusLine.getProtocolVersion(), statusLine.getStatusCode(), reason);
    }
}

From source file:se.vgregion.urlservice.services.SambaFacilitiesServiceTest.java

@Before
public void before() throws IOException {
    MockitoAnnotations.initMocks(this);

    facilityService.setSambaBaseUrl(URI.create("http://example.com/"));

    when(httpClientFactory.getClient()).thenReturn(httpClient);
    when(httpClient.execute(Mockito.any(HttpUriRequest.class))).thenReturn(httpResponse);
    when(httpResponse.getEntity()).thenReturn(httpEntity);
    when(httpResponse.getStatusLine())// ww w.j  ava  2  s .co  m
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 0), 200, "OK"));

    facilityService.setHttpClientFactory(httpClientFactory);
}