1

I'm trying to implement OpenNTF Domino API as a replacement in our project but it fails with this message: "OpenNTF Domino API: org.openntf.domino.utils.Factory is not initialized for this thread!"

Code snippet: boolean init = Factory.isInitialized(); // false Database db = Factory.getSession().getCurrentDatabase(); // This fails of course because no Session

I'm implementing the call in a JAVA DAO behind a EXTLib Servlet in XPages. So it's not called by an XPage but as an REST API call.

The Domino API Demo DB is working so the server install seems to be OK.

Is there a setup, properties I'm missing to init it ?

rbrastad
  • 36
  • 2

1 Answers1

2

Yes, there is specific setup require for non-XPages access, as done in OsgiWorlds on OpenNTF. Nathan has added a DAS extension specifically for REST access from Graph database. You basically need to initialise the session for the Factory before trying to access it, generally done in the Servlet when it initiates the HTTP connection. Please contact me on Twitter (Paulswithers) so the team can work with you. Also it's worth you having a look at the OsgiWorlds source code. Although that's for a Vaadin servlet and allows defining a development user to run as, in production mode it also uses the logged on user name and the configuration class and calls to it from the servlet are effectively what you need from the REST servlet.

Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33
  • Thanks, I got it to work. I used ExtLibUtil as the basis and created a ExtLibApplicationConfig that extends BaseApplicationConfigurator It looks like for me it can be done much easier than with the Vaadin approach due to the fact that ExtLibUtil knows who you are, which DB youre in and so on. I'll look more into this :) – rbrastad Oct 14 '15 at 23:03
  • Yes, the ContextInfo object is the key to getting the current user and session. Now I am at my computer, if you have the source code, check out org.openntf.domino.rest.servlet.ODADataServlet which uses org.openntf.domino.xsp.session.DasCurrentSessionFactory. That's https://github.com/OpenNTF/org.openntf.domino/blob/master/domino/rest/src/main/java/org/openntf/domino/rest/servlet/ODADataServlet.java and https://github.com/OpenNTF/org.openntf.domino/blob/master/domino/xsp/src/main/java/org/openntf/domino/xsp/session/DasCurrentSessionFactory.java. – Paul Stephen Withers Oct 15 '15 at 07:54
  • The rest package was not delivered as part of the server-available code in 2.0.0, but ODADataServlet is what will be in your code. Bear in mind that Session fixes won't automatically get applied, so I'd recommend adding those in. ODADataServlet gives you ideas on those. – Paul Stephen Withers Oct 15 '15 at 07:55
  • Thanks again, I'll take a deep dive :=) – rbrastad Oct 15 '15 at 08:13
  • Hey, After some more testing I found out that I could start and stop the ODAPlatform in the Activator class of the NSF. Do you see any issues with this approach or any expreience doing it here. I have done a lot of OSGI programming some years back and this is a good starting point for starting and stopping things @Paul Stephen Withers – rbrastad Oct 16 '15 at 06:45
  • I'll check with the team. I see ODADataServlet does that but I had assumed it was one instance of ODAPlatform for the server, so OsgiWorlds checked whether it was running, if not, started it and added a flag that it was OsgiWorlds that started it and so should also stop it. But I may have misunderstood. – Paul Stephen Withers Oct 16 '15 at 07:37
  • The ODAPlatform is loaded once per servlet So if you have another servlet in the NSF or use ODA elsewhere in the NSF, you could get unexpected results. ODAPlatform in 2.0.0 should have an isStarted() method you can use, I added it a couple of months ago for OsgiWorlds – Paul Stephen Withers Oct 19 '15 at 07:43
  • Thanks, i hsve added the isstarted check. Everything Seems ok. No Errors :) – rbrastad Oct 19 '15 at 08:13