Java 意外字符('<'(代码 60))
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50158404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unexpected character ('<' (code 60))
提问by xpagesbeast
I'm getting a weird error. This used to work. I'm not sure if it is app server, code, jvm?
我收到一个奇怪的错误。这曾经奏效。我不确定它是应用服务器、代码还是 jvm?
JVM: Java Virtual Machine initialized.
Java runtime version: pwa6480sr4fp5-20170421_01 (SR4 FP5)
JVM version: JRE 1.8.0 Windows Server 2008 R2 amd64-64 20170419_344392 (JIT enabled, AOT enabled) J9VM - R28_20170419_1004_B344392 JIT - tr.r14.java_20170419_344392 GC - R28_20170419_1004_B344392 J9CL - 20170419
```
``
JVM: Caused by:
JVM: com.fasterxml.Hymanson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
JVM: at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@2a19861e; line: 1, column: 2]
JVM: at com.fasterxml.Hymanson.core.JsonParser._constructError(JsonParser.java:1524)
JVM: at com.fasterxml.Hymanson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:557)
JVM: at com.fasterxml.Hymanson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:475)
JVM: at com.fasterxml.Hymanson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2343)
JVM: at com.fasterxml.Hymanson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:818)
JVM: at com.fasterxml.Hymanson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:698)
JVM: at com.fasterxml.Hymanson.databind.ObjectMapper._initForReading(ObjectMapper.java:3031)
JVM: at com.fasterxml.Hymanson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2978)
JVM: at com.fasterxml.Hymanson.databind.ObjectMapper.readValue(ObjectMapper.java:2158)
JVM: at org.springframework.http.converter.json.MappingHymanson2HttpMessageConverter.readJavaType(MappingHymanson2HttpMessageConverter.java:225)
```
```
import org.springframework.web.client.RestTemplate;
public static RestTemplate getRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
MappingHymanson2HttpMessageConverter converter = new MappingHymanson2HttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_HTML);
mediaTypes.add(MediaType.APPLICATION_JSON);
converter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(converter);
messageConverters.add(new StringHttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
return restTemplate;
}
//The call is here
ResponseEntity<BargeType[]> responseEntity = getRestTemplate().getForEntity(url+"/bargetype", BargeType[].class);
```
I checked the URL being passed in with my browser and I am getting back JSON. I copy and pasted the response into json lint and validated it successfully.
我检查了使用浏览器传入的 URL,然后返回 JSON。我将响应复制并粘贴到 json lint 中并成功验证。
I'm guessing there is an error returned because the error messsage has '<' in the exception.
我猜有一个错误返回,因为错误消息在异常中有“<”。
My questions are:
我的问题是:
1) Is there a better pattern to use RestTemplate?
1) 有没有更好的模式来使用 RestTemplate?
2) Is there a way to get the http error?
2)有没有办法得到http错误?
Updated 5/3/2018 Using Fiddler Daisy recommended, the GET Response Header using Browser on my workstation (however, app is running on server).
2018 年 5 月 3 日更新推荐使用 Fiddler Daisy,GET Response Header 在我的工作站上使用浏览器(但是,应用程序正在服务器上运行)。
HTTP/1.1 200 OK
Server: Lotus-Domino
Date: Thu, 03 May 2018 15:28:23 GMT
Connection: close
Content-Type: text/html; charset=UTF-8
[{"contract":xxxx,"customer":".....
采纳答案by stwissel
An XPage by default returns its result as text/html
despite of what you do in the XPage. If, as the example suggest, you compute JSON (and not HTML looking like JSON), you can overwrite the returned header to application/json
. Then add a plugin to Chromethat renders the JSON in the browser so you can check.
text/html
无论您在 XPage 中执行什么操作,XPage 都会默认返回其结果。如果,如示例所示,您计算 JSON(而不是看起来像 JSON 的 HTML),您可以将返回的标头覆盖为application/json
. 然后向 Chrome添加一个插件,在浏览器中呈现 JSON,以便您进行检查。
What is very well possible: If a server calls Domino, how does it authenticate? When you have session based authentication and it fails, you won't get a 401 back, but the HTML based input form for username/password (Try the page in your browser using an anonymous window).
很有可能:如果服务器调用 Domino,它如何进行身份验证?当您使用基于会话的身份验证并且失败时,您将不会得到 401,而是返回基于 HTML 的用户名/密码输入表单(使用匿名窗口尝试浏览器中的页面)。
In the Domino configuration you can specify that a URL can use basic authentication besides the session. Then your server can send https://user:[email protected]/yourdb.nsf/somexpage.xspto get the result.
在 Domino 配置中,您可以指定 URL 可以使用除会话之外的基本身份验证。然后您的服务器可以发送https://user:[email protected]/yourdb.nsf/somexpage.xsp来获取结果。
So first check: Does your server use a user/pass and does it have sufficient access.
所以首先检查:您的服务器是否使用用户/通行证并且它是否有足够的访问权限。
回答by Paul A M C
Rest Assured failed to parse specified format
Rest Assured 无法解析指定的格式
Example for XML, you need to use as
XML 示例,您需要将其用作
response.as(ClassName.class, ObjectMapperType.JAXB);
Other predefined object mappers that can be used with REST Assured as below:
可与 REST Assured 一起使用的其他预定义对象映射器如下:
public enum ObjectMapperType {
HymanSON_2, HymanSON_1, GSON, JAXB
}