SubmitFeed Sample Java is not working


#1

Hello, I’m new to MWS. I’m trying to build submitfeed API and I’m using sample java code to test it but in MarketplaceWebserviceClient.java ---- from line — method.setEntity( new InputStreamEntity(sfr.getFeedContent() , -1) ); — it is throwing exception. Please need some quick help on this. Please let me know what causing this issue.
Output getting -
Caught Exception: null
Response Status Code: -1
Error Code: null
Error Type: null
Request ID: null
XML: nullResponseHeaderMetadata: null


#2

Since you didn’t provide more information the only help I can give is that there is something missing on your SubmitFeedRequest object. From the exception it looks like its the feedContent property is null.


#3

Thanks for the quick reply. Yes, I’m not sending feedContent value. I’m pasting the java code where I used my sample values to get a result. As per your comment I tried to uncomment feedContent type it is not finding FileInputStream class. Please suggest further.

Code:
/*******************************************************************************

  • Copyright 2009 Amazon Services.
  • Licensed under the Apache License, Version 2.0 (the “License”);
  • You may not use this file except in compliance with the License.
  • You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
  • This file is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
  • CONDITIONS OF ANY KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations under the License.

  • Marketplace Web Service Java Library
  • API Version: 2009-01-01
  • Generated: Wed Feb 18 13:28:48 PST 2009

*/

package com.amazonaws.mws.samples;

import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.ArrayList;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import com.amazonaws.mws.;
import com.amazonaws.mws.model.
;
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;

/**
*

  • Submit Feed Samples

*/
public class SubmitFeedSample {

/**
 * Just add a few required parameters, and try the service Submit Feed
 * functionality
 * 
 * @param args
 *            unused
 */
/**
 * @param args
 */
public static void main(String... args) {

    /************************************************************************
     * Access Key ID and Secret Access Key ID, obtained from:
     * http://aws.amazon.com
     ***********************************************************************/
    final String accessKeyId = "0PB842ExampleN4ZTR2";
    final String secretAccessKey = "kWcrlEXAMPLEM/LtmEENI/aVmYvHNif5zB+d9+ct";

    final String appName = "IR";
    final String appVersion = "12c";

    MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

    /************************************************************************
     * Uncomment to set the appropriate MWS endpoint.
     ************************************************************************/
    // US
     config.setServiceURL("https://mws.amazonservices.com/");
    // UK
    // config.setServiceURL("https://mws.amazonservices.co.uk/");
    // Germany
    // config.setServiceURL("https://mws.amazonservices.de/");
    // France
    // config.setServiceURL("https://mws.amazonservices.fr/");
    // Italy
    // config.setServiceURL("https://mws.amazonservices.it/");
    // Japan
    // config.setServiceURL("https://mws.amazonservices.jp/");
    // China
    // config.setServiceURL("https://mws.amazonservices.com.cn/");
    // Canada
    // config.setServiceURL("https://mws.amazonservices.ca/");
    // India
    // config.setServiceURL("https://mws.amazonservices.in/");

    /************************************************************************
     * You can also try advanced configuration options. Available options are:
     *
     *  - Signature Version
     *  - Proxy Host and Proxy Port
     *  - User Agent String to be sent to Marketplace Web Service
     *
     ***********************************************************************/

    /************************************************************************
     * Instantiate Http Client Implementation of Marketplace Web Service        
     ***********************************************************************/

    MarketplaceWebService service = new MarketplaceWebServiceClient(
            accessKeyId, secretAccessKey, appName, appVersion, config);


    /************************************************************************
     * Setup request parameters and uncomment invoke to try out sample for
     * Submit Feed
     ***********************************************************************/

    /************************************************************************
     * Marketplace and Merchant IDs are required parameters for all
     * Marketplace Web Service calls.
     ***********************************************************************/
    final String merchantId = "A1XExample5E6";
    final String sellerDevAuthToken = "amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE";
    // marketplaces to which this feed will be submitted; look at the
    // API reference document on the MWS website to see which marketplaces are
    // included if you do not specify the list yourself
    final IdList marketplaces = new IdList(Arrays.asList(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    		"Marketplae1",
    		"Marketplace2"));

    SubmitFeedRequest request = new SubmitFeedRequest();
    request.setMerchant(merchantId);
    request.setMWSAuthToken(sellerDevAuthToken);
    request.setMarketplaceIdList(marketplaces);

    request.setFeedType("_POST_ORDER_FULFILLMENT_DATA_");

    // MWS exclusively offers a streaming interface for uploading your
    // feeds. This is because
    // feed sizes can grow to the 1GB+ range - and as your business grows
    // you could otherwise
    // silently reach the feed size where your in-memory solution will no
    // longer work, leaving you
    // puzzled as to why a solution that worked for a long time suddenly
    // stopped working though
    // you made no changes. For the same reason, we strongly encourage you
    // to generate your feeds to
    // local disk then upload them directly from disk to MWS via Java -
    // without buffering them in Java
    // memory in their entirety.
    // Note: MarketplaceWebServiceClient will not retry a submit feed request
    // because there is no way to reset the InputStream from our client. 
    // To enable retry, recreate the InputStream and resubmit the feed
    // with the new InputStream. 
    //
    // request.setFeedContent( new FileInputStream("my-feed.xml" /*or
    // "my-flat-file.txt" if you use flat files*/);

    invokeSubmitFeed(service, request);

}

/**
 * Submit Feed request sample Uploads a file for processing together with
 * the necessary metadata to process the file, such as which type of feed it
 * is. PurgeAndReplace if true means that your existing e.g. inventory is
 * wiped out and replace with the contents of this feed - use with caution
 * (the default is false).
 * 
 * @param service
 *            instance of MarketplaceWebService service
 * @param request
 *            Action to invoke
 */
public static void invokeSubmitFeed(MarketplaceWebService service,
        SubmitFeedRequest request) {
    System.out.println("Hello");
    try {
        System.out.println("request: "+request);
        SubmitFeedResponse response = service.submitFeed(request);

        System.out.println("SubmitFeed Action Response");
        System.out
        .println("=============================================================================");
        System.out.println();

        System.out.print("    SubmitFeedResponse");
        System.out.println();
        if (response.isSetSubmitFeedResult()) {
            System.out.print("        SubmitFeedResult");
            System.out.println();
            SubmitFeedResult submitFeedResult = response
            .getSubmitFeedResult();
            if (submitFeedResult.isSetFeedSubmissionInfo()) {
                System.out.print("            FeedSubmissionInfo");
                System.out.println();
                FeedSubmissionInfo feedSubmissionInfo = submitFeedResult
                .getFeedSubmissionInfo();
                if (feedSubmissionInfo.isSetFeedSubmissionId()) {
                    System.out.print("                FeedSubmissionId");
                    System.out.println();
                    System.out.print("                    "
                            + feedSubmissionInfo.getFeedSubmissionId());
                    System.out.println();
                }
                if (feedSubmissionInfo.isSetFeedType()) {
                    System.out.print("                FeedType");
                    System.out.println();
                    System.out.print("                    "
                            + feedSubmissionInfo.getFeedType());
                    System.out.println();
                }
                if (feedSubmissionInfo.isSetSubmittedDate()) {
                    System.out.print("                SubmittedDate");
                    System.out.println();
                    System.out.print("                    "
                            + feedSubmissionInfo.getSubmittedDate());
                    System.out.println();
                }
                if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
                    System.out
                    .print("                FeedProcessingStatus");
                    System.out.println();
                    System.out.print("                    "
                            + feedSubmissionInfo.getFeedProcessingStatus());
                    System.out.println();
                }
                if (feedSubmissionInfo.isSetStartedProcessingDate()) {
                    System.out
                    .print("                StartedProcessingDate");
                    System.out.println();
                    System.out
                    .print("                    "
                            + feedSubmissionInfo
                            .getStartedProcessingDate());
                    System.out.println();
                }
                if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
                    System.out
                    .print("                CompletedProcessingDate");
                    System.out.println();
                    System.out.print("                    "
                            + feedSubmissionInfo
                            .getCompletedProcessingDate());
                    System.out.println();
                }
            }
        }
        if (response.isSetResponseMetadata()) {
            System.out.print("        ResponseMetadata");
            System.out.println();
            ResponseMetadata responseMetadata = response
            .getResponseMetadata();
            if (responseMetadata.isSetRequestId()) {
                System.out.print("            RequestId");
                System.out.println();
                System.out.print("                "
                        + responseMetadata.getRequestId());
                System.out.println();
            }
        }
        System.out.println(response.getResponseHeaderMetadata());
        System.out.println();
        System.out.println();

    } catch (MarketplaceWebServiceException ex) {

        System.out.println("Caught Exception: " + ex.getMessage());
        System.out.println("Response Status Code: " + ex.getStatusCode());
        System.out.println("Error Code: " + ex.getErrorCode());
        System.out.println("Error Type: " + ex.getErrorType());
        System.out.println("Request ID: " + ex.getRequestId());
        System.out.print("XML: " + ex.getXML());
        System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
    }
}

}
Output:
“C:\Program Files\Java\jdk1.8.0_144\bin\javaw.exe” -server -classpath C:\JDeveloper\mywork_12.2.1.3\AmazonSeller.adf;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\AMZSFeedsClientLibraryService\classes;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\commons-codec-1.3\commons-codec-1.3.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\commons-httpclient-3.0.1\commons-httpclient-3.0.1.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\commons-logging-1.1\commons-logging-1.1.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\httpclient-4.2\httpclient-4.2.6.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\httpcore-4.2\httpcore-4.2.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\jaxb-ri-2.1\activation.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\jaxb-ri-2.1\jaxb-api.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\jaxb-ri-2.1\jaxb-impl.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\jaxb-ri-2.1\jaxb-xjc.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\jaxb-ri-2.1\jsr173_1.0_api.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\third-party\log4j-1.2.14\log4j-1.2.14.jar;C:\JDeveloper\mywork_12.2.1.3\AmazonSeller\dist\MaWSJavaClientLibrary-1.1.jar -Djavax.net.ssl.trustStore=C:\Users*****\AppData\Local\Temp\trustStore1067076711832250244.jks com.amazonaws.mws.samples.SubmitFeedSample
Hello
request: com.amazonaws.mws.model.SubmitFeedRequest@358ee631
Hello1
Hello2
Caught Exception: null
Response Status Code: -1
Error Code: null
Error Type: null
Request ID: null
XML: nullResponseHeaderMetadata: null
Picked up _JAVA_OPTIONS: -Xmx1024m
Process exited with exit code 0.


#4

Additionally, in feedContent type it is basically sending the feed xml file but in my case I’m not going to send the feed xml file like that. Please provide some more information.


#5

This call will fail unless you provide a file. Which feed are you trying to use?


#6

I’m using POST_ORDER_FULFILLMENT_DATA. Using this code to get ContentMD5Value and Signature mainly. Is this just a filename or it will look for that file also. Please assist further.


#7

Not sure why you need those things. However you need to provide a file or else it will fail trying to attempt to make the call. You can get those via scratchpad. Scratchpad hits production data so be very careful with what you are testing.

https://mws.amazonservices.com/scratchpad/index.html


#8

Ok, I think I should ask the 1st question 1st and then it will make more sense. As I mentioned I’m totally new to MWS and trying to send shipment order information to amazon using their API. So, on documentation I found, I to have build a REST API like below - So what I found is ContentMD5Value and Signature, these two I have to calculate and pass and rest of the values I think I will get from developer access. Please let me know whether the understanding is correct or not. If you can give me a sample API to see how that looks will be great as well. I need to form that API correctly and then I will use Oracle SOA Suite to call the API.

POST /Feeds/2009-01-01 HTTP/1.1
Content-Type: x-www-form-urlencoded
Host: mws.amazonservices.com
User-Agent:

?AWSAccessKeyId=0PB842ExampleN4ZTR2
&Action=SubmitFeed
&FeedType=POST_ORDER_FULFILLMENT_DATA
&MWSAuthToken=amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE
&MarketplaceIdList.Id.1=ATVExampleDER
&SellerId=A1XExample5E6
&ContentMD5Value=ExampleMd5HashOfHttpBodyAsPerRfc2616Example
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2009-01-26T23%3A51%3A31.315Z
&Version=2009-01-01
&Signature=SvSExamplefZpSignaturex2cs%3D


#9

Why not just leverage that Java client library to do this work for you?


#10

Yes, that’s why I started going through that submitfeedsample.java to create the API for me and there I got stuck with that error. So, from your comment I feel like I’m looking at the correct place and now I’ve to put that filename to get the API generated. Another challenge is I’m yet to get the developer access, so not sure what would be final output of that java class once I provide my credentials details. So, that java class will give me the correct API formed which I need to use, right?


#11

Are you creating your own API or are you trying to access Amazon’s API (MWS)?


#12

Amazon’s API (MWS)


#13

The client library includes mock objects. They aren’t all complete however the API documentation itself has a sample of the response. Since you don’t have credentials you won’t be able to make the call even if you add the xml. However you could create a test call that instead of reaching Amazon it just replies with the sample XML. If done properly you could have a working mock environment so that you can get things ready until you receive the credentials.

This is from the http://docs.developer.amazonservices.com/en_US/feeds/Feeds_SubmitFeed.html

Successful submitted response:

<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
	<SubmitFeedResult>
		<FeedSubmissionInfo>
			<FeedSubmissionId>2291326430</FeedSubmissionId>
			<FeedType>_POST_PRODUCT_DATA_</FeedType>
			<SubmittedDate>2009-02-20T02:10:35+00:00</SubmittedDate>
			<FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus>
		</FeedSubmissionInfo>
	</SubmitFeedResult>
	<ResponseMetadata>
		<RequestId>75424a38-f333-4105-98f0-2aa9592d665c</RequestId>
	</ResponseMetadata>
</SubmitFeedResponse>

#14

Sure, I will look into those mock objects. So, can you please confirm whether this sample codes actually submit the feed? I basically want to use these sample codes just to generate correct Amazon MWS APIs and then will call it from Oracle SOA suite. Can I use that code just to get the API and not to actually submit from inside the java code?


#15

Well its not that simple. Since you are trying to reverse engineer this and not use the Java client. The main issue I’ve seen people run into when doing this is that the request has to be signed. Good place to try and test this is using scratchpad which I posted on an earlier reply. But without dev credentials you can’t do anything.


#16

Yes, let me get that 1st and if I have anymore roadblocks after that, I will post accordingly. Thanks for your help and suggestions so far.


#17

Hello, finally I got the credentials and used scratchpad to generate the signature and contentMD5value. What I see is contentMD5value is same each time but signature is getting changed. Can you please confirm whether I can use same signature for all the APIs or that needs to be generated each time? Please confirm on this.


#18

The signature needs to be generated for each call as it is the encoded value of the API call which includes the API name, action, time stamp, access key, etc. Even for the same API and action, the signature will change as the time stamp will change.


#19

Thanks for the update. Do you have any java code suggestion to generate the signature? I will use MD5value from scratchpad but do you think I should generate that as well and what is timestamp format it they are using?


#20

Look at the request details in scratchpad. It has the exact timestamp format.