Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected character ('<' (code 60))

I'm getting a weird error. This used to work. I'm not sure if it is app server, code, 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.jackson.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.jackson.core.JsonParser._constructError(JsonParser.java:1524)
JVM:  at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:557)
JVM:  at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:475)
JVM:  at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2343)
JVM:  at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:818)
JVM:  at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:698)
JVM:  at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3031)
JVM:  at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2978)
JVM:  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2158)
JVM:  at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:225)
```


```
import org.springframework.web.client.RestTemplate;

public static RestTemplate getRestTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        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.

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?

2) Is there a way to get the http error?

Updated 5/3/2018 Using Fiddler Daisy recommended, the GET Response Header using Browser on my workstation (however, app is running on server).

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":".....
like image 762
xpagesbeast Avatar asked May 03 '18 15:05

xpagesbeast


1 Answers

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 Chrome that renders the JSON in the browser so you can check.

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).

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.xsp to get the result.

So first check: Does your server use a user/pass and does it have sufficient access.

like image 85
stwissel Avatar answered Nov 05 '22 12:11

stwissel