0
votes

I have encounter recently an interesting problem. I am trying to access sametime by using the integrated REST API. To do that i wanted to prepare an XAgent that is doing the lookup and data connection for me.

The first two steps to connect to the Sametimeserver work perfectly fine but i have a problem with the last step. Regardless what i do i cant set the header of the GET request. I tried it with other fields then one mentioned below but it looks like its not setting the header.

Anybody any idea why setting the header in SSJS doesnt work?

var url = new  java.net.URL("http://oursametimeserver/stwebapi/RTCServlet?"+sid);       
conn= url.openConnection();   
conn.setRequestProperty("Rtc4web-Nonce",pid);
conn.setRequestMethod("GET");
writer.write(@Implode(conn.getHeaderFields()));

Please see the results:

{null=[HTTP/1.1 400 Bad Request], Cache-Control=[no-cache="set-cookie, set-cookie2"], Expires=[Thu, 01 Dec 1994 16:00:00 GMT], X-Powered-By=[Servlet/3.0], Content-Length=[170], Content-Language=[en-US], Content-Type=[application/json], Connection=[Close], Date=[Mon, 09 Mar 2015 19:18:54 GMT], Set-Cookie=[JSESSIONID=0000zwXn8VhNWlZ78jN4yfMJQrU:-1; Path=/; HttpOnly]}

Please ignore the Error 400. The rest api returns it because i am not submitting the RTC4WEB-NONCE field in the header. I get the same result when i use POSTMAN in chrome. With that value everything is fine.

1

1 Answers

1
votes

You need to change your approach slightly:

1) Write a small Java class that wraps all the call to Java objects, so you can call that one with a simple JS call. It takes the "map a untyped js variable to a typed Java method" guesswork out of the picture

2) Don't use the HttpUrlConnection class. Either use the ApacheHttp Client which is both available and has methods to set the header - or use the social business toolkit that has ready functions to connect to Sametime