播放框架中WS调用的SSL问题

时间:2018-10-26 11:58:36

标签: java ssl playframework freshdesk play-ws

我遇到了从Play 2.6应用程序调用Freshdesk API的问题,我创建了一个库来使用Retrofit来执行此操作,另一个类使用Play WS来执行此操作,但是当我在Play内启动流程时,每个选项都失败了应用。

我测试了Retrofit客户端,并且创建/删除操作在我的集成测试中表现完美。

这是我的代码,可用于Play WS而不是Retrofit客户端。

public void create(String userEmail, String subject, String content) {

    // Obtain configuration using internal class and enumerations
    Config config = appService.getConfiguration(EConfig.FRESHDESK);

    JsonNode request = Json.newObject()
            .put("email", userEmail)
            .put("subject", subject)
            .put("description", content)
            .put("status", 2) // Fixed to "Open"
            .put("priority", 1); // Fixe to "Normal"

    CompletionStage<WSResponse> response = client.url(config.getString("url"))
        .setAuth(config.getString("token"), "X")
        .setContentType("application/json")
        .post(request);

    response.thenApply(wsResponse -> {

        System.out.println(wsResponse);

        return null;
    }).exceptionally(cause -> {

        logger.error("Error calling Freshdesk, this problem cannot be reported.", cause);

        return null;
    });

}

这是Play WS调用的堆栈跟踪:

java.util.concurrent.CompletionException: java.net.ConnectException: Received fatal alert: internal_error
  at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
  at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
  at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
  at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
  at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
  at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
  at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
  at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
  at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60)
  at scala.concurrent.impl.CallbackRunnable.run(Promise.scala)
Caused by: java.net.ConnectException: Received fatal alert: internal_error
  at play.shaded.ahc.org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:168)
  at play.shaded.ahc.org.asynchttpclient.netty.channel.NettyConnectListener$1.onFailure(NettyConnectListener.java:139)
  at play.shaded.ahc.org.asynchttpclient.netty.SimpleFutureListener.operationComplete(SimpleFutureListener.java:26)
  at play.shaded.ahc.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:507)
  at play.shaded.ahc.io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:500)
  at play.shaded.ahc.io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:479)
  at play.shaded.ahc.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:420)
  at play.shaded.ahc.io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:122)
  at play.shaded.ahc.io.netty.handler.ssl.SslHandler.notifyHandshakeFailure(SslHandler.java:1443)
  at play.shaded.ahc.io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1435)
Caused by: javax.net.ssl.SSLException: Received fatal alert: internal_error
  at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
  at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1666)
  at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1634)
  at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1800)
  at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1083)
  at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:907)
  at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781)
  at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
  at play.shaded.ahc.io.netty.handler.ssl.SslHandler$SslEngineType$3.unwrap(SslHandler.java:272)
  at play.shaded.ahc.io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1175)

1 个答案:

答案 0 :(得分:0)

最后,问题是我自己的错误,当我在配置中编写端点URL时,我犯了一个拼写错误。