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.github.avarabyeu.restendpoint.http.DefaultErrorHandlerTest.java

private HttpResponse getHttpResponse(int statusCode, String message) {
    StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, message);
    BasicHttpResponse response = new BasicHttpResponse(statusLine, EnglishReasonPhraseCatalog.INSTANCE,
            Locale.US);//from   w w  w .j a  v  a2s .c  o  m
    response.setEntity(new StringEntity("test string response body", Consts.UTF_8));
    return response;
}

From source file:org.sonatype.nexus.repository.proxy.ProxyFacetSupportTest.java

@Test
public void testGet_ProxyServiceException_contentReturnedIfCached() throws IOException {
    when(cacheController.isStale(cacheInfo)).thenReturn(true);
    doReturn(content).when(underTest).getCachedContent(cachedContext);

    doThrow(new ProxyServiceException(new BasicHttpResponse(null, 503, "Offline"))).when(underTest)
            .fetch(cachedContext, content);

    Content foundContent = underTest.get(cachedContext);

    assertThat(foundContent, is(content));
}

From source file:com.optimizely.ab.config.HttpProjectConfigManagerTest.java

@Test
@Ignore/*from  w  w  w .java 2s . c  o  m*/
public void testGetDatafileHttpResponse2XX() throws Exception {
    String modifiedStamp = "Wed, 24 Apr 2019 07:07:07 GMT";
    HttpResponse getResponse = new BasicHttpResponse(new ProtocolVersion("TEST", 0, 0), 200, "TEST");
    getResponse.setEntity(new StringEntity(datafileString));
    getResponse.setHeader(HttpHeaders.LAST_MODIFIED, modifiedStamp);

    String datafile = projectConfigManager.getDatafileFromResponse(getResponse);
    assertNotNull(datafile);

    assertEquals("4", parseProjectConfig(datafile).getVersion());
    // Confirm last modified time is set
    assertEquals(modifiedStamp, projectConfigManager.getLastModified());
}

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

@Test
public void reusesWrapperForRequestsFromEquivalentHostsDefaultHttpPort() throws Exception {
    ServiceWrapper wrapper = new NullWrapper();
    HttpUriRequest req1 = new HttpGet("http://foo.example.com/bar");
    HttpUriRequest req2 = new HttpGet("http://foo.example.com:80/baz");
    HttpResponse resp1 = resp;/*from   www  .  j  a  v a 2 s  .  co  m*/
    HttpResponse resp2 = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    expect(mockFactory.getWrapperWithName(isA(String.class))).andReturn(wrapper);
    expect(mockBackend.execute(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpContext.class)))
            .andReturn(resp1);
    expect(mockBackend.execute(isA(HttpHost.class), isA(HttpRequest.class), isA(HttpContext.class)))
            .andReturn(resp2);

    replayMocks();
    impl.execute(req1, ctx);
    impl.execute(req2, ctx);
    verifyMocks();
}

From source file:groovyx.net.http.thirdparty.GAEClientConnection.java

public HttpResponse receiveResponseHeader() throws HttpException, IOException {
    if (this.response == null) {
        flush();/*from   ww  w . j a v a 2  s .  c  om*/
    }

    HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
            this.response.getResponseCode(), null);
    //     System.err.println("RECV: " + response.getStatusLine());

    for (HTTPHeader h : this.response.getHeaders()) {
        //       System.err.println("RECV: " + h.getName() + ": " + h.getValue());
        response.addHeader(h.getName(), h.getValue());
    }

    return response;
}

From source file:org.dataconservancy.ui.services.EZIDServiceImplTest.java

/**
 * Tests that delete is called succesfully without throwing exception
 * @throws ClientProtocolException//from   w ww  . j  av a 2s  . c  o m
 * @throws IOException
 */
@Test
public void testSuccessfulDelete() throws ClientProtocolException, IOException {
    boolean noExceptions = true;
    HttpResponse mockResponse = new BasicHttpResponse(new HttpVersion(1, 1), 200, "ok");
    StringEntity entity = new StringEntity("success: namespace:id");
    mockResponse.setEntity(entity);

    HttpClient mockHttpClient = mock(HttpClient.class);
    when(mockHttpClient.execute(any(HttpDelete.class))).thenReturn(mockResponse);

    ezidService.setHttpClient(mockHttpClient);

    try {
        ezidService.deleteID("www.test.com/id/namespace:id");
    } catch (EZIDServiceException e) {
        noExceptions = false;
    }

    assertTrue(noExceptions);
}

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

public HttpResponse setOK(File requestedFile) throws FileNotFoundException, UnsupportedEncodingException {
    HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    HttpEntity entity = null;//from ww w .j a va2s  .co m
    if (requestedFile.isDirectory()) {
        entity = getDirectoryEntity(requestedFile);
    } else {
        int fileLen = (int) requestedFile.length();
        BufferedInputStream fileIn = new BufferedInputStream(new FileInputStream(requestedFile));

        // Detect the content mimetype
        String mimeTypeName = new MimetypesFileTypeMap().getContentType(requestedFile);

        response.setHeader("Content-Type", mimeTypeName);
        response.setHeader("Content-length", new Integer(fileLen).toString());
        entity = new InputStreamEntity(fileIn, fileLen);
    }
    response.setEntity(entity);
    return response;
}

From source file:com.favalike.http.GAEClientConnection.java

@Override
public HttpResponse receiveResponseHeader() throws HttpException, IOException {
    if (this.response == null) {
        flush();/*  w  w w.j a  v a2  s  . c o m*/
    }

    HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1),
            this.response.getResponseCode(), null);

    for (HTTPHeader h : this.response.getHeaders()) {
        response.addHeader(h.getName(), h.getValue());
    }

    return response;
}

From source file:com.salesforce.dva.argus.service.callback.DefaultCallbackService.java

private static HttpResponse errorResponse(String reason, Throwable t) {
    return new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 500,
            String.format("%s: %s", reason, t.getMessage()));
}

From source file:com.shopgun.android.sdk.network.impl.HttpURLNetwork.java

private HttpResponse getHttpResponse(HttpURLConnection connection) throws IOException {

    ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
    String rm = connection.getResponseMessage();
    HttpResponse response = new BasicHttpResponse(pv, connection.getResponseCode(), rm);

    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);/*from   w  w  w  .j a  v  a2 s.  c  o m*/
        }
    }

    return response;
}