Marjorie Fiallos

Marjorie Fiallos

  • 2k
  • 10
  • 1.7k

how to call a method of another class (TimerSessionBean)

Sep 27 2017 4:27 PM
I am trying to call a method from another class from a session timer bean but I get error so far I have made this part of the code
 Please, Can anybody help me.
package com.eg.dat.example.web.timer;
import com.eg.dat.Data.ejb.entity.EjData;
import com.eg.dat.Data.ejb.service.DataService;
import com.eg.dat.Data.web.data.listApproved;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
@Singleton
@LocalBean
@Startup
public class ExampleAvisoTimer {
private static final Logger LOG = Logger.getLogger(ExampleAvisoTimer.class.getName());
@Inject
private ListApproved listApproved;
@EJB
private ParameterService parameterService;
@EJB
private DataService dataService;
@Resource
TimerService timerService;
int veces = 1;
@PostConstruct
private void init() {
timerService.createCalendarTimer(
new ScheduleExpression().
hour(10).
minute(20).
second(00), new TimerConfig("ExampleTimer", false));
}
@Timeout
public void timeout(javax.ejb.Timer timer) {
if (veces == 1) {
try {
Date fecha= new Date();
Calendar calendar =Calendar.getInstance(); 
calendar.add(Calendar.DATE, -2); 
fecha=calendar.getTime();
for (EjDatos data : this.dataService.listData(fecha,"AD",6)) {
 
//method other class

listAproved.generateReportAutomatic(data);
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Can not generate", e);
}
veces++;
}
}
-------------------------------------------------------------------------------------------------------------------
 
@Named(value = "listAproved")
@ViewScoped
public class listAproved implements Serializable {
/**
* Constante LOG.
*/
private static final Logger LOG = Logger.getLogger(listAproved.class.getName());
private static final long serialVersionUID = -5160910464446901605L;
public void generateReportAutomatic(EjDatos data) throws IOException {
if ( != null) {
JRFileVirtualizer virtualizer = new JRFileVirtualizer(10, JasperReportUtil.PATH_TMP);
Map<String, Object> prm = new HashMap<>();
DateFormat datehourFormat = new SimpleDateFormat("dd/MM/yyyy");
prm.put("content", MessageFormat.format(
FacesUtil.getResourceBundle().getString("content"),
data.getNumber(), data.getId().getName(), data.getId().getName(), datehourFormat.format(data.getDateCr())));
prm.put("article", MessageFormat.format(
FacesUtil.getResourceBundle().getString("article"),
data.getRazonSocial(), data.getId().getName(), data.getId().getName()));
prm.put("article2", MessageFormat.format(
FacesUtil.getResourceBundle().getString("article2"),
data.getNumber()));
prm.put("article3", MessageFormat.format(
FacesUtil.getResourceBundle().getString("article3"), ""));
prm.put("paragraph", MessageFormat.format(
FacesUtil.getResourceBundle().getString("paragraph"), ""));
prm.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
JasperReportUtil jru = new JasperReportUtil();
try {
jru.generarReporteBD(JasperReportUtil.PATH_REPORT,
JasperReportUtil.TIPO_PDF, "report"+data.getdatasId(), prm);
} catch (ClassNotFoundException e) {
LOG.log(Level.SEVERE, "Cant create report.", e);
FacesUtil.mensajeError("Cant create report.");
}
} else {
LOG.log(Level.SEVERE, "Cant create report.");
FacesUtil.mensajeError("Cant create report.");
}
}
 
 
 
the error:
 
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.faces.view.ViewScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:708)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
at ec.gob.mdt.reglamentosInternos.web.tramite.ListaTramitesRIAprobacionFrm$Proxy$_$$_WeldClientProxy.generarActaAutomatica(Unknown Source)
at ec.gob.mdt.reglamentosInternos.web.timer.RIAvisoTimer.timeout(RIAvisoTimer.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:4051)
at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1199)
at com.sun.ejb.containers.EJBTimerService.access$000(EJBTimerService.java:89)
at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1919)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Answers (1)