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.android.net.volley.mock.MockHttpClient.java

@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) {
    requestExecuted = request;//w  w  w .ja  v a2s  . c om
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(mResponseEntity);

    return response;
}

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

@Override
public void setStatusCode(int code) throws IllegalStateException {
    if (statusLine == null) {
        statusLine = new BasicStatusLine(DEFAULT_PROTOCOL_VERSION, code, "");
    } else {/*w  ww  .  j a  v  a  2 s . c o  m*/
        statusLine = new BasicStatusLine(statusLine.getProtocolVersion(), code, statusLine.getReasonPhrase());
    }
}

From source file:org.cryptable.pki.communication.http.PKIHTTPCommunicationTest.java

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

From source file:org.carewebframework.vista.api.mbroker.BrokerResponse.java

private static StatusLine createStatusLine(String statusLine) {
    String[] pcs = statusLine.split("\\ ", 3);
    String p1[] = pcs[0].split("\\/", 2);
    String p2[] = p1[1].split("\\.", 2);
    ProtocolVersion protocolVersion = new ProtocolVersion(p1[0], Integer.parseInt(p2[0]),
            Integer.parseInt(p2[1]));
    int statusCode = Integer.parseInt(pcs[1]);
    String reasonPhrase = pcs[2];
    return new BasicStatusLine(protocolVersion, statusCode, reasonPhrase);
}

From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolverTest.java

@Test
public void testSimpleGET() throws IOException {
    HTTPClientResponseResolver resolver = new TestableResolver();
    HttpResponse mockedResponse = mock(HttpResponse.class);
    when(mockedResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[0]);
    when(mockedResponse.getStatusLine()).thenReturn(new BasicStatusLine(new HttpVersion(1, 1), 200, "OK"));
    when(client.execute(Mockito.<HttpUriRequest>anyObject())).thenReturn(mockedResponse);
    HTTPResponse response = resolver.resolve(new HTTPRequest(URI.create("http://www.vg.no")));
    assertNotNull("Response was null", response);
    assertEquals("Wrong header size", 0, response.getHeaders().size());
    assertFalse("Response did have payload", response.hasPayload());
}

From source file:com.github.mfriedenhagen.artifactorygo.JsonResponseHandlerTest.java

/**
 * Test of handleResponse method, of class JsonResponseHandler.
 *//*from  www.j  a v  a2s  .  c om*/
@Test
public void testHandleResponse() throws Exception {
    final BasicStatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    when(mockedResponse.getStatusLine()).thenReturn(statusLine);
    final HttpEntity mockedEntity = mock(HttpEntity.class);
    when(mockedEntity.getContent())
            .thenReturn(JsonResponseHandlerTest.class.getResourceAsStream("/junit.json"));
    when(mockedResponse.getEntity()).thenReturn(mockedEntity);

    final ArtifactorySearchResults searchResults = sut.handleResponse(mockedResponse);
    final ArtifactoryStorage searchResult = searchResults.getResults().get(0);

    assertEquals(4, searchResults.getResults().size());
    assertEquals("http://localhost:8081/artifactory/api/storage/repo1-cache/junit/junit/4.11/junit-4.11.pom",
            searchResult.getUri().toString());
    assertEquals("http://localhost:8081/artifactory/repo1-cache/junit/junit/4.11/junit-4.11.pom",
            searchResult.getDownloadUri().toString());
}

From source file:org.jboss.tools.aerogear.hybrid.core.test.TestBundleHttpStorage.java

private HttpCacheEntry makeHttpCacheEntry() {
    final Date now = new Date();
    final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    final Header[] headers = { new BasicHeader("Date", DateUtils.formatDate(now)),
            new BasicHeader("Server", "MockServer/1.0") };
    final Resource resource = new HeapResource(new byte[0]);
    HttpCacheEntry entry = new HttpCacheEntry(now, now, statusLine, headers, resource);
    return entry;
}

From source file:org.envirocar.app.test.dao.TrackDecoderTest.java

private StatusLine createStatusLine() {
    return new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 204, "");
}

From source file:net.oneandone.shared.artifactory.JsonResponseHandlerTest.java

/**
 * Test of handleResponse method, of class JsonResponseHandler.
 *///  w ww  .  j  a v a 2 s .co m
@Test
public void testHandleResponse() throws Exception {
    final BasicStatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    when(mockedResponse.getStatusLine()).thenReturn(statusLine);
    final HttpEntity mockedEntity = mock(HttpEntity.class);
    when(mockedEntity.getContent())
            .thenReturn(JsonResponseHandlerTest.class.getResourceAsStream("/checksum.json"));
    when(mockedResponse.getEntity()).thenReturn(mockedEntity);
    final ArtifactoryChecksumResults checksumResults = sut.handleResponse(mockedResponse);
    final ArtifactoryChecksumResult checksumResult = checksumResults.results.get(0);
    assertEquals(
            "http://localhost:8081/artifactory/api/storage/plugins-snapshot-local/net/oneandone/maven/plugins/bill-of-materials-maven-plugin/2.1-SNAPSHOT/bill-of-materials-maven-plugin-2.1-SNAPSHOT-javadoc.jar",
            checksumResult.uri.toString());
}

From source file:com.joyent.manta.exception.MantaClientHttpResponseExceptionTest.java

private static HttpResponse responseWithErrorJson(final String json) {
    final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_SERVICE_UNAVAILABLE,
            "UNAVAILABLE");
    final HttpResponse response = mock(HttpResponse.class);
    when(response.getStatusLine()).thenReturn(statusLine);

    HttpEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
    when(response.getEntity()).thenReturn(entity);

    Header[] headers = new Header[] { new BasicHeader(HttpHeaders.DATE, "Wed, 13 Dec 2017 17:18:48 GMT"),
            new BasicHeader(HttpHeaders.SERVER, "Manta"),
            new BasicHeader(MantaHttpHeaders.REQUEST_ID, UUID.randomUUID().toString()),
            new BasicHeader("x-response-time", "198"), new BasicHeader(HttpHeaders.CONNECTION, "Keep-alive") };

    when(response.getAllHeaders()).thenReturn(headers);

    return response;
}