« How SmartNSF came to rescue in a heavily surveilled little (bird) house | Main| How to configure BitLocker so it doesn"t need 72 hours to encrypt 2 TB! »

How a SmartNSF custom route can be used to create a redirector, in my case to open the corresponding Notes-document

Tags: SmartNSF Java
0

I am – to nobody’s surprise – a big fan of SmartNSF. Here the other day I had to come up with a solution to make a web-URL redirect to a Notes-URL (you know, notes://…) and thus open a document in the Notes client. Why? A modernized Notes application surface it’s data on the web, but the users still needs to be able to see the real document in the Notes client. There are several ways to do this with traditional Notes development. However, I wanted to see how I can do this with a simple java class, all controlled by a SmartNSF custom rule.

For example, the URL http://someserver.com/DocumentDatabase.nsf/xsp/.xrest/doc_v1/5921-A4 will grab the document ID “5921-A4” and lookup the document behind the scenes, and grab the NotesURL such as Notes://SomeDominoServerName/C12573EF007A4D9D/B3612539371CB37AC125830D002A4BF9/67FD0734318B98A4C12582B900208F1F. The latter URL will normally open the specified document UNID in the Notes client, at least after you have confirmed security warnings like these;

image

How is it done?

First, if you don’t have SmartNSF on your server and in your Designer client, head over to the documentation to see how to get there. If you need more tips on how to set up the custom route and work some java, take a look at my article Wow! SmartNSF (BETA-5) can now call java directly, and work with the parameters with ease!

First – create the SmartNSF route and map it to the coming java class

OK, lets start by looking at the SmartNSF definition, or the so called XRest API Routes. You find this design element below the “Application Configuration” marked by (1) below;

SNAGHTML150e9d1

Marked by (2) you see the so-called route, “documents/{docID}”. This is where you define how you want to access your data with REST Services call. In my example the route will make the URL like this;

http://webserver.no/databasename.nsf/xsp/.xrest/documents/<documentid>

Pay special attention to the variable name {docID} as this will be used later in the code!

Marked by (3) you see how SmartNSF maps the route to the java class with the package name “no.vcode.utility” and the java class “RedirectDoc”.

Then – add the java class RedirectDoc.java

Start by switching the Designer perspective to XPages. This will make Designer access the java classes directly. Below you see how I have added the java class “RedirectDoc.java”, living inside the package “no.vcode.utility”. Should be familiar from the SmartNSF route-definition above Smile

SNAGHTML1470ac7

Opening the RedirectDoc.java, it the complete java code looks like this;

SNAGHTML14acce0

Click on image above to see larger image

Below I focus on the key aspacts in the code above.

Just above the mark (1) you see the so-called package name. Change it to whatever you like, but remember to redefine it in the SmartNSF-route.

Marked by (2) I use a map to store all parameters from the context. Among a bunch of context-related variables such as the current database etc, you also get your own variables, such as docID, from the URL.

Marked by (3) I get the content of the variable docID from the current URL. This means that if I for example use this URL;

http://webserver.no/databasename.nsf/xsp/.xrest/documents/01
… the docID will contain “01”

Marked by (4) I use ordinary Notes-java code to get the database and open a view which is sorted on the document ID. I then locate the document with the ID from the docID-variable.

If I find the document, I grab the Notes document’s property NotesURL – marked by (5).

Marked by (6) i get the response object from the context (which is a HttpServletResponse object) and set the response status to 302 (“Moved Temporarily” - see here for the meaning of HTTP Response code 302) and set the redirect location via the method Location.

That’s it! You have a full functioning redirect handler now.

OK, marked by (7) I also have some error handling in case you specify a docID that doesn’t exist, or if anything bad happens during the call.

Hope this may be to help for someone!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)