Domino 11.0 does not support java.pol

When running Java and XPages on Domino it is sometimes required to loosen up the Java security restrictions by editing the jvm/lib/security/java.policy file or by adding a java.pol file with the required changes.

But on HCL Domino 11.0 it is no longer supported to use a java.pol file since the java.security file in Domino 11.0 on longer includes a reference to a java.pol file. This (unfortunate) change is related to the move from the IBM JRE to the AdoptOpenJDK JRE.

In a future release of HCL Domino this could be re-introduced if HCL adds support for it in the java.security file. I have created an idea on re-adding support for it.

Thanks to Daniele Vistalli for pointing out that you can use the option to add a modified java.policy file to the home directory of the user running the Domino instance since the java.security file still includes this option:

policy.url.2=file:${user.home}/.java.policy

On my Windows Server the Domino service runs under the local system account and the home directory of the local system account is C:\Windows\System32\config\systemprofile. So by adding a modified .java.policy file to this directory, it does indeed work (notice that the file must be called .java.policy according to policy.url.2 in java.security).

Update January 2022:

As of Domino 12.0.1 support for java.pol is back. The java.security file now contains a reference to a java.pol in the same directory as the java.security/java.policy files:
policy.url.1=file:${java.home}/lib/security/java.policy
policy.url.2=file:${java.home}/lib/security/java.pol
policy.url.3=file:${user.home}/.java.policy

IBM Domino and IBM Notes/Domino Designer 9.0.1 FP10 has been released: major update to the platform!

IBM Domino and IBM Notes/Domino Designer 9.0.1 Feature Pack 10 has been released today and is available for download on IBM Fix Central. This is a major update to the platform.

The most important updates for developers include:

  • Upgrade from Java 1.6 to Java 1.8 for both Domino Designer and the server
  • The Domino Designer Eclipse platform is now running version 4.6.2 (a major upgrade from Eclipse 3.4.2)
  • OSGi is upgraded

More details of changes are available at developerWorks. Details of all fixes will be available later in the usual Fix List database.

How to recycle Notes objects in XPages and Java

Using Notes objects in XPages and in Java require that you recycle those objects in order to avoid memory leaks and backend out of memory issues. Here I will summarize how to do proper recycling in XPages for server-side javascript, Java and Java using the new OpenNTF project org.openntf.domino.

Server-side JavaScript

With server-side JavaScript you have to use the recycle method available on Notes objects and you have to “nullify” your server-side JavaScript variables. Thank you, Tony McGuckin, for clarifying this.

Here’s a very simple example that assumes that the variable doc has been initialized elsewhere:

doc.recycle();
doc = null;

Java

In Java you have to use the recycle method available on Notes objects. So for looping through a document collection you have to do this:

try {
	Database dbCurrent = ExtLibUtil.getCurrentDatabase();
	DocumentCollection dc = db.getAllDocuments();
	Document doc = dc.getFirstDocument();
	While (doc != null) {
		// process doc
		tmp = dc.getNextDocument(doc);
		doc.recycle();
		doc = tmp;
	}
	dc.recycle();
} catch (NotesException e) {
	e.printStackTrace();
}

org.openntf.domino

With org.openntf.domino you do nothing with regards to recycling! So when looping through a document collection you can concentrate on your business logic:

Database db = Factory.getSession().getCurrentDatabase();
for (Document doc : db.getAllDocuments())
	// process doc
}

I am now an IBM Certified Advanced Application Developer – Lotus Notes and Domino 8.5

I recently passed the LOT-922 certification test (Developing IBM Lotus Domino 8.5.2 Applications: Advanced XPage Design). The test is a multiple choice test with 32 questions and a required passing score of 75%- I scored 90%.

Since I was already an IBM Certified Application Developer on Notes/Domino 8.5 the passing of the test upgraded my certification level to IBM Certified Advanced Application Developer – Lotus Notes and Domino 8.5.

I prepared for the test by reading the test objectives and by practicing using a practice test from CertFX. The test focuses on advanced XPages programming and covers the following areas:

  • Building themes
  • Extending the data sources
  • Optimizing, troubleshooting and localization
  • Using advanced Dojo controls
  • Using Server-side JavaScript
  • Using XPages for mobile user interfaces
  • Working with Java

Unfortunately, the test is already somewhat outdated in its focus on Domino Designer 8.5.2. So be prepared for that if you plan to take the test.

Creating your first managed bean for XPages

With Java and managed beans you can make your XPages applications even more powerful. In this blog post I will go through the steps to create and use a managed bean in XPages.

I am using Lotus Notes and Domino Designer 8.5.3 and will therefore use the new Java design element for the Java code located in the Code section.

In short: use “New Java Class” to create a Java class. Give your new class a package name (e.g. com.company) and a class name (e.g. HelloWorld). Add a local variable and let Eclipse generate getter and setter for it by using Source – Generate Getters and Setters. Also, let Eclipse generate a public no-parameter constructor by using Source – Generate Constructor using Fields and deselect your newly created field and omit call to super().

You will then have the following basic skeleton for a Java class:

package com.company;

public class helloworld {

	public helloworld() {
	}

	private String someVariable;

	public String getSomeVariable() {
		return someVariable;
	}

	public void setSomeVariable(String someVariable) {
		someVariable = someVariable;
	}

}

In order to support the XPages server page persistence option “Keep pages on disk”, the Java class needs to be serializable. The Java class therefore needs to implement Serializable. Therefore, add “implements Serializable” after your class name (and Eclipse will automatically add the required import). Then use the Eclipse Quick Fix to “Add generated serial version ID”. You now have a basic skeleton for a Java class that can be used as a managed bean:

package com.company;

import java.io.Serializable;

public class helloworld implements Serializable {

	private static final long serialVersionUID = 6469339826789980362L;

	public helloworld() {
	}

	private String someVariable;

	public String getSomeVariable() {
		return someVariable;
	}

	public void setSomeVariable(String someVariable) {
		someVariable = someVariable;
	}

}

Now we need to tell XPages that we would like to use this Java class as a managed bean. First, Add the Package Explorer view to your Eclipse perspective using Window – Show Eclipse Views – Other and select Package Explorer. Now go to the Package Explorer and navigate to the WebContent/WEB-INF folder where you will find a faces-config.xml file. Open the faces-config.xml file and add the following managed bean section in the <faces-config> section:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
	<managed-bean>
		<managed-bean-name>helloWorld</managed-bean-name>
		<managed-bean-class>com.company.helloworld</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
</faces-config>

You now have a basic faces-config for your HelloWorld Java class. Scope for a bean can be the usual scopes (application, session, view, request).

With the Java class and the faces-config in place the managed bean can now be used in an XPage. The bean value (both the getter and setter) can be accessed from an XPage using #{helloWorld.someVariable}.

This very basic example of a bean does not do anything. The Java class would of course have to add values to the someVariable property before that value would be useful in an XPage. I will create a 2nd blog post that shows how to use a bean in a repeat control to display values from the managed bean.

For more information on XPages and managed beans have a look at:

Integrating a Lotus Notes application with Exchange

I recently finished a project with the purpose of integrating a Lotus Notes CRM application with Microsoft Outlook and Microsoft Exchange. The customer has moved their mail handling to Exchange and Outlook and still uses Lotus Notes for their application handling including this CRM application. The CRM application had functionality to import mails from Notes, send mail from Notes, and create and maintain meeting invitations. My task was to make this functionality work with Exchange and Outlook instead.

In order to integrate with Exchange I used the Exchange Web Services (EWS) Java API and created a Java class with the necessary jar files imported that is responsible for the interface between the existing Lotusscript logic and the EWS API. The Lotusscript logic then uses LS2J to use the methods in the Java class.

With Exchange Web Services installed on the Exchange server the Java API can access the web services using the WSDL at /EWS/Service.wsdl (through an endpoint called /EWS/exchange.asmx).

To allow the Lotus Notes client to communicate with the Exchange server I needed to change the java.policy file in order to add: permission java.net.NetPermission “setCookieHandler”, “write”;. To automate this I used this Lotusscript code by Darren Oliver that checks the java.policy file for a specific permission policy and if not found adds the permission policy.

At first I wanted to use Exchange Impersonation to allow a single Windows Active Directory account to be able to act on behalf of others users on a Exchange mailbox. This decision was later changed to use the individual users own credentials. The user is prompted for their password and this is stored encrypted for their use only in a profile document. The following code snippet shows how communication with the Exchange server is set up in Java using the EWS API:

service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// service.setTraceEnabled(true); // enable to trace the web service communication in the Java debug console
service.setUrl(new java.net.URI(server));
ExchangeCredentials credentials = new WebCredentials(userid, password);
service.setCredentials(credentials);

A meeting is simply created using the Appointment class. Time zone support is achieved by using UTC as the time zone for date details. To format dates as UTC I used the LSGMTTime  property of the NotesDateTime class.

Appointment appointment = new Appointment(service);
appointment.setSubject(subject);
appointment.setBody(MessageBody.getMessageBodyFromText(body));
appointment.setStart(formatter.parse(startDate));
appointment.setEnd(formatter.parse(endDate));
appointment.setLocation(location);
// Save as appointment - and not as a meeting with participants
appointment.save(SendInvitationsMode.SendToNone);

Importing mails is done by presenting the user with a list of mails from the users Exchange mailbox. The list is retrieved by looping through the Inbox folder:

ItemView view = new ItemView(100);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
FindItemsResults<Item> findResults;
findResults = service.findItems(WellKnownFolderName.Inbox, view);
service.loadPropertiesForItems(findResults.getItems(), new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.DateTimeReceived, EmailMessageSchema.Sender));

The user then selects a mail from the list and the corresponding mail in Exchange is retrieved with the unique item id as identifier.

EmailMessage message = EmailMessage.bind(service, new ItemId(mailItemId));

Rich text support between Notes and Outlook is handled using Lotusscript stream and mime classes:

Set stream = session.CreateStream
Call stream.WriteText(mailBody)
Set mime = doc.CreateMIMEEntity("Body")
Call mime.SetContentFromText (stream, "text/html;charset=UTF-8",ENC_NONE)

When sending mails from the Notes CRM application the user can access their Outlook contacts. The list of Outlook contacts is retrieved by looping through the Contacts folder:

ItemView view = new ItemView(2000);
view.getOrderBy().add(ContactSchema.DisplayName, SortDirection.Ascending);
FindItemsResults<Item> findResults;
findResults = service.findItems(WellKnownFolderName.Contacts, view);

The Microsoft Outlook client is launched when a meeting invitation is created in order for the user to finish the meeting invitation in Outlook. This is achieved by using the Shell Lotusscript command together with the fact that Outlook can be launched with a parameter that indicates what item to open when launched:

Shell( getOutlookPath() + " /select outlook:" + Ucase(doc.OutlookUniqueId(0)) )

The use of LS2J led to some performance issues at the customer site in the form of 10-20 seconds load times before a document was opened. The reason for this is that the Java code is extracted to disk whereby the Antivirus program at use at the customer site started to check all files for virus before the document could be opened. The customer modified the Antivirus settings to remove this check whereby the documents opened within reasonable time again.

getItemValueString and Domino 6.5.5 and 7.0 (Show’n Tell Thursday)

The return value of the Java method getItemValueString has been changed in Lotus Domino 6.5.5, Lotus Domino 7.0 and later releases. Before 6.5.5 the method getItemValueString returns null if the item is empty or if the item does not exist. In 6.5.5, 7.0 and later releases getItemValueString returns the empty string (“”) instead.

I upgraded three servers from 6.5.4 to 6.5.5 and found out the hard way when the application didn’t work as expected. Conditions checking getItemValueString for null values were never met so lots of logic was skipped.

So if you plan to upgrade to 6.5.5 og 7.0 or later then check your Java code for the use of getItemValueString.

Update: I have added this post to the Lotus Notes and Domino Blogging Community Show’n Tell Thursday series.

Write AJAX apps using Java (Google Web Toolkit)

Google Web Toolkit has been released. From the overview: “Google Web Toolkit (GWT) is a Java development framework that lets you escape the matrix of technologies that make writing AJAX applications so difficult and error prone. With GWT, you can develop and debug AJAX applications in the Java language using the Java development tools of your choice. When you deploy your application to production, the GWT compiler to translates your Java application to browser-compliant JavaScript and HTML.

This should make it easier to use AJAX functionality with Domino web applications.

Update: EclipseZone has an article called “Getting started with Google Web Toolkit (GWT)” that describes in detail how to use GWT.

June 27 update: An article on developerWorks has just been published: “Ajax for Java developers: Exploring the Google Web Toolkit“.