6

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":".....
xpagesbeast
  • 708
  • 1
  • 8
  • 18
  • 1
    "I checked the URL being passed in with my browser and I am getting back JSON." That may well depend on what the request headers are though. I suggest you try to use something like Fiddler to see what's actually being returned to your code. – Jon Skeet May 03 '18 at 15:12
  • @DaisyShipton thank you for the Fiddler recommendation, really great tool. I updated the posting with the Response Header. – xpagesbeast May 03 '18 at 15:44
  • So that's the data that the *code* is rejecting? It's very bizarre that it claims to be text/html despite clearly being JSON. That's weird. (I'd really hoped to see that it was returning XML. I'm glad you like Fiddler, but I'm sad that it hasn't solved the problem quickly this time.) – Jon Skeet May 03 '18 at 15:45
  • Did you get the same exception *with that response*? – Jon Skeet May 03 '18 at 15:46
  • @DaisyShipton good point, I am using a workstation, tested the response with my browser hitting the URL. I'll need to remote into the server, and install Fiddler there and see it from there. This may get interesting. Let's see what Fiddler shows us.. be right back. – xpagesbeast May 03 '18 at 15:55
  • Ah, right. In that case, I'm reasonably confident it will indeed show a difference. Make sure you look at the *request* as well as the response! – Jon Skeet May 03 '18 at 15:56
  • The UI is in the browser, the error I'm getting is a server side exception in the application server. The UI simply shows no data in a html table. When trying Fiddler on the server, using a browser on the server, I do not see the GET request being done by the application server, Fiddler is showing traffic in the browser context. Can fiddler inspect the application server http traffic? – xpagesbeast May 03 '18 at 16:08
  • Yes, Fiddler acts as a proxy, so it should definitely be able to intercept app server traffic, although you may need to restart the server. – Jon Skeet May 03 '18 at 16:41
  • The server has two OSGi plugins running, and they are actually calling each other, I'm not sure if this traffic loops through the network card because I cannot see it using Fiddler or Wireshark. I think I need to get that response via code, not sure how to do that. – xpagesbeast May 03 '18 at 17:09
  • Ah - yes, that'll make things trickier. Not sure the best way to proceed, not knowing the types involved. I'd remove `mediaTypes.add(MediaType.TEXT_HTML);` though, unless you can *actually* cope with HTML. – Jon Skeet May 03 '18 at 22:39

2 Answers2

4

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:password@theotherserver.com/yourdb.nsf/somexpage.xsp to get the result.

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

stwissel
  • 19,390
  • 6
  • 44
  • 90
  • I changed the returned value to a String.class so I can view the response and it was a login form. There was a change on the server to not allow anonymous connections. I had to turn Anonymous access back on. New problem, how can I deploy a HTTP rest service written in Spring with Domino OSGi and share the session so I do not have to authenticate the user again. – xpagesbeast Jun 01 '18 at 12:21
  • You need to provide authentication to that web service. If it is user neutral just modify the URL to include a generic username/password. If it has to be the specific user you need to dig into the cookies coming in and send them along. The big question: if that service is running on the same server: just call the Java class directly – stwissel Jun 01 '18 at 14:10
0

Rest Assured failed to parse specified format

Example for XML, you need to use as

response.as(ClassName.class, ObjectMapperType.JAXB);

Other predefined object mappers that can be used with REST Assured as below:

public enum ObjectMapperType {
    JACKSON_2, JACKSON_1, GSON, JAXB
}
Rohan Kushwaha
  • 698
  • 6
  • 18
AMC
  • 1
  • Can you [edit] this one and format the "code" or output, and the prose so it is clear what you are suggesting? It's unclear to me how this answers the question. –  Jan 23 '19 at 18:07