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:org.callimachusproject.rewrite.MissingAdviceFactory.java

private StatusLine getStatusLine(Method method) {
    if (method.isAnnotationPresent(disabled.class)) {
        String[] phrase = method.getAnnotation(disabled.class).value();
        if (phrase.length < 1) {
            phrase = new String[] { "Disabled" };
        }/*  w w  w .ja  v a 2s . co m*/
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 404, phrase[0]);
    }
    if (method.isAnnotationPresent(deleted.class)) {
        String[] phrase = method.getAnnotation(deleted.class).value();
        if (phrase.length < 1) {
            phrase = new String[] { "Deleted" };
        }
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 410, phrase[0]);
    }
    throw new AssertionError();
}

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

/**
 * Ctor.//from w w w . j  ava 2 s .c o  m
 *
 * @param xml the xml payload that YouTrack returns in 404 responses
 * @since 0.4.0
 */
@SuppressWarnings("checkstyle:MagicNumber")
public MockNotFoundResponse(String xml) {
    this.statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 404, "Not Found");
    this.payload = new StringEntity(xml, ContentType.APPLICATION_XML);
}

From source file:com.vsct.dt.strowgr.admin.repository.consul.ConsulReaderTest.java

@Test
public void should_throw_exception_when_status_out_of_range_200_299() {
    for (int status = 100; status < 600; status++) {
        if (status >= 200 && status < 300)
            continue; // skip
        // given/*from  w  ww .ja  va  2 s  .c om*/
        HttpResponse httpResponse = mock(HttpResponse.class);
        when(httpResponse.getStatusLine())
                .thenReturn(new BasicStatusLine(new ProtocolVersion("http1.1", 1, 1), status, ""));
        BasicHttpEntity givenHttpEntity = new BasicHttpEntity();
        givenHttpEntity.setContent(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)));
        when(httpResponse.getEntity()).thenReturn(givenHttpEntity);

        // test
        try {
            new ConsulReader(null).parseHttpResponse(httpResponse, this::getHttpEntity);
            // check
            fail("can't reach this point for status " + status);
        } catch (ClientProtocolException e) {
            // check
            assertThat(e.getMessage()).contains(String.valueOf(status));
        }
    }
}

From source file:com.eviware.soapui.impl.wsdl.support.CompressionSupport.java

public static byte[] decompress(String alg, byte[] content) throws Exception {
    // Use the excellent content encoding handling that exists in HTTP Client
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 0), 0, null));
    ByteArrayEntity entity = new ByteArrayEntity(content);
    entity.setContentEncoding(alg);/*  www.ja v a2s . com*/
    response.setEntity(entity);
    new ResponseContentEncoding().process(response, null);
    return IOUtils.toByteArray(response.getEntity().getContent());
}

From source file:com.intuit.qbsharedlib.qbo.network.mock.MockHttpClient.java

@Override
public HttpResponse execute(HttpUriRequest request) {
    requestExecuted = request;/*www.  j ava  2s .c  o  m*/
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    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:org.apache.camel.component.hipchat.HipchatEPSuccessTestSupport.java

public Producer createProducer() throws Exception {
    return new HipchatProducer(this) {
        @Override//from  www. j a  v a2s . c  om
        protected StatusLine post(String urlPath, Map<String, String> postParam) throws IOException {
            callback.call(postParam);
            return new BasicStatusLine(new ProtocolVersion("any", 1, 1), 204, "");
        }
    };
}

From source file:org.springframework.cloud.netflix.ribbon.apache.HttpClientStatusCodeExceptionTest.java

@Test
public void getResponse() throws Exception {
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    doReturn(new Locale("en")).when(response).getLocale();
    Header foo = new BasicHeader("foo", "bar");
    Header[] headers = new Header[] { foo };
    doReturn(headers).when(response).getAllHeaders();
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "Success");
    doReturn(statusLine).when(response).getStatusLine();
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream("foo".getBytes()));
    entity.setContentLength(3);/*from  w  w  w.  j  a v  a 2  s  .  c om*/
    doReturn(entity).when(response).getEntity();
    HttpEntity copiedEntity = HttpClientUtils.createEntity(response);
    HttpClientStatusCodeException ex = new HttpClientStatusCodeException("service", response, copiedEntity,
            new URI("http://service.com"));
    assertEquals("en", ex.getResponse().getLocale().toString());
    assertArrayEquals(headers, ex.getResponse().getAllHeaders());
    assertEquals("Success", ex.getResponse().getStatusLine().getReasonPhrase());
    assertEquals(200, ex.getResponse().getStatusLine().getStatusCode());
    assertEquals("http", ex.getResponse().getStatusLine().getProtocolVersion().getProtocol());
    assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMajor());
    assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMinor());
    assertEquals("foo", EntityUtils.toString(ex.getResponse().getEntity()));
    verify(response, times(1)).close();
}

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

@Test
public void testOkResponseCodeAnalysis() {

    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK");
    when(response.getStatusLine()).thenReturn(statusLine);

    RestClient.responseCodeAnalysis(response);

    verify(response).getStatusLine();//from ww  w  .  j a  v  a 2  s  .c om
}

From source file:bigbluej.CrawlerTest.java

@Test
public void shouldPost() 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"));
}

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

/**
 * Primary ctor.//w  w w .j  a v  a2s.  c om
 * Sets http status code 200.
 * @param payload the mock {@link HttpEntity} to set as payload
 * @param headers the mock {@link Header headers}
 * @since 0.4.0
 */
public MockOkResponse(HttpEntity payload, Header... headers) {
    this.statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1),
            // @checkstyle MagicNumber (1 line)
            200, "OK");
    this.payload = payload;
    this.headers = Arrays.asList(headers);
}