本文整理了Java中com.amazonaws.http.HttpResponse.builder()
方法的一些代码示例,展示了HttpResponse.builder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.builder()
方法的具体详情如下:
包路径:com.amazonaws.http.HttpResponse
类名称:HttpResponse
方法名:builder
[英]Creates a builder for HttpResponse.
[中]为HttpResponse创建生成器。
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public HttpResponse execute(HttpRequest request) throws IOException {
HttpUriRequest httpRequest = createHttpRequest(request);
org.apache.http.HttpResponse httpResponse = httpClient.execute(httpRequest);
String statusText = httpResponse.getStatusLine().getReasonPhrase();
int statusCode = httpResponse.getStatusLine().getStatusCode();
InputStream content = null;
if (httpResponse.getEntity() != null) {
content = httpResponse.getEntity().getContent();
}
HttpResponse.Builder builder = HttpResponse.builder()
.statusCode(statusCode)
.statusText(statusText)
.content(content);
for (Header header : httpResponse.getAllHeaders()) {
builder.header(header.getName(), header.getValue());
}
return builder.build();
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public HttpResponse execute(HttpRequest request) throws IOException {
return HttpResponse.builder()
.statusCode(statusCode)
.statusText(reasonPhrase)
.build();
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonErrorResponseReturnsNullIfExceptionIsNull() throws Exception {
List<JsonErrorUnmarshaller> exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>();
exceptionUnmarshallers.add(new JsonErrorUnmarshaller() {
@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
return null;
}
});
handler = new JsonErrorResponseHandler(exceptionUnmarshallers);
response = HttpResponse.builder()
.statusCode(403)
.content(new ByteArrayInputStream("{}".getBytes(StringUtils.UTF8)))
.build();
assertNull(handler.handle(response));
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonErrorResponse() throws Exception {
String body = "{\"__type\":\"InvalidSignatureException\",\"message\":\"Clock is skewed\"}";
ByteArrayInputStream content = new ByteArrayInputStream(body.getBytes(StringUtils.UTF8));
response = HttpResponse.builder()
.content(content)
.statusCode(403)
.build();
AmazonServiceException ase = handler.handle(response);
assertEquals(ase.getErrorCode(), "InvalidSignatureException");
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testRestJsonErrorResponse() throws Exception {
String body = "{\"message\":\"Clock is skewed\"}";
ByteArrayInputStream content = new ByteArrayInputStream(body.getBytes(StringUtils.UTF8));
response = HttpResponse.builder()
.content(content)
.statusCode(403)
.header("x-amzn-ErrorType", "InvalidSignatureException")
.build();
AmazonServiceException ase = handler.handle(response);
assertEquals(ase.getErrorCode(), "InvalidSignatureException");
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test(expected = UnsupportedOperationException.class)
public void testUnmodifierableHeaders() {
builder = HttpResponse.builder()
.statusCode(statusCode)
.statusText(statusText)
.content(content);
response = builder.build();
response.getHeaders().put("key", "value");
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonErrorResponseReturnsServiceErrorTypeIfErrorStatus5XX() throws Exception {
List<JsonErrorUnmarshaller> exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>();
exceptionUnmarshallers.add(new JsonErrorUnmarshaller() {
@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
return new AmazonServiceException("TestException");
}
});
handler = new JsonErrorResponseHandler(exceptionUnmarshallers);
response = HttpResponse.builder()
.statusCode(500)
.content(new ByteArrayInputStream("{}".getBytes(StringUtils.UTF8)))
.build();
AmazonServiceException returnedException = handler.handle(response);
assertEquals(returnedException.getErrorType(), ErrorType.Service);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonErrorResponseReturnsXAmzRequestId() throws Exception {
List<JsonErrorUnmarshaller> exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>();
exceptionUnmarshallers.add(new JsonErrorUnmarshaller() {
@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
return new AmazonServiceException("TestException");
}
});
handler = new JsonErrorResponseHandler(exceptionUnmarshallers);
response = HttpResponse.builder()
.statusCode(500)
.header("X-Amzn-RequestId", "55")
.content(new ByteArrayInputStream("{}".getBytes(StringUtils.UTF8)))
.build();
AmazonServiceException returnedException = handler.handle(response);
assertEquals(returnedException.getRequestId(), "55");
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseExpirationHeader2() {
MockObjectExpirationResult result = new MockObjectExpirationResult();
ObjectExpirationHeaderHandler<MockObjectExpirationResult> handler =
new ObjectExpirationHeaderHandler<MockObjectExpirationResult>();
HttpResponse response = HttpResponse.builder()
.header("x-amz-expiration",
"rule-id=\"Test\", expiry-date=\"Tue, 01 Jan 2013 00:00:00 GMT\"")
.build();
handler.handle(result, response);
Assert.assertEquals(1356998400000L,
result.getExpirationTime().getTime());
Assert.assertEquals("Test", result.getExpirationTimeRuleId());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testContentEncodingGZIPRaw() throws Exception {
String str = "content to be zipped";
InputStream zippedContent = getGzippedInputStream(str);
builder = HttpResponse.builder()
.header("Content-Encoding", "gzip")
.content(zippedContent);
response = builder.build();
InputStream rawContent = response.getRawContent();
assertFalse("Not gzip", rawContent instanceof GZIPInputStream);
GZIPInputStream gis = new GZIPInputStream(rawContent);
String result = IOUtils.toString(gis);
assertEquals("unzip correctly", str, result);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseExpirationHeader1() {
MockObjectExpirationResult result = new MockObjectExpirationResult();
ObjectExpirationHeaderHandler<MockObjectExpirationResult> handler =
new ObjectExpirationHeaderHandler<MockObjectExpirationResult>();
HttpResponse response = HttpResponse.builder()
.header("x-amz-expiration",
"expiry-date=\"Tue, 01 Jan 2013 00:00:00 GMT\", rule-id=\"Test\"")
.build();
handler.handle(result, response);
Assert.assertEquals(1356998400000L,
result.getExpirationTime().getTime());
Assert.assertEquals("Test", result.getExpirationTimeRuleId());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseRestoreHeader2() {
MockObjectRestoreResult result = new MockObjectRestoreResult();
ObjectRestoreHeaderHandler<MockObjectRestoreResult> handler =
new ObjectRestoreHeaderHandler<MockObjectRestoreResult>();
HttpResponse response = HttpResponse.builder()
.header("x-amz-restore",
"ongoing-request=\"false\", "
+ "expiry-date=\"Tue, 01 Jan 2013 00:00:00 GMT\"")
.build();
handler.handle(result, response);
Assert.assertFalse(result.getOngoingRestore());
Assert.assertEquals(1356998400000L,
result.getRestoreExpirationTime().getTime());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseRestoreHeader3() {
MockObjectRestoreResult result = new MockObjectRestoreResult();
ObjectRestoreHeaderHandler<MockObjectRestoreResult> handler =
new ObjectRestoreHeaderHandler<MockObjectRestoreResult>();
HttpResponse response = HttpResponse.builder()
.header("x-amz-restore",
"expiry-date=\"Tue, 01 Jan 2013 00:00:00 GMT\", "
+ "ongoing-request=\"false\"")
.build();
handler.handle(result, response);
Assert.assertFalse(result.getOngoingRestore());
Assert.assertEquals(1356998400000L,
result.getRestoreExpirationTime().getTime());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseRestoreHeader1() {
MockObjectRestoreResult result = new MockObjectRestoreResult();
ObjectRestoreHeaderHandler<MockObjectRestoreResult> handler =
new ObjectRestoreHeaderHandler<MockObjectRestoreResult>();
HttpResponse response = HttpResponse.builder()
.header("x-amz-restore", "ongoing-request=\"true\"")
.build();
handler.handle(result, response);
Assert.assertTrue(result.getOngoingRestore());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseEmptyRestoreHeader() {
MockObjectRestoreResult result = new MockObjectRestoreResult();
ObjectRestoreHeaderHandler<MockObjectRestoreResult> handler =
new ObjectRestoreHeaderHandler<MockObjectRestoreResult>();
HttpResponse response = HttpResponse.builder().build();
handler.handle(result, response);
Assert.assertNull(result.getRestoreExpirationTime());
Assert.assertNull(result.getOngoingRestore());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testContentEncodingIdentity() throws Exception {
builder = HttpResponse.builder()
.header("Content-Encoding", "identity")
.content(content);
response = builder.build();
assertFalse("Not gzip", response.getContent() instanceof GZIPInputStream);
assertEquals("same content", "content", IOUtils.toString(response.getContent()));
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testParseEmptyExpirationHeader() {
MockObjectExpirationResult result = new MockObjectExpirationResult();
ObjectExpirationHeaderHandler<MockObjectExpirationResult> handler =
new ObjectExpirationHeaderHandler<MockObjectExpirationResult>();
HttpResponse response = HttpResponse.builder().build();
handler.handle(result, response);
Assert.assertNull(result.getExpirationTime());
Assert.assertNull(result.getExpirationTimeRuleId());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testJsonExceptionUnmarshallerWithAdditionalFields() throws Exception {
HttpResponse response = HttpResponse.builder()
.content(new ByteArrayInputStream(errorResponse.getBytes("UTF-8")))
.build();
JsonErrorResponse error = JsonErrorResponse.fromResponse(response);
AmazonServiceException ase = new InternalServerErrorExceptionUnmarshaller()
.unmarshall(error);
assertTrue(ase instanceof InternalServerErrorException);
assertEquals("value1", ((InternalServerErrorException) ase).getField1());
assertEquals("value2", ((InternalServerErrorException) ase).getField2());
assertEquals("InternalServerError", ase.getErrorCode());
assertEquals("Requested resource not found "
+ "(Service: null; "
+ "Status Code: 0; "
+ "Error Code: InternalServerError; "
+ "Request ID: null)",
ase.getMessage());
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testContentEncodingGZIP() throws Exception {
String str = "content to be zipped";
InputStream zippedContent = getGzippedInputStream(str);
builder = HttpResponse.builder()
.header("Content-Encoding", "gzip")
.content(zippedContent);
response = builder.build();
InputStream unzippedContent = response.getContent();
assertTrue(unzippedContent instanceof GZIPInputStream);
String result = IOUtils.toString(unzippedContent);
assertEquals("unzip correctly", str, result);
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testBuilder() throws Exception {
builder = HttpResponse.builder()
.statusCode(statusCode)
.statusText(statusText)
.content(content);
for (int i = 0; i < 10; i++) {
builder.header("key" + i, "value" + i);
}
response = builder.build();
assertEquals("status text", statusText, response.getStatusText());
assertTrue("status code", statusCode == response.getStatusCode());
assertTrue("has headers", 10 == response.getHeaders().size());
assertEquals("content", content, response.getContent());
}
内容来源于网络,如有侵权,请联系作者删除!