异步调用代理Xpages

时间:2014-07-24 14:55:06

标签: xpages

我将此代码提供给OpenNTF.org上的Thread and Jobs应用程序

import lotus.domino.NotesException;
import lotus.domino.Session;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;

import com.ibm.domino.xsp.module.nsf.ThreadSessionExecutor;

public class JobRunner {

public static void start(String dbPath, String agentName, String paramDocId) {

    synchronized (JobRunner.class) {

        runningJob = new ISPJob(dbPath, agentName, paramDocId);
        runningJob.addJobChangeListener(new JobChangeAdapter() {
            public void done(IJobChangeEvent event) {
                System.out.println("Done event");
                runningJob = null;
            }
        });
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                runningJob.schedule();
                return null;
            }
        });

    }
}

private static ISPJob runningJob;

private static final class ISPJob extends Job {

    private ThreadSessionExecutor<IStatus> executor;

    private String docId;
    private String dbPath;
    private String agentName;

    public ISPJob(String paramDbPath, String paramAgentName, String paramDocId) {
        super(paramDocId);

        this.docId = paramDocId;
        this.dbPath = paramDbPath;
        this.agentName = paramAgentName;

        this.executor = new ThreadSessionExecutor<IStatus>() {
            @Override
            protected IStatus run(Session session) throws NotesException {

                System.out.println("Job started" + docId);
                System.out.println("   >> Session created: "
                        + session.getUserName() + ", Effective User:"
                        + session.getEffectiveUserName());

                    Database db = session.getDatabase(null,dbPath);

                    if (db != null) {
                        try {
                            if (!db.isOpen()) db.open();
                            if (db.isOpen()) {
                                System.out.println("   >> Database opened: "
                                        + db.getTitle());
                                Agent agent = db.getAgent(agentName);
                                try {
                                    System.out.println("   >> Agent Started: " + agent.getName());
                                    agent.run(docId);
                                    System.out.println("   >> Agent Ran: " + agent.getName());
                                } finally {
                                    agent.recycle();
                                }

                            }
                        } finally {
                            db.recycle();                           
                        }

                }
                System.out.println("Job completed");

                return Status.OK_STATUS;
            }
        };

    }

    protected IStatus run(IProgressMonitor monitor) {
        try {
            return executor.run();
        } catch (Exception ex) {
            return Status.CANCEL_STATUS;
        }
    }
};
}

我在按钮(SSJS)上的JobRunner事件中使用了代码(onclick类)

   <xp:button value="Label" id="button4">
    <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="button4">
        <xp:this.action>
            <![CDATA[#{javascript:myPck.JobRunner.start(database.getFilePath(),"(Export)",docTemp.getUniversalID())}]]>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>

返回以下错误

"Error 500 http web server command not handled exception"

可能是什么问题?

2 个答案:

答案 0 :(得分:1)

如果您遇到ClassNotFoundException Eclipse运行时类(在workspace / logs文件夹中),则意味着XPages会阻止您使用这些类来提高安全性。通常,使用java.policy文件授予所有权限应解决此问题。

但是,我在ThreadSessionExecuter类中遇到了针对不同Domino版本的错误和不一致的行为。我还在9.0.1上测试了你的代码,并且在我的测试服务器上也出现了这样的问题。

您可以使用其他方法。您可以参考我的博客文章,其中包含ICONUK 2013演示数据库和幻灯片的链接。

http://lotusnotus.com/lotusnotus_en.nsf/dx/iconuk-2013-slidedeck-demo-application-and-a-surprize....htm

同时从OpenNTF检查XPages Toolkit项目。它提供了一个用于运行后台任务的插件框架。

答案 1 :(得分:-1)

在我的日志中,我有一个“ClassNotFoundException”, 我修改了我的文件java.policy并重启服务器,但错误500继续

C:\ Program Files \ IBM \ Lotus \ Domino \ jvm \ lib \ security

// Notes java code gets all permissions

grant codeBase "file:${notes.binary}/*" {
    permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/rjext/*" {
    permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/ndext/*" {
    permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/xsp/-" {
    permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/osgi/-" {
    permission java.security.AllPermission;
};


// My new line
grant {
   permission java.security.AllPermission;
};