本文整理了Java中com.amazonaws.http.HttpResponse.getContent()
方法的一些代码示例,展示了HttpResponse.getContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getContent()
方法的具体详情如下:
包路径:com.amazonaws.http.HttpResponse
类名称:HttpResponse
方法名:getContent
[英]Returns the input stream containing the response content.
[中]返回包含响应内容的输入流。
代码示例来源:origin: apache/nifi
public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException {
this.httpResponse = httpResponse;
if(httpResponse.getContent() != null) {
this.body = IOUtils.toString(httpResponse.getContent());
}else {
this.body = null;
}
}
代码示例来源:origin: aws/aws-sdk-java
public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
AmazonWebServiceResponse<String> awsResponse = parseResponseMetadata(response);
int bytesRead;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder();
InputStream content = response.getContent();
while ((bytesRead = content.read(buffer)) > 0) {
builder.append(new String(buffer, 0, bytesRead, StringUtils.UTF8));
}
awsResponse.setResult(builder.toString());
return awsResponse;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Static factory method to create a JsonContent object from the contents of the HttpResponse
* provided
*/
public static JsonContent createJsonContent(HttpResponse httpResponse,
JsonFactory jsonFactory) {
byte[] rawJsonContent = null;
try {
if (httpResponse.getContent() != null) {
rawJsonContent = IOUtils.toByteArray(httpResponse.getContent());
}
} catch (Exception e) {
LOG.debug("Unable to read HTTP response content", e);
}
return new JsonContent(rawJsonContent, new ObjectMapper(jsonFactory)
.configure(JsonParser.Feature.ALLOW_COMMENTS, true));
}
代码示例来源:origin: aws/aws-sdk-java
/**
* @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
*/
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response);
responseHeaders = response.getHeaders();
if (responseUnmarshaller != null) {
log.trace("Beginning to parse service response XML");
T result = responseUnmarshaller.unmarshall(response.getContent());
log.trace("Done parsing service response XML");
awsResponse.setResult(result);
}
return awsResponse;
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public RawResult unmarshall(JsonUnmarshallerContext in) throws IOException {
HttpResponse response = in.getHttpResponse();
RawResult result = new RawResult();
result.sdkResponseMetadata(new SdkResponseMetadata(SdkHttpMetadata.from(response)));
try {
resultContentConsumer.consume(result, response.getContent());
} finally {
response.getContent().close();
}
return result;
}
}
代码示例来源:origin: aws/aws-sdk-java
public PutMediaResult unmarshall(JsonUnmarshallerContext context) throws Exception {
PutMediaResult putMediaResult = new PutMediaResult();
putMediaResult.setPayload(context.getHttpResponse().getContent());
return putMediaResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetIntrospectionSchemaResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetIntrospectionSchemaResult getIntrospectionSchemaResult = new GetIntrospectionSchemaResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getIntrospectionSchemaResult.setSchema(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getIntrospectionSchemaResult;
}
代码示例来源:origin: aws/aws-sdk-java
public DeleteThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteThingShadowResult deleteThingShadowResult = new DeleteThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
deleteThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return deleteThingShadowResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetThingShadowResult getThingShadowResult = new GetThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getThingShadowResult;
}
代码示例来源:origin: aws/aws-sdk-java
public UpdateThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception {
UpdateThingShadowResult updateThingShadowResult = new UpdateThingShadowResult();
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
updateThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return updateThingShadowResult;
}
代码示例来源:origin: aws/aws-sdk-java
private AmazonServiceException createAse(HttpResponse errorResponse) throws Exception {
// Try to parse the error response as XML
final Document document = documentFromContent(errorResponse.getContent(), idString(errorResponse));
/*
* We need to select which exception unmarshaller is the correct one to
* use from all the possible exceptions this operation can throw.
* Currently we rely on the unmarshallers to return null if they can't
* unmarshall the response, but we might need something a little more
* sophisticated in the future.
*/
for (Unmarshaller<AmazonServiceException, Node> unmarshaller : unmarshallerList) {
AmazonServiceException ase = unmarshaller.unmarshall(document);
if (ase != null) {
ase.setStatusCode(errorResponse.getStatusCode());
return ase;
}
}
return null;
}
代码示例来源:origin: aws/aws-sdk-java
public GetMediaResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetMediaResult getMediaResult = new GetMediaResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getMediaResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
}
getMediaResult.setPayload(context.getHttpResponse().getContent());
return getMediaResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetMediaForFragmentListResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetMediaForFragmentListResult getMediaForFragmentListResult = new GetMediaForFragmentListResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getMediaForFragmentListResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
}
getMediaForFragmentListResult.setPayload(context.getHttpResponse().getContent());
return getMediaForFragmentListResult;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
*/
public AmazonWebServiceResponse<S3Object> handle(HttpResponse response) throws Exception {
/*
* TODO: It'd be nice to set the bucket name and key here, but the information isn't easy to
* pull out of the response/request currently.
*/
S3Object object = new S3Object();
AmazonWebServiceResponse<S3Object> awsResponse = parseResponseMetadata(response);
if (response.getHeaders().get(Headers.REDIRECT_LOCATION) != null) {
object.setRedirectLocation(response.getHeaders().get(Headers.REDIRECT_LOCATION));
}
// If the requester is charged when downloading a object from an
// Requester Pays bucket, then this header is set.
if (response.getHeaders().get(Headers.REQUESTER_CHARGED_HEADER) != null) {
object.setRequesterCharged(true);
}
if (response.getHeaders().get(Headers.S3_TAGGING_COUNT) != null) {
object.setTaggingCount(Integer.parseInt(response.getHeaders().get(Headers.S3_TAGGING_COUNT)));
}
ObjectMetadata metadata = object.getObjectMetadata();
populateObjectMetadata(response, metadata);
object.setObjectContent(new S3ObjectInputStream(response.getContent(), response.getHttpRequest()));
awsResponse.setResult(object);
return awsResponse;
}
代码示例来源:origin: aws/aws-sdk-java
public SynthesizeSpeechResult unmarshall(JsonUnmarshallerContext context) throws Exception {
SynthesizeSpeechResult synthesizeSpeechResult = new SynthesizeSpeechResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
synthesizeSpeechResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("x-amzn-RequestCharacters") != null) {
context.setCurrentHeader("x-amzn-RequestCharacters");
synthesizeSpeechResult.setRequestCharacters(context.getUnmarshaller(Integer.class).unmarshall(context));
}
}
synthesizeSpeechResult.setAudioStream(context.getHttpResponse().getContent());
return synthesizeSpeechResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetSdkResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetSdkResult getSdkResult = new GetSdkResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getSdkResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Disposition") != null) {
context.setCurrentHeader("Content-Disposition");
getSdkResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getSdkResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getSdkResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetExportResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetExportResult getExportResult = new GetExportResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getExportResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Disposition") != null) {
context.setCurrentHeader("Content-Disposition");
getExportResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
getExportResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return getExportResult;
}
代码示例来源:origin: aws/aws-sdk-java
public InvokeEndpointResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeEndpointResult invokeEndpointResult = new InvokeEndpointResult();
if (context.isStartOfDocument()) {
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
invokeEndpointResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("x-Amzn-Invoked-Production-Variant") != null) {
context.setCurrentHeader("x-Amzn-Invoked-Production-Variant");
invokeEndpointResult.setInvokedProductionVariant(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amzn-SageMaker-Custom-Attributes") != null) {
context.setCurrentHeader("X-Amzn-SageMaker-Custom-Attributes");
invokeEndpointResult.setCustomAttributes(context.getUnmarshaller(String.class).unmarshall(context));
}
}
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
invokeEndpointResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return invokeEndpointResult;
}
代码示例来源:origin: aws/aws-sdk-java
public InvokeResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeResult invokeResult = new InvokeResult();
if (context.isStartOfDocument()) {
if (context.getHeader("X-Amz-Function-Error") != null) {
context.setCurrentHeader("X-Amz-Function-Error");
invokeResult.setFunctionError(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Log-Result") != null) {
context.setCurrentHeader("X-Amz-Log-Result");
invokeResult.setLogResult(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Executed-Version") != null) {
context.setCurrentHeader("X-Amz-Executed-Version");
invokeResult.setExecutedVersion(context.getUnmarshaller(String.class).unmarshall(context));
}
}
invokeResult.setStatusCode(context.getHttpResponse().getStatusCode());
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
invokeResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return invokeResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetJobOutputResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetJobOutputResult getJobOutputResult = new GetJobOutputResult();
if (context.isStartOfDocument()) {
if (context.getHeader("x-amz-sha256-tree-hash") != null) {
context.setCurrentHeader("x-amz-sha256-tree-hash");
getJobOutputResult.setChecksum(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Range") != null) {
context.setCurrentHeader("Content-Range");
getJobOutputResult.setContentRange(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Accept-Ranges") != null) {
context.setCurrentHeader("Accept-Ranges");
getJobOutputResult.setAcceptRanges(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getJobOutputResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("x-amz-archive-description") != null) {
context.setCurrentHeader("x-amz-archive-description");
getJobOutputResult.setArchiveDescription(context.getUnmarshaller(String.class).unmarshall(context));
}
}
getJobOutputResult.setStatus(context.getHttpResponse().getStatusCode());
getJobOutputResult.setBody(context.getHttpResponse().getContent());
return getJobOutputResult;
}
内容来源于网络,如有侵权,请联系作者删除!