當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicStatusLine類代碼示例

本文整理匯總了Java中org.apache.http.message.BasicStatusLine的典型用法代碼示例。如果您正苦於以下問題:Java BasicStatusLine類的具體用法?Java BasicStatusLine怎麽用?Java BasicStatusLine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasicStatusLine類屬於org.apache.http.message包,在下文中一共展示了BasicStatusLine類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: post_whenResponseIsFailure_logsException

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void post_whenResponseIsFailure_logsException() throws IOException {
    ArgumentCaptor<HttpPost> requestCaptor = ArgumentCaptor.forClass(HttpPost.class);
    HttpClient httpClient = mock(HttpClient.class);
    BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1), 400, ""));
    response.setEntity(new StringEntity("failure reason here"));

    when(httpClient.execute(requestCaptor.capture())).thenReturn(response);

    MsTeamsNotification w = factory.getMsTeamsNotification(httpClient);

    MsTeamsNotificationPayloadContent content = new MsTeamsNotificationPayloadContent();
    content.setBuildDescriptionWithLinkSyntax("http://foo");
    content.setCommits(new ArrayList<Commit>());

    w.setPayload(content);
    w.setEnabled(true);
    w.post();

    assertNotNull(w.getResponse());
    assertFalse(w.getResponse().getOk());
}
 
開發者ID:spyder007,項目名稱:teamcity-msteams-notifier,代碼行數:23,代碼來源:MsTeamsNotificationTest.java

示例2: bufferLimitTest

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
private static void bufferLimitTest(HeapBufferedAsyncResponseConsumer consumer, int bufferLimit) throws Exception {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    consumer.onResponseReceived(new BasicHttpResponse(statusLine));

    final AtomicReference<Long> contentLength = new AtomicReference<>();
    HttpEntity entity = new StringEntity("", ContentType.APPLICATION_JSON) {
        @Override
        public long getContentLength() {
            return contentLength.get();
        }
    };
    contentLength.set(randomLong(bufferLimit));
    consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);

    contentLength.set(randomLongBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE));
    try {
        consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);
    } catch(ContentTooLongException e) {
        assertEquals("entity content is too long [" + entity.getContentLength() +
                "] for the configured buffer limit [" + bufferLimit + "]", e.getMessage());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:HeapBufferedAsyncResponseConsumerTests.java

示例3: testExecute_non2xx_exception

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void testExecute_non2xx_exception() throws IOException {
    HttpResponse resp = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "Not found"));
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream("{\"message\" : \"error payload\"}".getBytes()));
    resp.setEntity(entity);
    Mockito.doReturn(resp).when(mockClient).execute(any(HttpUriRequest.class), any(HttpContext.class));

    Map<String, String> headers = new HashMap<>();
    headers.put("Account-Id", "fubar");
    headers.put("Content-Type", "application/json");

    try {
        client.execute(
                new GenericApiGatewayRequestBuilder()
                        .withBody(new ByteArrayInputStream("test request".getBytes()))
                        .withHttpMethod(HttpMethodName.POST)
                        .withHeaders(headers)
                        .withResourcePath("/test/orders").build());

        Assert.fail("Expected exception");
    } catch (GenericApiGatewayException e) {
        assertEquals("Wrong status code", 404, e.getStatusCode());
        assertEquals("Wrong exception message", "{\"message\":\"error payload\"}", e.getErrorMessage());
    }
}
 
開發者ID:rpgreen,項目名稱:apigateway-generic-java-sdk,代碼行數:27,代碼來源:GenericApiGatewayClientTest.java

示例4: segmentInResponseToCode

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
private Segment segmentInResponseToCode(int code) {
    NoOpResponseHandler responseHandler = new NoOpResponseHandler();
    TracedResponseHandler<String> tracedResponseHandler = new TracedResponseHandler<>(responseHandler);
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, code, ""));

    Segment segment = AWSXRay.beginSegment("test");
    AWSXRay.beginSubsegment("someHttpCall");

    try {
        tracedResponseHandler.handleResponse(httpResponse);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    AWSXRay.endSubsegment();
    AWSXRay.endSegment();
    return segment;
}
 
開發者ID:aws,項目名稱:aws-xray-sdk-java,代碼行數:19,代碼來源:TracedResponseHandlerTest.java

示例5: logsRequestAndResponseFields

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void logsRequestAndResponseFields() {
    HttpContext context = new BasicHttpContext();
    context.setAttribute(HTTP_TARGET_HOST, "http://www.google.com");

    OutboundRequestLoggingInterceptor interceptor = new OutboundRequestLoggingInterceptor(new FakeClock(20));

    interceptor.process(new BasicHttpRequest("GET", "/something"), context);
    interceptor.process(new BasicHttpResponse(new BasicStatusLine(ANY_PROTOCOL, 200, "any")), context);

    Map<String, Object> fields = new ConcurrentHashMap<>();
    fields.put("requestMethod", "GET");
    fields.put("requestURI", "http://www.google.com/something");
    testAppender.assertEvent(0, INFO, "Outbound request start", appendEntries(fields));

    fields.put("responseTime", 20L);
    fields.put("responseCode", 200);
    testAppender.assertEvent(1, INFO, "Outbound request finish", appendEntries(fields));
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:20,代碼來源:OutboundRequestLoggingInterceptorTest.java

示例6: allowEmptyConstructorToBuildDefaultClock

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void allowEmptyConstructorToBuildDefaultClock() {
    testAppender.clearEvents();

    HttpContext context = new BasicHttpContext();
    context.setAttribute(HTTP_TARGET_HOST, "http://www.google.com");

    OutboundRequestLoggingInterceptor interceptor = new OutboundRequestLoggingInterceptor();

    interceptor.process(new BasicHttpRequest("GET", "/something"), context);
    interceptor.process(new BasicHttpResponse(new BasicStatusLine(ANY_PROTOCOL, 200, "any")), context);

    assertThat(testAppender.getEvents()).extracting("message")
        .contains("Outbound request start", Index.atIndex(0))
        .contains("Outbound request finish", Index.atIndex(1));
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:17,代碼來源:OutboundRequestLoggingInterceptorTest.java

示例7: waitForServerReady

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
/**
 * Wait for the server is ready.
 */
private void waitForServerReady() throws IOException, InterruptedException {
	final HttpGet httpget = new HttpGet(getPingUri());
	HttpResponse response = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, ""));
	int counter = 0;
	while (true) {
		try {
			response = httpclient.execute(httpget);
			final int status = response.getStatusLine().getStatusCode();
			if (status == HttpStatus.SC_OK) {
				break;
			}
			checkRetries(counter);
		} catch (final HttpHostConnectException ex) { // NOSONAR - Wait, and check later
			log.info("Check failed, retrying...");
			checkRetries(counter);
		} finally {
			EntityUtils.consume(response.getEntity());
		}
		counter++;
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:25,代碼來源:AbstractRestTest.java

示例8: downloadNewStatementsClosesEntityStream

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void downloadNewStatementsClosesEntityStream() throws Exception {
    final Config filesStep = ConfigFactory.parseString("{ method = get, path = /files }");
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    final HttpEntity entity = mock(HttpEntity.class);
    final InputStream stream = mock(InputStream.class);
    doReturn(Collections.singletonList(filesStep)).when(config).getConfigList("fileList");
    when(client.execute(any(HttpGet.class))).thenReturn(response);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null));
    when(response.getEntity()).thenReturn(entity);
    when(entity.isStreaming()).thenReturn(true);
    when(entity.getContent()).thenReturn(stream);

    download.downloadNewStatements();

    verify(response).getEntity();
    verify(entity).getContent();
    verify(stream).close();
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:20,代碼來源:FileDownloadTest.java

示例9: downloadNewStatementsCapturesResult

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void downloadNewStatementsCapturesResult() throws Exception {
    final Config filesStep = ConfigFactory.parseString("{ method = get, path = /files, " +
            "result = { format = json, extract = [{ name = var, selector = x }] } }");
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    final HttpEntity entity = mock(HttpEntity.class);
    final InputStream stream = new ByteArrayInputStream("{\"x\":\"value\"}".getBytes("UTF-8"));
    doReturn(Collections.singletonList(filesStep)).when(config).getConfigList("fileList");
    when(client.execute(any(HttpGet.class))).thenReturn(response);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null));
    when(response.getEntity()).thenReturn(entity);
    when(entity.getContent()).thenReturn(stream);

    download.downloadNewStatements();

    verify(response).getEntity();
    verify(context).putValue("var", "value");
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:19,代碼來源:FileDownloadTest.java

示例10: downloadNewStatementsCapturesFileList

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void downloadNewStatementsCapturesFileList() throws Exception {
    final Config filesStep = ConfigFactory.parseString("{ method = get, path = /files, " +
            "result = { format = html, files.selector = { path = li, fields = [\"text()\"] } } }");
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    final HttpEntity entity = mock(HttpEntity.class);
    final InputStream stream = new ByteArrayInputStream("<html><body><li>file url</li></body></html>".getBytes("UTF-8"));
    doReturn(Collections.singletonList(filesStep)).when(config).getConfigList("fileList");
    when(context.getBaseUrl()).thenReturn("http://example.com");
    when(client.execute(any(HttpGet.class))).thenReturn(response);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null));
    when(response.getEntity()).thenReturn(entity);
    when(entity.getContent()).thenReturn(stream);

    download.downloadNewStatements();

    verify(response).getEntity();
    verify(context).addFile(Collections.singletonList("file url"));
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:20,代碼來源:FileDownloadTest.java

示例11: downloadNewStatementsSavesNewFile

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
@Test
public void downloadNewStatementsSavesNewFile() throws Exception {
    final Config downloadStep = ConfigFactory.parseString("{ method = get, path = /files, save = true }");
    final CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    final HttpEntity entity = mock(HttpEntity.class);
    final InputStream stream = new ByteArrayInputStream("statement content".getBytes("UTF-8"));
    final List<Object> fileKeys = Collections.singletonList("file key");
    final File statement = new File("./test.txt");
    if (statement.exists()) statement.delete();
    doReturn(Collections.emptyList()).when(config).getConfigList("fileList");
    doReturn(Collections.singletonList(downloadStep)).when(config).getConfigList("download");
    when(context.getFileList()).thenReturn(Collections.singletonList(fileKeys));
    when(context.getFile(fileKeys)).thenReturn(statement);
    when(client.execute(any(HttpGet.class))).thenReturn(response);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null));
    when(response.getEntity()).thenReturn(entity);
    when(entity.getContent()).thenReturn(stream);

    download.downloadNewStatements();

    verify(response).getEntity();
    verify(context).addStatement(statement);
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:24,代碼來源:FileDownloadTest.java

示例12: canCreateInstance

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
public void canCreateInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_CREATED, "Created");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/instances/created.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    Instance instance = new Instance()
            .setName("some_name")
            .setPackageId(new UUID(12L, 24L))
            .setImage(new UUID(8L, 16L))
            .setTags(Collections.singletonMap(TEST_TAG_KEY, TEST_TAG));

    try (CloudApiConnectionContext context = createMockContext(response)) {
        final Instance created = instanceApi.create(context, instance);
        assertNotNull(created);
        assertNotNull(created.getId());
    }
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:20,代碼來源:InstancesTest.java

示例13: errorsCorrectlyWhenDeletingUnknownInstance

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
public void errorsCorrectlyWhenDeletingUnknownInstance() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/error/not_found.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    boolean thrown = false;

    try (CloudApiConnectionContext context = createMockContext(response)) {
        UUID instanceId = new UUID(512L, 1024L);
        instanceApi.delete(context, instanceId);
    } catch (CloudApiResponseException e) {
        thrown = true;
        assertTrue(e.getMessage().contains("VM not found"),
                   "Unexpected message on exception");
    }

    assertTrue(thrown, "CloudApiResponseException never thrown");
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:21,代碼來源:InstancesTest.java

示例14: canWaitForStateChangeWhenItAlreadyChanged

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
public void canWaitForStateChangeWhenItAlreadyChanged() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/domain/instance.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");
    final String stateToChangeFrom = "provisioning";

    try (CloudApiConnectionContext context = createMockContext(response)) {
        final Instance running = instanceApi.waitForStateChange(
                context, instanceId, stateToChangeFrom, 0L, 0L);

        assertEquals(running.getId(), instanceId, "ids should match");
        assertNotEquals(running.getState(), stateToChangeFrom,
                "shouldn't be in [" + stateToChangeFrom + "] state");
        assertEquals(running.getState(), "running", "should be in running state");
    }
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:21,代碼來源:InstancesTest.java

示例15: canFindRunningInstanceById

import org.apache.http.message.BasicStatusLine; //導入依賴的package包/類
public void canFindRunningInstanceById() throws IOException {
    final StatusLine statusLine = new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, "OK");
    final HttpResponse response = new BasicHttpResponse(statusLine);
    final File file = new File("src/test/data/domain/instance.json");
    final HttpEntity entity = new FileEntity(file);
    response.setEntity(entity);

    final UUID instanceId = UUID.fromString("c872d3bf-cbaa-4165-8e18-f6e3e1d94da9");

    try (CloudApiConnectionContext context = createMockContext(response)) {
        Instance found = instanceApi.findById(context, instanceId);

        assertNotNull(found, "expecting instance to be found");
        assertEquals(found.getId(), instanceId, "expecting ids to match");
    }
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:17,代碼來源:InstancesTest.java


注:本文中的org.apache.http.message.BasicStatusLine類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。