REST Web服务调用在Java 1.7中不起作用

时间:2016-11-08 14:27:13

标签: web-services rest playframework jdk1.7

我正在尝试在Java中使用RESTful API,它在Java 1.6和Java 1.8中工作,但在Java 1.7中不起作用。

我的代码:

import play.libs.F.Promise;
import play.libs.WS;
import play.libs.WS.Response;
import play.libs.WS.WSRequestHolder;

public class Test {

    public static void main(String[] args) {
        final String ADD_CART_URL ="https://stagconnect.acehubpaymentservices.com/gateway/v3/payments/";
        String postString = "{\"action\":\"payment\", \"header\":{\"businessId\":\"4578895\"}, \"body\":{\"transaction\":{\"trackingCode\":\"9090-90-9876\", \"type\":\"SINGLE\", \"brandId\":\"1010\", \"amount\":\"5.00\", \"currencyCode\":\"EUR\",\"countryCode\":\"NL\"}, \"card\":{\"holderName\":\"John Smith\", \"number\":\"4907639999990022\", \"expiryMonth\":\"12\", \"expiryYear\":\"2017\", \"cvv\":\"029\"}}}";
        String certificatesTrustStorePath = "/usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts";
        System.setProperty("javax.net.ssl.trustStore", certificatesTrustStorePath);

        System.out.println("ws call start");
        Promise<Response>  promise = WS.url(ADD_CART_URL)
                .setHeader("Content-Type", "application/json")
                .setHeader("Authorization", "Basic S2FjaHluZwedYzpEQEk1secvdfVQ=")
                .post(postString);
        String responseText = promise.get(20000L).getBody();
        System.out.println(responseText);
        System.out.println("WS Call End \n");   
    }
}

Java 1.7出错:

 ws call start
 Exception in thread "main" java.util.concurrent.TimeoutException:    Futures timed out after [20000 milliseconds]
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96)
    at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58)
    at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
    at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
    at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
    at scala.concurrent.Await$.ready(package.scala:86)
    at play.api.libs.concurrent.PlayPromise.await(Promise.scala:134)
    at play.libs.F$Promise.get(F.java:213)
    at play.libs.F$Promise.get(F.java:224)
    at com.kachyng.processor.AcaptureTest.main(AcaptureTest.java:24)

0 个答案:

没有答案