Forum Discussion

luk's avatar
luk
Boss
11 years ago

http.client request to local Lithium REST API timeout

I have problems using the http.client for calling the local REST API in an endpoint.

 

I need JSON data for REST calls as a response from an endpoint to further process it in the frontend.

 

With the rest context object it seems to not be possible to get an actual JSON object inside FreeMarker as the returned data from a rest() call is always a FreeMarker "node" object, e.g. XML, no matter if I specify "?restapi.response_format=json" in the URL or not.

 

So what I'm trying to do to circumvate this problem is using the http.client to get data from the local REST API but when I call something like:

 

<#local url = "http://community.lithium.com/restapi/vc/categories/?restapi.response_format=json" />

<#local requestObj = http.client.request(url) />

<#local responseObj = requestObj.get() />

 

I get back an error that says:

 

"error making http request: Request timed out"

 

The same thing works with another (remote/foreign) REST API without problems.

 

So my question is if I'm trying something that is just not possible, e.g. calling a (local) Lithium REST API via http.client?

 

The domain is listed under System > HTTP Client, I also tried to request data from other Lithium REST APIs like

 

http://community.sony.ch/restapi/vc/categories/?restapi.response_format=json

 

which also time out when called with the http.client but when entered directly in the browser these calls work as expected and return JSON data...this led to the suspicion that the http.client is just not able to interact with Lithium REST APIs, I hope I'm just doing something very simple wrong, quite new to Lithium^^...

 

I also thought it could be some kind of CORS issue and asked the Lithium support to adjust the CORS configuration, but didn't seem to help, the requests made from FreeMarker still time out when the target is a Lithium REST API.

 

any hints are very much appreciated!

2 Replies

  • luk's avatar
    luk
    Boss
    11 years ago

    Thanks,

     

    I have found the first one about timouts before I even posted the question, but didn't really seem to be the same problem. I guess there it was somehow a "problem" with the remote API that needed longer than 5s to return the response.

     

    The second link/thread also doesn't apply to my problem as I do not want to actually parse the returned JSON data, I just want to wrap it in a JSON structure (similar to v2 API responses) and return it back, no processing at all, that's why I'm not using .json() on the request object.

     

    The problem is, that from ANY (local/remote) Lithium REST API called via http client the requests time out after 5 seconds, every other non-Lithium API that returns JSON works perfectly well with my approach, just not Lithium Instances, as they wouldn't allow it's own http client to request data from it...which seems quite odd...


    I'll request an increased request timeout time from support anyways, maybe the Lithium APIs are just slow?? But I do not have that impression when entering such a URL into the browser, then the data is coming in reasonable time (around 290ms), so that's why I think this is not the issue here...

     

    EDIT: I thought it could be some kind of "User Agent" blocking on Lithiums side and tried so set it via .header("User Agent", "UA String") but didn't help...