本文整理汇总了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());
}
示例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());
}
}
示例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());
}
}
示例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;
}
示例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));
}
示例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));
}
示例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++;
}
}
示例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();
}
示例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");
}
示例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"));
}
示例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);
}
示例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());
}
}
示例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");
}
示例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");
}
}
示例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");
}
}