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.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.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 a  v  a  2s  .  c  o m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
    String responseBody = "{\"message\": \"Successfully updated\"}";
    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:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportAuthsTest.java

@Before
public void setUp() throws Exception {
    httpClient = mock(HttpClient.class);
    response = mock(HttpResponse.class);
    crypto = mock(Crypto.class);
    when(response.getStatusLine())//www. ja v  a  2 s .c o  m
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
    String responseBody = "{\"auth_request\" : \"Expected auth_request\"}";
    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:com.nexmo.client.voice.endpoints.ReadCallMethodTest.java

@Test
public void parseResponse() throws Exception {
    HttpResponse stubResponse = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("1.1", 1, 1), 200, "OK"));

    String json = "      {\n" + "        \"uuid\": \"93137ee3-580e-45f7-a61a-e0b5716000ef\",\n"
            + "        \"status\": \"completed\",\n" + "        \"direction\": \"outbound\",\n"
            + "        \"rate\": \"0.02400000\",\n" + "        \"price\": \"0.00280000\",\n"
            + "        \"duration\": \"7\",\n" + "        \"network\": \"23410\",\n"
            + "        \"conversation_uuid\": \"aa17bd11-c895-4225-840d-30dc38c31e50\",\n"
            + "        \"start_time\": \"2017-01-13T13:55:02.000Z\",\n"
            + "        \"end_time\": \"2017-01-13T13:55:09.000Z\",\n" + "        \"to\": {\n"
            + "          \"type\": \"phone\",\n" + "          \"number\": \"447700900104\"\n" + "        },\n"
            + "        \"from\": {\n" + "          \"type\": \"phone\",\n"
            + "          \"number\": \"447700900105\"\n" + "        },\n" + "        \"_links\": {\n"
            + "          \"self\": {\n"
            + "            \"href\": \"/v1/calls/93137ee3-580e-45f7-a61a-e0b5716000ef\"\n" + "          }\n"
            + "        }\n" + "      }\n";
    InputStream jsonStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(jsonStream);/*from  ww  w  .  j  a v a 2s  .c o m*/
    stubResponse.setEntity(entity);

    CallInfo record = method.parseResponse(stubResponse);
    assertEquals("93137ee3-580e-45f7-a61a-e0b5716000ef", record.getUuid());
}

From source file:org.elasticsearch.client.HeapBufferedAsyncResponseConsumerTests.java

public void testResponseProcessing() throws Exception {
    ContentDecoder contentDecoder = mock(ContentDecoder.class);
    IOControl ioControl = mock(IOControl.class);
    HttpContext httpContext = mock(HttpContext.class);

    HeapBufferedAsyncResponseConsumer consumer = spy(new HeapBufferedAsyncResponseConsumer(TEST_BUFFER_LIMIT));

    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    httpResponse.setEntity(new StringEntity("test", ContentType.TEXT_PLAIN));

    //everything goes well
    consumer.responseReceived(httpResponse);
    consumer.consumeContent(contentDecoder, ioControl);
    consumer.responseCompleted(httpContext);

    verify(consumer).releaseResources();
    verify(consumer).buildResult(httpContext);
    assertTrue(consumer.isDone());/*from w  w w  . j  a  va2  s.  co m*/
    assertSame(httpResponse, consumer.getResult());

    consumer.responseCompleted(httpContext);
    verify(consumer, times(1)).releaseResources();
    verify(consumer, times(1)).buildResult(httpContext);
}

From source file:ste.web.http.api.BugFreeApiHandlerBase.java

@Before
public void setup() throws Exception {
    request = request(TEST_URI_PARAMETERS);
    context = new HttpSessionContext();
    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, getConnection());
    context.setAttribute(TEST_REQ_ATTR_NAME1, TEST_VALUE1);
    context.setAttribute(TEST_REQ_ATTR_NAME2, TEST_VALUE2);
    context.setAttribute(TEST_REQ_ATTR_NAME3, TEST_VALUE3);
    response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
    handler = new ApiHandler(new File(ROOT).getAbsolutePath());
}

From source file:net.oneandone.sushi.fs.webdav.methods.PropPatch.java

@Override
public Void processResponse(WebdavConnection connection, HttpResponse response) throws IOException {
    List<MultiStatus> lst;//from   w  w w .  j a va 2s .c o m
    MultiStatus ms;

    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
        throw new MovedException();
    case HttpStatus.SC_MULTI_STATUS:
        lst = MultiStatus.fromResponse(getXml(), response);
        ms = MultiStatus.lookupOne(lst, dest);
        if (ms.status != HttpStatus.SC_OK) {
            throw new StatusException(new BasicStatusLine(HttpVersion.HTTP_1_1, ms.status, null));
        }
        return null;
    default:
        throw new StatusException(response.getStatusLine());
    }
}

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

@Test
public void connect() throws IOException {
    HttpResponse response = mock(HttpResponse.class);
    when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(response);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HTTP_1_1, 200, "OK"));
    client.connect();//w  w w  . j a v  a  2  s . co m
}

From source file:bigbluej.CrawlerTest.java

@Test
public void shouldPostWithBody() throws IOException {
    String expectedResult = "break-out-prison";
    when(httpClientFactory.create()).thenReturn(httpClient);
    HttpResponse httpResponse = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("http", 100, 1), 200, ""));
    httpResponse.setEntity(new StringEntity(expectedResult));
    when(httpClient.execute((HttpUriRequest) anyObject())).thenReturn(httpResponse);
    assertEquals(expectedResult, crawler.post("the-url", "the-body"));
}

From source file:com.gooddata.http.client.LoginSSTRetrievalStrategyTest.java

@Test
public void obtainSstHeader() throws IOException {
    statusLine = new BasicStatusLine(new ProtocolVersion("https", 1, 1), HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(new StringEntity("--" + "  userLogin\n" + "    profile: /gdc/account/profile/1\n"
            + "    token: " + SST + "\n" + "    state: /gdc/account/login/1"));
    when(httpClient.execute(isA(HttpHost.class), isA(HttpPost.class))).thenReturn(response);

    assertEquals(SST, sstStrategy.obtainSst(httpClient, host));

    final ArgumentCaptor<HttpHost> hostCaptor = ArgumentCaptor.forClass(HttpHost.class);
    final ArgumentCaptor<HttpPost> postCaptor = ArgumentCaptor.forClass(HttpPost.class);

    verify(httpClient).execute(hostCaptor.capture(), postCaptor.capture());

    assertEquals("server.com", hostCaptor.getValue().getHostName());
    assertEquals(123, hostCaptor.getValue().getPort());

    final String postBody = "{\"postUserLogin\":{\"login\":\"" + LOGIN + "\",\"password\":\"" + PASSWORD
            + "\",\"remember\":0,\"verify_level\":2}}";//TODO: JSON assert
    StringWriter writer = new StringWriter();
    IOUtils.copy(postCaptor.getValue().getEntity().getContent(), writer, "UTF-8");

    assertEquals(postBody, writer.toString());
    assertEquals("/gdc/account/login", postCaptor.getValue().getURI().getPath());
}

From source file:com.orange.retrytest.OkHttpStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    OkHttpClient.Builder clientBuilder = client.newBuilder();
    int timeoutMs = request.getTimeoutMs();
    clientBuilder.connectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.writeTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    OkHttpClient client = clientBuilder.build();

    okhttp3.Request.Builder requestBuilder = new okhttp3.Request.Builder();
    requestBuilder.url(request.getUrl());

    setHeaders(requestBuilder, request, additionalHeaders);
    setConnectionParameters(requestBuilder, request);

    okhttp3.Request okHttpRequest = requestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();

    StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()),
            okHttpResponse.code(), okHttpResponse.message());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(getEntity(okHttpResponse));

    Headers responseHeaders = okHttpResponse.headers();
    for (int i = 0, len = responseHeaders.size(); i < len; i++) {
        response.addHeader(new BasicHeader(responseHeaders.name(i), responseHeaders.value(i)));
    }//from  w w  w  .jav  a2 s.  c o  m

    return response;
}