在Play框架中调用Web服务抛出执行异常

时间:2013-10-10 10:47:59

标签: java web-services rest playframework

使用play WS调用Web Services时,它正在抛出

[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

1 个答案:

答案 0 :(得分:2)

此异常实际上是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>

尝试通过REST客户端(如SOAP UI或PostMan)调用Web服务,然后再将其与Play框架集成。