PoisonedYouth
PoisonedYouth

Reputation: 546

Run Java Agent XPage

I try to run an Java Agent in XPage. The Agent runs in the beforePageLoad Event to manipulate the current document.

 <xp:this.beforePageLoad><![CDATA[#{javascript:
          var agent:NotesAgent =database.getAgent("RedirectGroups")
          agent.runWithDocumentContext(currentDocument.getDocument())
    }]]></xp:this.beforePageLoad>

For testing the agent prints a simple message to the console.

If I run the XPage in Browser I get an error 500 message. I'm using Notes 9.01 on an Domino 9 Server

Will I have to run the agent in an other event of the XPage?

Upvotes: 1

Views: 1028

Answers (2)

Knut Herrmann
Knut Herrmann

Reputation: 30960

The agent has to have

  • Security option "Run as Web user" set
  • as Target "None"

As the agent might run with this options it's not good practice to call a Java agent in an XPage. Better call/use the Java code direct in your XPage.

Upvotes: 3

John Dalsgaard
John Dalsgaard

Reputation: 2807

Well, the first thing you have to realize is that a Java agent runs in a totally different context than the XPage. They are running in two separate JVMs. It is therefore also important to understand that you will NOT have access to any of the classes/resources available to your XPage from your agent.

To run Java code that manipulates your document you would use e.g. managed beans and instead of just having the opening/saving phases of a "traditional" Domino web application you will have the 6 phases in the JSF lifecycle to interact with your data source. This is a better pattern for modifying your data in an XPages application.

When you get an error 500 it means that some logic in the server side has failed (e.g. in a managed bean or some SSJS). The best way to see this is by using the XPages LogReader from openntf.org that will show you the contents of the local files from the server with the error messages (and stack trace).

You can find valuable info about how to use Java in XPages via a number of NotesIn9 video sequences.

Upvotes: 5

Related Questions