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

xpszyzbs  于 2023-02-28  发布在  Java
关注(0)|答案(2)|浏览(107)

我试图从Amazon MWS获得订单,我从简单地复制客户端库示例中的ListOrdersSample.java开始。下面是代码和它抛出的StringIndexOutOfBounds异常。我不知道为什么会发生这种情况。Amazon的文档非常少,在线搜索产生的结果很少。
有谁能帮忙吗?先谢谢你!

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
djp7away

djp7away1#

我收到这个异常是因为我的ServiceURL设置不正确。
为了修复,我将ServiceURL设置为https://mws.amazonservices.com

e5nqia27

e5nqia272#

您是否为Java MWS库执行了Quick Start列表中的第3项操作?服务端点似乎尚未配置。

相关问题