private void populateAndEndSubsegment(Subsegment currentSubsegment, Request<?> request, Response<?> response) { if (null != response) { String requestId = null; if (response.getAwsResponse() instanceof AmazonWebServiceResult<?>) { // Not all services return responses extending AmazonWebServiceResult (e.g. S3) ResponseMetadata metadata = ((AmazonWebServiceResult<?>) response.getAwsResponse()).getSdkResponseMetadata(); if (null != metadata) { requestId = metadata.getRequestId(); if (null != requestId) { currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, requestId); } } } else if (null != response.getHttpResponse()) { // S3 does not follow request id header convention if (null != response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY)) { currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY)); } if (null != response.getHttpResponse().getHeader(S3_EXTENDED_REQUEST_ID_HEADER_KEY)) { currentSubsegment.putAws(EXTENDED_REQUEST_ID_SUBSEGMENT_KEY, response.getHttpResponse().getHeader(S3_EXTENDED_REQUEST_ID_HEADER_KEY)); } } currentSubsegment.putAllAws(extractResponseParameters(request, response.getAwsResponse())); currentSubsegment.putAllHttp(extractHttpResponseInformation(response.getHttpResponse())); } finalizeSubsegment(request); }
/** * TODO: メソッドコメント * * @param client * @return */ public AmazonEC2 wrap(final AmazonEC2 client) { InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (!AmazonWebServiceResult.class.isAssignableFrom(method.getReturnType())) { return method.invoke(client, args); } return doInvoke(client, proxy, method, args); } }; return (AmazonEC2) Proxy.newProxyInstance(LoggingAwsClientWrapper.class.getClassLoader(), new Class[] { AmazonEC2.class }, handler); }
/** * TODO: メソッドコメント * * @param client * @return */ public AmazonElasticLoadBalancing wrap(final AmazonElasticLoadBalancing client) { InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (!AmazonWebServiceResult.class.isAssignableFrom(method.getReturnType())) { return method.invoke(client, args); } return doInvoke(client, proxy, method, args); } }; return (AmazonElasticLoadBalancing) Proxy.newProxyInstance(LoggingAwsClientWrapper.class.getClassLoader(), new Class[] { AmazonElasticLoadBalancing.class }, handler); }
@SuppressWarnings("unchecked") private <T> T fillInResponseMetadata(AmazonWebServiceResponse<T> awsResponse, HttpResponse httpResponse) { final T result = awsResponse.getResult(); if (result instanceof AmazonWebServiceResult<?>) { ((AmazonWebServiceResult) result) .setSdkResponseMetadata(awsResponse.getResponseMetadata()) .setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse)); } return result; }
private boolean isResponseSuccessful(AmazonWebServiceResult<?> response) { return response.getSdkHttpMetadata().getHttpStatusCode() == HttpStatus.SC_OK; }