This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Dec 26, 2011, 2:31 PM
7 Posts

Issue with the GET request to the Domino Data Service

  • Category: Extension Library
  • Platform: All
  • Release: 8.5.3
  • Role:
  • Tags: Domino Data Service,JSON
  • Replies: 4
I am using the example from the GET request to the Domino Data Service below.  I changed the URL: to access a database on my server.  I tested the URL and made sure that it actually returns JSON data and it works.  But when I run the code below it does not return any data. 
 
I conn.getContentLength() and it has data, but i cannot seem to get to the data.  What am I doing wrong?  Also, is it possible to bind this to an objectData type?
 
 
// Establish connection with Domino database collection resource
var url = new java.net.URL("http://ibm-z0shi2lw4cz.swg.usma.ibm.com:80/api/data");
var conn:java.net.HttpURLConnection = url.openConnection();
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() == "200") {
 
	// Get the response
	var reader = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream()));
	var buffer = new java.lang.StringBuffer();
	var line = "";
	while ((line = reader.readLine()) != null) {
		buffer.append(line);
	}
	reader.close();
 
	// Create array from response
	var jsonarray = eval('(' + buffer + ')');
 
	// Get filenames and titles from Domino database collection resource
	// On XPage, requestScope.status is bound to a multi-line text control
	for (var i = 0; i < jsonarray.length; i++) {
		requestScope.status += jsonarray [i].@filepath + " - " + jsonarray [i].@title + "\n";
	}
 
} else { // if connection fails
	requestScope.status = conn.getResponseCode() + " " + conn.getResponseMessage();
}  
 
 
Thank you,
Dec 27, 2011, 9:34 PM
272 Posts
Re: Issue with the GET request to the Domino Data Service
Hi,
 
maybe I am wrong, but does not getResponseCode() return an integer value instead of a string?
 
Hope this helps
Sven
 
Dec 27, 2011, 9:43 PM
7 Posts
Re: Issue with the GET request to the Domino Data Service
Sven,
 
This code above is directly from the Development WIKI: 
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Sending_a_GET_request_in_JavaScript_dds10
 
 Do you know how to get the JSON object?
Dec 29, 2011, 10:12 AM
272 Posts
Re: Issue with the GET request to the Domino Data Service
Are you unable to get data from the server or to extract JSON data?
 
What if you printing the buffer to the console? Is it empty?
Is the eval-Statement executed?
 
Sven
 
http://blog.hasselba.ch
Dec 29, 2011, 2:39 PM
7 Posts
Re: Issue with the GET request to the Domino Data Service
I found my problem: the HttpURLConnections was not authenticating me. I had to add the following:
 
var auth="<user>:<pass>"
conn.setRequestProperty("Authorization","Basic " + new sun.misc.BASE64Encoder().encode(auth.getBytes()));
conn.connect();
 
and then everything works fine.  Why do I have to do this?
 
Thank you.
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal