我想在nuxeo IDE中安排一个事件,但出现错误java.lang.ClassCastException:
org.nuxeo.ecm.core.event.impl.EventContextImpl无法转换为
org.nuxeo.ecm.core.event.impl.DocumentEventContext。
我的调度程序贡献是:
<?xml version="1.0"?>
<component name="org.nuxeo.sample.ScheduleCall" version="1.0">
<extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
point="schedule">
<schedule id="testschedule">
<username>Administrator</username>
<eventId>user_created</eventId>
<eventCategory>default</eventCategory>
<cronExpression>0 1 * * * ?</cronExpression>
</schedule>
</extension>
</component>
我的听众的贡献是:
<component name="org.nuxeo.sample.listener.contrib.ScheduleListener">
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
point="listener">
<listener name="schedulelistener" async="false" postCommit="true"
class="org.nuxeo.sample.ScheduleListener" priority="140">
<event>user_created</event>
</listener>
</extension>
</component>
我的侦听器的Java类是:
/**
*
*/
package org.nuxeo.sample;
import org.nuxeo.ecm.core.event.EventListener;
import org.nuxeo.ecm.core.event.Event;
/**
* @author Parul.Puri01
*/
public class ScheduleListener implements EventListener {
public void handleEvent(Event event){
try{
if(event!=null && event.getName().equals("user_created")){
System.out.println("parul");
}
System.out.println("not an event");
}
catch (Exception e){
e.printStackTrace();
}
}
}
错误是:
java.lang.ClassCastException: org.nuxeo.ecm.core.event.impl.EventContextImpl cannot be cast to org.nuxeo.ecm.core.event.impl.DocumentEventContext
at org.nuxeo.ecm.user.center.profile.localeProvider.UserLocaleSelectorListener.handleEvent(UserLocaleSelectorListener.java:43)
at org.nuxeo.ecm.core.event.impl.EventServiceImpl.fireEvent(EventServiceImpl.java:200)
at org.nuxeo.ecm.core.scheduler.EventJob.execute(EventJob.java:119)
at org.nuxeo.ecm.core.scheduler.EventJob.execute(EventJob.java:65)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
2016-06-02 12:13:01,047 WARN [Nuxeo-Work-default-3] [org.nuxeo.ecm.platform.ec.notification.NotificationEventListener] Can not handle notification on a event that is not bound to a DocumentEventContext
请让我知道如何在nuxeo IDE中创建侦听器扩展点。我将其创建为文档侦听器。如何解决错误?
最佳答案
user_created eventId由Nuxeo平台在Document上下文内部使用。
因此,您不能使用没有文档上下文的调度程序来触发同一事件。
如果要使示例工作,只需将user_created重命名为my_user_created或其他名称即可。
最好,