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 21, 2011, 12:51 PM
3 Posts
topic has been resolvedResolved

Get resource (XPage) of the database from Java Agent

  • Category: Other
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: xpage,java agent,resource
  • Replies: 4
Well, here we go.
Some time ago I created a Server-Side Javascript that get the xpage like a resource and open a stream, then it process the source code of the xpage.

This is the code:

var url:string = "/" + xpage + ".xsp";  //xpage is a variable with just the name of the XPage
var con = facesContext.getExternalContext().getResource(url).openConnection();
var reader:java.io.BufferedReader = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));


Ok, I could accesc the resource with the facesContext.getExternalContext().
Now, I need to do the same thing, but in the Java Agent. I don't have the 'facesContext' to do the same thing. Then, I tried:

String resource = "/" + xpage + ".xsp";
InputStream is = this.getClass().getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));


and

String resource = "/" + xpage + ".xsp";
InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));


In the both cases, it gets the resource of the Java Agent's project. But I want the resource of the database (.nsf). In tried a lot of things, including open a http connection to the xpage, but when I read from the inputStream, it returns a HTML's code, and I want the Xpage's code.

Can someone help me with this? I'm trying this for a week.

Thanks a lot.

aaaa
Feb 21, 2011, 2:43 PM
40 Posts
Re: Get resource (XPage) of the database from Java Agent
 Inside an agent, this isn't possible.  Each agent is its own project, and can not share the java context or files with the rest of the NSF. This is the same reason why you can not include java from XPages in your agent and vice versa.
Feb 21, 2011, 2:55 PM
9 Posts
Re: Get resource (XPage) of the database from Java Agent
 Part of the problem is that the Agent Manager is going to use a different ClassLoader than the XPages servlet itself. So a lot of the no-effort capabilities provided by XPages aren't yet available in Agents. In this particular case, to get the same behavior, you would need to import the entire NotesFileSystem plugin to your agent. This could prove... daunting.
 
However, a much simpler solution would be to use DXL from the Agent content. You can build a NoteCollection that includes your XPage resource fairly easily, and when you export it via DXL to a stream, you'll have an XML block containing the  base64-encoded XSP source as a file attachment. I believe it's in the $FileData item. Extract this content, base64-decode it, and you should have your original XSP markup.
 
Otherwise, if you want to go with the ResourceAsStream route, you're going to have to do a lot of reverse engineering on the plugin JARs that make up the XPages runtime so you can include them in your Agent. It will take a while. 
 
You might also want to try the XAgent approach, as documented by Stephan Wissel. Google is your friend to find that one. 
Feb 22, 2011, 2:26 PM
3 Posts
Re: Get resource (XPage) of the database from Java Agent
Thank you. I'll try to do something.
Feb 24, 2011, 1:50 PM
3 Posts
Re: Get resource (XPage) of the database from Java Agent
Well, I got it!
 I thought about the Nathan T. Freeman's post and tried some solutions. Then I just created a field in the document's form and set it with the xpages's code.
Thanks everybody. :]

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