Amazon AWS Java - 列表订单抛出异常

时间:2015-03-19 04:58:18

标签: java amazon amazon-mws

我试图从亚马逊MWS获得订单,而我只是简单地在客户端库样本中复制ListOrdersSample.java。下面是代码,以及它抛出的StringIndexOutOfBounds异常。我不确定为什么会这样。亚马逊的文档非常稀少,在线搜索产生的结果非常少。

有人可以帮忙吗?提前谢谢!

public class GetOrderList 
{
    private static final String mAccessKeyID = "accessKeyID";
    private static final String mSecretAccessKey = "secretAccessKey";
    private static final String mMerchantID = "merchantID";
    private static final String mMarketplaceID = "marketplaceID";

     /**
     * Call the service, log response and exceptions.
     */
    public static ListOrdersResponse invokeListOrders(
            MarketplaceWebServiceOrders client, 
            ListOrdersRequest request) 
    {
        try 
        {
            // Call the service.
            // Line 44
            ListOrdersResponse response = client.listOrders(request);
            ResponseHeaderMetadata rhmd = response.getResponseHeaderMetadata();

            // We recommend logging every the request id and timestamp of every call.
            System.out.println("Response:");
            System.out.println("RequestId: "+rhmd.getRequestId());
            System.out.println("Timestamp: "+rhmd.getTimestamp());
            String responseXml = response.toXML();
            System.out.println(responseXml);
            return response;
        } 
        catch (MarketplaceWebServiceOrdersException ex) 
        {
            // Exception properties are important for diagnostics.
            System.out.println("Service Exception:");
            ResponseHeaderMetadata rhmd = ex.getResponseHeaderMetadata();

            if(rhmd != null) 
            {
                System.out.println("RequestId: "+rhmd.getRequestId());
                System.out.println("Timestamp: "+rhmd.getTimestamp());
            }

            System.out.println("Message: "+ex.getMessage());
            System.out.println("StatusCode: "+ex.getStatusCode());
            System.out.println("ErrorCode: "+ex.getErrorCode());
            System.out.println("ErrorType: "+ex.getErrorType());
            throw ex;
        }
    }

    /**
     *  Command line entry point.
     */
    public static void main(String[] args) 
    {
        // Get a client connection.
        // Make sure you've set the variables in MarketplaceWebServiceOrdersSampleConfig.
        MarketplaceWebServiceOrdersClient client = MarketplaceWebServiceOrdersSampleConfig.getClient();

        // Create a request.
        ListOrdersRequest request = new ListOrdersRequest();

        request.setSellerId(mMerchantID);

        // Not sure if this is correct
        request.setMWSAuthToken(mAccessKeyID);

        XMLGregorianCalendar createdAfter = MwsUtl.getDTF().newXMLGregorianCalendar();
        request.setCreatedAfter(createdAfter);

        XMLGregorianCalendar createdBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
        request.setCreatedBefore(createdBefore);

        XMLGregorianCalendar lastUpdatedAfter = MwsUtl.getDTF().newXMLGregorianCalendar();
        request.setLastUpdatedAfter(lastUpdatedAfter);

        XMLGregorianCalendar lastUpdatedBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
        request.setLastUpdatedBefore(lastUpdatedBefore);

        List<String> orderStatus = new ArrayList<String>();
        request.setOrderStatus(orderStatus);

        List<String> marketplaceId = new ArrayList<String>();
        request.setMarketplaceId(marketplaceId);

        List<String> fulfillmentChannel = new ArrayList<String>();
        request.setFulfillmentChannel(fulfillmentChannel);

        List<String> paymentMethod = new ArrayList<String>();
        request.setPaymentMethod(paymentMethod);

        String buyerEmail = "example";
        request.setBuyerEmail(buyerEmail);

        String sellerOrderId = "example";
        request.setSellerOrderId(sellerOrderId);

        Integer maxResultsPerPage = 100;
        request.setMaxResultsPerPage(maxResultsPerPage);

        List<String> tfmShipmentStatus = new ArrayList<String>();
        request.setTFMShipmentStatus(tfmShipmentStatus);

        // Make the call.
        // Line 129
        invokeListOrders(client, request);
    }
}


Service Exception:
Message: null
StatusCode: 0
ErrorCode: null
Exception in thread "main" com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersException
ErrorType: null
at com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersClient$RequestType.wrapException(MarketplaceWebServiceOrdersClient.java:143)
at com.amazonservices.mws.client.MwsConnection.call(MwsConnection.java:429)
at com.amazonservices.mws.orders._2013_09_01.MarketplaceWebServiceOrdersClient.listOrders(MarketplaceWebServiceOrdersClient.java:87)
at test.GetOrderList.invokeListOrders(GetOrderList.java:44)
at test.GetOrderList.main(GetOrderList.java:129)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1955)
at com.amazonservices.mws.client.MwsConnection$ServiceEndpoint.<init>(MwsConnection.java:102)
at com.amazonservices.mws.client.MwsConnection.getServiceEndpoint(MwsConnection.java:398)
at com.amazonservices.mws.client.MwsConnection.newCall(MwsConnection.java:687)
at com.amazonservices.mws.client.MwsConnection.call(MwsConnection.java:420)
... 3 more

2 个答案:

答案 0 :(得分:0)

您是否在Java MWS库的Quick Start列表中排名第3?似乎未配置服务端点。

答案 1 :(得分:0)

我收到此异常是因为我的ServiceURL设置不正确。

要解决此问题,我将ServiceURL设置为https://https://mws.amazonservices.com