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



Feb 24, 2011, 8:24 AM
38 Posts
topic has been resolvedResolved

Reading XML/RSS file in SSJS

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.1
  • Role: Developer
  • Tags: SSJS,Java,XML
  • Replies: 7
 I need to read an XML / RSS file in XPages. I know it is possible with Java XML parsers and I am using the same just writing the code in SSJS.
 
Here's my code snippet: 
 
importPackage(javax.xml.parsers);
importPackage(org.w3c.dom);
try {
 var factory:DocumentBuilderFactory = DocumentBuilderFactory.newInstance();
 print(".........................1");
 var builder:DocumentBuilder = factory.newDocumentBuilder();
 print(".........................2");
 var xmlDocument:Document = builder.parse("http://<PATH TO XML/RSS FILE>");
 print(".........................3");
} catch(e) {
 print("ERROR --> " + e.toString())
}
 
 
But the above code is not working, whereas its equivalent Java code when run as a standalone program works. The error shown on console is:
java.net.ConnectException: Connection refused: connect
 
I even tried writing Java agent, Java class (and then using it in SSJS code) but no luck!
 
Any ideas why is this happening?
Feb 24, 2011, 11:25 AM
3 Posts
Re: Reading XML/RSS file in SSJS
Probably a problem with lacking permissions.
 
You could temporarily grant all permissions to all code in the java.policy file of the JVM.

I've a working serlvet accessing and reading from an RSS stream (using RSSlib4J) and an XPage doing an HTTP request and displaying the results (using HTTPClient from apache.org).
 
Please have a look an http://www.assono.de/blog/d6plinks/EC11-Zaehme-den-Tiger
"Folien" means slides. They are in German, but just go for the demos with source code extracts. You can download the demos for the complete code.

Feb 24, 2011, 2:22 PM
40 Posts
Re: Reading XML/RSS file in SSJS
 I can confirm, you do need to loosen the permissions for this to work (at your own risk of course) or you can use the extensibility api to create a component and use that. Those have full security granted to do things like that.
 
 
Feb 25, 2011, 6:56 AM
38 Posts
Re: Reading XML/RSS file in SSJS
Jeremy,
 
I loosened the permissions but still got the same error.  
 
This is what I did: 
1. Opened the file "java.policy" in the directory "<Lotus Notes Installation>\jvm\lib\security" and added the following lines to it
grant {
permission java.security.AllPermission;
};
2. Restarted my Lotus Notes client (I am doing this on my local machine and local database) 
 
Am I missing something? 
Feb 25, 2011, 1:46 PM
40 Posts
Re: Reading XML/RSS file in SSJS
 Do you have a firewall on your local computer that blocks connections on on unknown apps ?
Feb 26, 2011, 2:53 AM
38 Posts
Re: Reading XML/RSS file in SSJS
Yes, I have a firewall. 
 
This is crazy!! I will have to completely open up my computer to hackers in order for this program to run.
 
Any other way to read XML/RSS files which does not require compromising security on my computer / servers? 
Feb 28, 2011, 4:20 PM
41 Posts
Re: Reading XML/RSS file in SSJS
 This would be an outbound connection, not an inbound connection. You don't need to allow port 80 in, just out. Hackers won't be involved unless they're sniffing what you're requesting.
Jun 28, 2011, 11:41 AM
38 Posts
Re: Reading XML/RSS file in SSJS
I know this reply is late but I finally found the culprit - Proxy!
 
If you have a proxy set then you can access websites using the java.net.URL (http://download.oracle.com/javase/6/docs/api/java/net/URL.html) class by calling the function openConnection(java.net.Proxy) and define the proxy address & port.
 
Hope this helps someone else !

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