使用 play WS 调用 Web 服务时,它会抛出异常
[RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.jboss.netty.buffer.ChannelBufferInputStream@1fecc4f; line: 1, column: 2]]
环境:Ubuntu 12.04 + Java 1.7 + Play Framework 2.2.0
最佳答案
这个异常实际上是JsonParseException
这意味着String
您实际上尝试解析的不是有效的 JSON。出现此问题的原因是收到的响应采用 XML 或 HTML 格式,并且包含字符 <
当服务不可用且该类型的响应时常见
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /123 was not found on this server.</p>
<p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
或
<data contentType="null" contentLength="0"><![CDATA[]]></data>
在将 Web 服务与 Play 框架集成之前,尝试通过 REST 客户端(例如 SOAP UI 或 PostMan)调用 Web 服务。
关于java - 在 Play 框架中调用 Web 服务抛出执行异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19293695/