Reputation: 940
A Java file in the Domino Designer Java library folder (not a Java Agent in the Agents folder) when called from XPage SSJS will throw a NullPointerException for standard methods like createDateTime()
:
import java.io.*;
import java.net.*;
import java.security.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.faces.context.FacesContext;
import javax.net.ssl.HttpsURLConnection;
import com.ibm.commons.util.io.base64.Base64;
import lotus.domino.*;
public class Tools extends AgentBase {
...
public void getSession( ) throws IOException {
Session s = getSession();
DateTime dt = s.createDateTime("Today"); // NullPointerException
String n = s.getEffectiveUserName(); // NullPointerException
...
}
}
If the Java code is saved as a Java Agent, then there is no exception thrown.
Is there another way to set a NotesDateTime field with 'Now" in Java without having to use the session.createDateTime() method?
Is the AgentBase extended or is there another extension to use when using a Java library (not an agent)?
What other ways are there to create a lotus.domino.Session that might help?
UPDATE: In plugin.xml, I added com.ibm.xsp.extlib as a Dependency, and the Java class compiled error-free.
XPages Properties, Page Generation Xpage Library com.ibm.xsp.extlib.library is checked.
From server console, tell http osgi ss com.ibm.xsp.extlib returns:
> tell http osgi ss com.ibm.xsp.extlib
osgi> "Framework is launched."
id State Bundle
114 RESOLVED com.ibm.xsp.extlib.controls.nl1_9.0.1.v10_00_20180115-1058
Master=117
115 RESOLVED com.ibm.xsp.extlib.controls.nl2_9.0.1.v10_00_20180115-1058
Master=117
116 RESOLVED com.ibm.xsp.extlib.controls.nl3_9.0.1.v10_00_20180115-1058
Master=117
117 STARTING com.ibm.xsp.extlib.controls_9.0.1.v10_00_20180115-1058
Fragments=116, 115, 114
118 RESOLVED com.ibm.xsp.extlib.core.nl1_9.0.1.v10_00_20180115-1058
Master=121
119 RESOLVED com.ibm.xsp.extlib.core.nl2_9.0.1.v10_00_20180115-1058
Master=121
120 RESOLVED com.ibm.xsp.extlib.core.nl3_9.0.1.v10_00_20180115-1058
Master=121
121 STARTING com.ibm.xsp.extlib.core_9.0.1.v10_00_20180115-1058
Fragments=119, 118, 120
122 RESOLVED com.ibm.xsp.extlib.domino.nl1_9.0.1.v10_00_20180115-1058
Master=125
123 RESOLVED com.ibm.xsp.extlib.domino.nl2_9.0.1.v10_00_20180115-1058
Master=125
124 RESOLVED com.ibm.xsp.extlib.domino.nl3_9.0.1.v10_00_20180115-1058
Master=125
125 STARTING com.ibm.xsp.extlib.domino_9.0.1.v10_00_20180115-1058
Fragments=123, 124, 122
126 RESOLVED com.ibm.xsp.extlib.mobile.nl1_9.0.1.v10_00_20180115-1058
Master=129
127 RESOLVED com.ibm.xsp.extlib.mobile.nl2_9.0.1.v10_00_20180115-1058
Master=129
128 RESOLVED com.ibm.xsp.extlib.mobile.nl3_9.0.1.v10_00_20180115-1058
Master=129
129 STARTING com.ibm.xsp.extlib.mobile_9.0.1.v10_00_20180115-1058
Fragments=127, 128, 126
130 RESOLVED com.ibm.xsp.extlib.oneui.nl1_9.0.1.v10_00_20180115-1058
Master=133
131 RESOLVED com.ibm.xsp.extlib.oneui.nl2_9.0.1.v10_00_20180115-1058
Master=133
132 RESOLVED com.ibm.xsp.extlib.oneui.nl3_9.0.1.v10_00_20180115-1058
Master=133
133 STARTING com.ibm.xsp.extlib.oneui_9.0.1.v10_00_20180115-1058
Fragments=132, 130, 131
134 RESOLVED com.ibm.xsp.extlib.relational.nl1_9.0.1.v10_00_20180115-1058
Master=137
135 RESOLVED com.ibm.xsp.extlib.relational.nl2_9.0.1.v10_00_20180115-1058
Master=137
136 RESOLVED com.ibm.xsp.extlib.relational.nl3_9.0.1.v10_00_20180115-1058
Master=137
137 STARTING com.ibm.xsp.extlib.relational_9.0.1.v10_00_20180115-1058
Fragments=135, 136, 134
138 STARTING com.ibm.xsp.extlib_9.0.1.v10_00_20180115-1058
Note that the log says STARTING com.ibm.xsp.extlib_9.0.1.v10_00_20180115-1058
What does that mean? I've also add an updatesite.nsf file to the server and updated the Notes.ini with OSGI_HTTP_DYNAMIC_BUNDLES=install\update-site.nsf.
When starting HTTP, there is no message that the OSGI is being loaded into the run time.
The error I get when trying to set the Session:
NoClassDefFoundError: com/ibm/xsp/extlib/util/ExtLibUtil
Isn't this class already included with Domino 9.0.1FP10 server?
Upvotes: 0
Views: 467
Reputation: 30970
Get the session with
Session s = ExtLibUtil.getCurrentSession();
Your subsequent code lines will work then.
public class Tools {
...
public void yourMethod() {
Session s = ExtLibUtil.getCurrentSession();
DateTime dt = s.createDateTime("Today");
String n = s.getEffectiveUserName();
...
}
}
The function getSession()
you used works for Java agents only.
Don't forget to include the extension library into your project:
Upvotes: 1