Java 如何在nuxeo IDE中创建事件侦听器

Java 如何在nuxeo IDE中创建事件侦听器,java,event-listener,nuxeo,Java,Event Listener,Nuxeo,我想在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

我想在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>
/**
 * 
 */

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
错误是:

<?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>
/**
 * 
 */

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中创建侦听器扩展点。我将其创建为文档侦听器。如何解决错误?

创建的用户\ueventId由Nuxeo平台在文档上下文中内部使用

因此,不能使用没有文档上下文的计划程序触发此相同事件

如果您想让您的示例正常工作,只需将创建的用户重命名为创建的我的用户或其他名称

最好的方法是,Nuxeo平台在文档上下文中内部使用创建的用户
eventId

因此,不能使用没有文档上下文的计划程序触发此相同事件

如果您想让您的示例正常工作,只需将创建的用户重命名为创建的我的用户或其他名称


最好,

您好,我试过了,但遇到了同样的错误,您能帮我解决这个错误吗?您好,我亲自测试了您的样品,它对我很好。您的cronExpression(0 1***?)表示每小时的第一分钟,例如16h01、17h01、18h01等,它与您的日志(2016-06-02 12:13:01047)的时间戳不匹配,这使我认为堆栈与您的计划程序无关,而是其他内容。您好,非常感谢。。我的nuxeo未配置..现在已配置完毕,因此此错误不会持续..但我无法获得任何输出..如果您将计划程序创建为nuxeo组件,将侦听器创建为文档侦听器,请向我提供信息。。您是否在eclipse窗口上看到了输出?谢谢你的帮助。嗨,我试过了,但是遇到了同样的错误,你能帮我解决这个错误吗?嗨,我亲自测试了你的样品,它对我很好。您的cronExpression(0 1***?)表示每小时的第一分钟,例如16h01、17h01、18h01等,它与您的日志(2016-06-02 12:13:01047)的时间戳不匹配,这使我认为堆栈与您的计划程序无关,而是其他内容。您好,非常感谢。。我的nuxeo未配置..现在已配置完毕,因此此错误不会持续..但我无法获得任何输出..如果您将计划程序创建为nuxeo组件,将侦听器创建为文档侦听器,请向我提供信息。。您是否在eclipse窗口上看到了输出?谢谢你的帮助