Signature of petition with file in the body
Describe the bug
I have the problem when I try to upload a .json file to my elastic search index.
The file I am uploading I have it as a .json binary. at the moment of making the tests by an external api call application it makes me the signature and uploads the file, the problem is in my code that I don't know where to advance.
Expected Behavior
I was expecting it to upload my file to the index and return an OK message.
Current Behavior
- {"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}
com.amazonaws.SdkClientException: Unable to read request payload to sign request. at com.amazonaws.auth.AbstractAWSSigner.getBinaryRequestPayloadStreamWithoutQueryParams(AbstractAWSSigner.java:359) at com.amazonaws.auth.AbstractAWSSigner.getBinaryRequestPayloadStream(AbstractAWSSigner.java:350) at com.amazonaws.auth.AWS4Signer.calculateContentHash(AWS4Signer.java:567) at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:241)
Reproduction Steps
URIBuilder uriBuilder = new URIBuilder(this.url);
DefaultRequest<?> requestVoid = new DefaultRequest<>(service);
requestVoid.setEndpoint(URI.create(new HttpHost(uriBuilder.getHost()).toURI()));
requestVoid.setResourcePath(uriBuilder.build().getRawPath());
requestVoid.setHttpMethod(HttpMethodName.POST);
requestVoid.addHeader("Content-Type", "application/json");
requestVoid.setContent(new ByteArrayInputStream(FileUtils.readFileToByteArray(file)));
AWS4Signer signer = new AWS4Signer();
signer.setServiceName(service);
signer.setRegionName(region);
signer.sign(requestVoid, new BasicAWSCredentials(ES_ACCESSKEY_ID,ES_SECRET_KEY));
AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
return amazonHttpClient
.requestExecutionBuilder()
.executionContext(new ExecutionContext(true))
.request(requestVoid)
.execute(new StringResponseHandler())
.getAwsResponse().getResult();
public class StringResponseHandler implements HttpResponseHandler<AmazonWebServiceResponse<String>> {
private static final Logger LOG = Logger.getLogger(StringResponseHandler.class.getName());
@Override
public AmazonWebServiceResponse<String> handle(com.amazonaws.http.HttpResponse response) throws IOException {
try {
LOG.info(response.toString());
AmazonWebServiceResponse<String> awsResponse = new AmazonWebServiceResponse<>();
//putting response string in the result, available outside the handler
awsResponse.setResult(IOUtils.toString(response.getContent()));
return awsResponse;
}catch(Exception e) {
LOG.log(Level.SEVERE,"Error con el StringResponseHandler ",e);
AmazonWebServiceResponse<String> awsResponse = new AmazonWebServiceResponse<>();
return awsResponse;
}
}
@Override
public boolean needsConnectionLeftOpen() {
return false;
}
}
Possible Solution
No response
Additional Information/Context
I have tried to try with external libraries but I get the error in the signature
AWS Java SDK version used
1.8.0_333
JDK version used
1.12.298
Operating System and version
Windows 10
Hello @carmanlcr ,
Thank you very much for your submission. Could you please provide the verbose wire logs associated with this issue?
Please make sure to remove any sensitive information. Sincerely,
Yasmine
It looks like this issue has not been active for more than five days. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it.