我从HTTP服务获得WSResponse(表单Play框架)响应
{"的authToken":" d4b4bf6d5ff3f35366a75b498c8dbb58"}
我试图将其视为JSON并使用
在控制台上打印 System.out.println(response.asJson());
我正确地在控制台上打印了响应,然而,代码在函数asJson()中断,并带有以下跟踪:
play.api.http.HttpErrorHandlerExceptions $$ anon $ 1:执行 例外[RuntimeException的: com.fasterxml.jackson.databind.JsonMappingException:没有要映射的内容 由于输入结束[来源: org.jboss.netty.buffer.ChannelBufferInputStream@23408f7c;行:1, 专栏:1]]] at play.api.http.HttpErrorHandlerExceptions $ .throwableToUsefulException(HttpErrorHandler.scala:265) 〜[play_2.10-2.4.2.jar:2.4.2] at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) 〜[play_2.10-2.4.2.jar:2.4.2] at play.api.GlobalSettings $ class.onError(GlobalSettings.scala:179) [play_2.10-2.4.2.jar:2.4.2] at play.api.DefaultGlobal $ .onError(GlobalSettings.scala:212) [play_2.10-2.4.2.jar:2.4.2] at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [play_2.10-2.4.2.jar:2.4.2] at play.filters.cors.AbstractCORSPolicy $$ anonfun $ 1.applyOrElse(AbstractCORSPolicy.scala:151) [filters-helpers_2.10-2.4.2.jar:2.4.2] at play.filters.cors.AbstractCORSPolicy $$ anonfun $ 1.applyOrElse(AbstractCORSPolicy.scala:150) [filters-helpers_2.10-2.4.2.jar:2.4.2] at scala.concurrent.Future $$ anonfun $ recoverWith $ 1.适用(Future.scala:344) [scala-library-2.10.5.jar:na] at scala.concurrent.Future $$ anonfun $ recoverWith $ 1.适用(Future.scala:343) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na] at play.api.libs.iteratee.Execution $蹦床$ .execute(Execution.scala:70) [play-iteratees_2.10-2.4.2.jar:2.4.2] at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.Promise $ DefaultPromise.tryComplete(Promise.scala:248) [scala-library-2.10.5.jar:na] at scala.concurrent.Promise $ class.tryFailure(Promise.scala:112) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.Promise $ DefaultPromise.tryFailure(Promise.scala:153) [scala-library-2.10.5.jar:na] at play.api.mvc.Filter $$不久$ 1 $$ anonfun $所适用$ 4 $$ anonfun $ $申请1.applyOrElse(Filters.scala:67) [play_2.10-2.4.2.jar:2.4.2] at play.api.mvc.Filter $$匿名$ $$ 1 $ anonfun $所适用4 $$ anonfun $ $申请1.applyOrElse(Filters.scala:61) [play_2.10-2.4.2.jar:2.4.2] at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.5.jar:na] at play.api.libs.iteratee.Iteratee $$ anonfun $ recoverM $ 1.applyOrElse(Iteratee.scala:629) [play-iteratees_2.10-2.4.2.jar:2.4.2] at play.api.libs.iteratee.Iteratee $$ anonfun $ recoverM $ 1.applyOrElse(Iteratee.scala:629) [play-iteratees_2.10-2.4.2.jar:2.4.2] at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.5.jar:na] at scala.util.Failure $$ anonfun $恢复$ 1.适用(Try.scala:185) [scala-library-2.10.5.jar:na]在scala.util.Try $ .apply(Try.scala:161) [scala-library-2.10.5.jar:na] at scala.util.Failure.recover(Try.scala:185) [scala-library-2.10.5.jar:na] at scala.concurrent.Future $$ anonfun $恢复$ 1.适用(Future.scala:324) [scala-library-2.10.5.jar:na] at scala.concurrent.Future $$ anonfun $恢复$ 1.适用(Future.scala:324) [scala-library-2.10.5.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na] at akka.dispatch.BatchingExecutor $ AbstractBatch.processBatch(BatchingExecutor.scala:55) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用$ MCV $ SP(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.BatchingExecutor $ BlockableBatch $$ anonfun $运行$ 1.适用(BatchingExecutor.scala:91) [akka-actor_2.10-2.3.11.jar:na] at scala.concurrent.BlockContext $ .withBlockContext(BlockContext.scala:72) [scala-library-2.10.5.jar:na] at akka.dispatch.BatchingExecutor $ BlockableBatch.run(BatchingExecutor.scala:90) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [akka-actor_2.10-2.3.11.jar:na] at akka.dispatch.ForkJoinExecutorConfigurator $ AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [akka-actor_2.10-2.3.11.jar:na] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinPool $ WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.5.jar:na] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.5.jar:na]引起:java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException:没有要映射的内容 由于输入结束[来源: org.jboss.netty.buffer.ChannelBufferInputStream@23408f7c;行:1, 专栏:1] at play.libs.Json.parse(Json.java:149) 〜[play-json_2.10-2.4.2.jar:2.4.2] at play.libs.ws.ning.NingWSResponse.asJson(NingWSResponse.java:149) 〜[play-java-ws_2.10-2.4.2.jar:2.4.2] at service.GlaasService.lambda $ getAuthToken $ 0(GlaasService.java:28) 〜[classes /:na] at service.GlaasService $$ Lambda $ 74 / 930311498.apply(未知来源) 〜[na:na] at play.core.j.FPromiseHelper $$ anonfun $表$ 1.适用(FPromiseHelper.scala:103) 〜[play_2.10-2.4.2.jar:2.4.2] at scala.util.Success $$ anonfun $表$ 1.适用(Try.scala:206) 〜[scala-library-2.10.5.jar:na] at scala.util.Try $ .apply(Try.scala:161)[scala-library-2.10.5.jar:na] at scala.util.Success.map(Try.scala:206)〜[scala-library-2.10.5.jar:na] 在scala.concurrent.Future $$ anonfun $ map $ 1.apply(Future.scala:235) 〜[scala-library-2.10.5.jar:na] at scala.concurrent.Future $$ anonfun $表$ 1.适用(Future.scala:235) 〜[scala-library-2.10.5.jar:na] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.5.jar:na] at play.core.j.HttpExecutionContext $$匿名$ 2.run(HttpExecutionContext.scala:40) 〜[play_2.10-2.4.2.jar:2.4.2] ...省略了6个常见帧引起的: com.fasterxml.jackson.databind.JsonMappingException:没有要映射的内容 由于输入结束[来源: org.jboss.netty.buffer.ChannelBufferInputStream@23408f7c;行:1, 专栏:1] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) 〜[jackson-databind-2.5.4.jar:2.5.4] at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3609) 〜[jackson-databind-2.5.4.jar:2.5.4] at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3549) 〜[jackson-databind-2.5.4.jar:2.5.4] at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2078) 〜[jackson-databind-2.5.4.jar:2.5.4] at play.libs.Json.parse(Json.java:147)〜[play-json_2.10-2.4.2.jar:2.4.2] ...省略了17个常见帧
错误的原因看起来像json的输入不合适,但我验证了JSON响应,如果工作正常,并且控制台语句也正确打印它,但它打印后打破它。如果我尝试在没有打印的情况下将响应作为JSON处理,它仍会以相同的异常中断。
添加方法代码如下:
public static Promise<Result> getAuthToken(String serviceProfileId, String username, String password, WSClient ws){
return ws.url("http://SERVER_URL/auth")
.setContentType("application/x-www-form-urlencoded")
.post("serviceID="+serviceProfileId+"&username="+username+"&password="+password)
.map( response -> {
if(response == null)
return play.mvc.Results.noContent();
System.out.println(response.asJson());
JsonNode json = response.asJson();
if(json == null) {
return play.mvc.Results.ok("Expecting Json data");
} else {
String token = json.findPath("authToken").textValue();
if(token == null) {
return play.mvc.Results.ok("Missing parameter [auth Token]");
} else {
return play.mvc.Results.ok("Hello " + token);
}
}
}); }
欢迎任何有关如何解决此问题的意见。感谢。