amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
585 stars 730 forks source link

The encrypted feed document contents were not uploaded to S3. #1706

Closed amao1310 closed 1 year ago

amao1310 commented 3 years ago

Calling the "createFeed" interface returns "Bad Request", and a message of "The encrypted feed document contents were not uploaded to S3." is found in debug.Below is my code `@Test public void createFeedDocumentTest() throws Exception { File fileinput = new File("D:\data\amazon\2021-07-27\productInfo_1627354726237.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fileinput); DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result1 = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result1); String asXML = writer.toString(); System.out.println(asXML); CreateFeedDocumentSpecification body = new CreateFeedDocumentSpecification(); body.setContentType("text/xml; charset=UTF-8"); AmazonAuthorConfigDTO dto = new AmazonAuthorConfigDTO(); dto.setAccessKeyId(AmazonUtils.USER_ACCESS_KEY_ID); dto.setSecretKey(AmazonUtils.USER_SECRET_ACCESS_KEY); dto.setRoleArn(AmazonUtils.ROLE_ARN); dto.setRoleSessionName(AmazonUtils.ROLE_SESSION_NAME); dto.setClientId(AmazonUtils.APP_CLIENT_ID); dto.setClientSecret(AmazonUtils.APP_CLIENT_SECRET); dto.setRefreshToken(REFRESH_TOKEN); dto.setRegion("us-east-1"); dto.setSpEndPoint("https://sellingpartnerapi-na.amazon.com"); dto.setLwaEndpoint("https://api.amazon.com/auth/o2/token"); FeedsApi feedsApi = AmazonUtils.amazonAuthorizationGrantFeed(dto); CreateFeedDocumentResponse response = feedsApi.createFeedDocument(body); CreateFeedDocumentResult result = response.getPayload(); String feedDocumentId = result.getFeedDocumentId(); String url = result.getUrl(); String key = result.getEncryptionDetails().getKey(); String initializationVector = result.getEncryptionDetails().getInitializationVector(); UploadExample.encryptAndUploadFromString(key,initializationVector,url,asXML); System.out.println(feedDocumentId);

    // TODO: test validations
}`

`public static void encryptAndUploadFromString(String key, String initializationVector, String url, String xml) {
    AESCryptoStreamFactory aesCryptoStreamFactory =
            new AESCryptoStreamFactory.Builder(key, initializationVector)
                    .build();

    // This contentType must be the same value that was provided to createFeedDocument.
    String contentType = String.format("text/xml; charset=%s", StandardCharsets.UTF_8);

    // The character set must be the same one that is specified in contentType.
    try (InputStream source = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
        UploadSpecification uploadSpec = new UploadSpecification.Builder(contentType, aesCryptoStreamFactory, source, url).build();
        uploadHelper.upload(uploadSpec);
    } catch (IOException | HttpResponseException | CryptoException e) {
        System.out.println(e);
    }
}`

`@Test
public void createFeedTest() throws ApiException {
    CreateFeedSpecification body = new CreateFeedSpecification();
    body.setFeedType("POST_PRODUCT_DATA");
    body.setFeedOptions(null);
    body.setMarketplaceIds(MARKETPLACE_ID);
    body.setInputFeedDocumentId("amzn1.tortuga.3.0f84b0f2-83cf-4a95-b548-d6d454501591.T1S0HRAPUNG22X");
    AmazonAuthorConfigDTO dto = new AmazonAuthorConfigDTO();
    dto.setAccessKeyId(AmazonUtils.USER_ACCESS_KEY_ID);
    dto.setSecretKey(AmazonUtils.USER_SECRET_ACCESS_KEY);
    dto.setRoleArn(AmazonUtils.ROLE_ARN);
    dto.setRoleSessionName(AmazonUtils.ROLE_SESSION_NAME);
    dto.setClientId(AmazonUtils.APP_CLIENT_ID);
    dto.setClientSecret(AmazonUtils.APP_CLIENT_SECRET);
    dto.setRefreshToken(REFRESH_TOKEN);
    dto.setRegion("us-east-1");
    dto.setSpEndPoint("https://sellingpartnerapi-na.amazon.com");
    dto.setLwaEndpoint("https://api.amazon.com/auth/o2/token");
    FeedsApi feedsApi = AmazonUtils.amazonAuthorizationGrantFeed(dto);
    CreateFeedResponse createFeedResponse = feedsApi.createFeed(body);
    System.out.println(createFeedResponse);

    // TODO: test validations
}`

Please help, thank you very much
amao1310 commented 3 years ago

It has been resolved, the exception of Illegal key size; this link can solve this exception: https://blog.csdn.net/dafeige8/article/details/76019911

johnkw commented 2 years ago

Also this should be closed because all of this pointless crypto complexity was removed in the newer /feeds/2021-06-30/ endpoint.

github-actions[bot] commented 1 year ago

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

github-actions[bot] commented 1 year ago

closed for inactivity