I´m trying to get an application attribute inside the Quartz Job, but I´m getting always a NPE:
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.context.FacesContext;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.support.SubjectThreadState;
import org.apache.shiro.util.ThreadState;
import org.omnifaces.util.Faces;
import org.omnifaces.util.FacesLocal;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ApplicationScoped
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DisallowConcurrentQuartzJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
FacesContext facesContext = FacesContext.getCurrentInstance();
// -> IS NULL
List<Object> customActionTypeClasses = Faces.getApplicationAttribute("TEST");
// -> IS NULL
}
Any ideas why this is not working? I´ve created also a CDI Factory:
@ApplicationScoped
public class SchedulerQuartzServiceBean {
@Inject
private CdiSchedulerJobFactory cdiSchedulerJobFactory;
// Start
public void startSchedule() {
Scheduler scheduler = schedulerFactory.getScheduler(defaultSchedulerName);
scheduler.setJobFactory(cdiSchedulerJobFactory);
}
}
@ApplicationScoped
public class CdiSchedulerJobFactory implements JobFactory {
@Inject
private BeanManager beanManager;
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
Class<? extends Job> jobClass = bundle.getJobDetail().getJobClass();
Set<Bean<?>> beans = beanManager.getBeans(jobClass);
if (beans.isEmpty()) {
throw new SchedulerException("No job instance found for job class: " + jobClass.getName());
}
Bean<?> bean = beanManager.getBeans(jobClass).iterator().next();
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
return (Job) beanManager.getReference(bean, jobClass, ctx);
}
}
Does anybody have an idea what´s wrong here? The Faces.getApplicationAttribute will throw a NPE because FacesContext is null.