OpenNTF / org.openntf.domino

Open replacement for lotus.domino package in HCL Domino
Apache License 2.0
66 stars 34 forks source link

ODA in agent. Session problem #169

Closed Cacus3 closed 5 years ago

Cacus3 commented 5 years ago

Hi, i trying to get ODA working in agent. My code look like this

import org.openntf.domino.*;
import org.openntf.domino.utils.Factory;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {
            if (!Factory.isStarted()) {
                Factory.startup();
            }
            Factory.initThread(Factory.STRICT_THREAD_CONFIG);
            Session ss = getSession();
            AgentContext agentContext = ss.getAgentContext();
            Document doc = ss.getCurrentDatabase().getDocumentByID(agentContext.getCurrentAgent().getParameterDocID());
            Raport raport = new Raport();
            raport.generuj(doc, ss);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Factory.termThread();
        }
    }
}

And i get

Agent printing: [ODA::SEVERE] Unable to get the session of type CURRENT. This probably means that you are running in an unsupported configuration or you forgot to set up your context at the start of the operation. If you're running in XPages, check the xsp.properties of your database. If you are running in an Agent, make sure you start with a call to Factory.setSession() and pass in your lotus.domino.Session [24625:00140-00007FF095B92700] 30-07-2019 08:09:14 Agent printing: [ODA::SEVERE] (source:org.openntf.domino.utils.Factory.getSession) [24625:00140-00007FF095B92700] 30-07-2019 08:09:14 Agent error: lip 30, 2019 8:09:14 AM org.openntf.domino.utils.Factory getSession POWA▒NE: Unable to get the session of type CURRENT. This probably means that you are running in an unsupported configuration or you forgot to set up your context at the start of the operation. If you're running in XPages, check the xsp.properties of your database. If you are running in an Agent, make sure you start with a call to Factory.setSession() and pass in your lotus.domino.Session i looked for Factory.setSession() but i dont known how "pass to lotus.domino.Session" i hope you can help me :)

jesse-gallagher commented 5 years ago

Agent support has admittedly fallen by the wayside because none of the development team uses it. However, you may be able to get it to work by using Factory.setSessionFactory(...) - for example, using Java 8 syntax:

Factory.setSessionFactory(() -> getSession(), SessionType.CURRENT);
Cacus3 commented 5 years ago

Thanks, its work.