Hi...
I have something very strange happening.
In an enterprise application that contains an ejb module and a war
module (JSF), a managed bean calls a business method from the ejb
module. However, the returned object is always null.
When I put some printout statements inside the managed bean method and
the session bean business method, I get that in the session bean, the
object being returned is not null. But the object assigned in the
managed bean is null.
This seems like a bug, or am I doing something wrong?
Here are the classes...
Session Bean (with its local interface):
@Local
public interface AdvertisingLocal {
public byte[] getAdvertising();
}
@Stateless
public class AdvertisingBean
implements AdvertisingLocal {
private static final long HOUR = 3600000L;
private static Object lock = new Object();
@Resource
private TimerService timerService;
@Resource(name="timer-interval")
private int interval;
private Timer timer;
@EJB
private AdsFacadeLocal adsFacade;
private Iterator<Ads> iterator;
public AdvertisingBean() {
}
@PostConstruct
private void construct() {
int count = 0;
List<Ads> results = adsFacade.findAll();
for (Ads ad : results)
count += ad.getTokens();
List<Ads> rotation = new ArrayList<Ads>(count);
for (Ads ad : results)
for (int i = 0 ; i < ad.getTokens() ; i++)
rotation.add(ad);
synchronized (lock) {
iterator = rotation.iterator();
}
}
@PreDestroy
private void destroy() {
if (timer != null)
timer.cancel();
}
@Timeout
private void timeout(Timer timer) {
construct();
}
@AroundInvoke
private void createTimer(InvocationContext context) {
try {
if (timer == null) {
// set expire for the next hour turn
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis() +
HOUR);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
timer = timerService.createTimer(calendar.getTime(),
interval, null);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
context.proceed();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public byte[] getAdvertising() {
synchronized (lock) {
if (!iterator.hasNext())
construct();
byte[] buffer = iterator.hasNext()
? iterator.next().getContent()
: "Advertising...".getBytes();
System.out.println("buffer: " + buffer);
return buffer;
}
}
}
Here the "buffer" printout is NOT null.
Managed Bean:
public class AdvertisingBean {
@EJB
private AdvertisingLocal advertisingService;
public AdvertisingBean() {
}
public String getContent() {
System.out.println("service: " + advertisingService);
System.out.println("content: " +
advertisingService.getAdvertising());
return String.valueOf(advertisingService.getAdvertising());
}
}
Here "service" is NOT null, and "content" IS null.
Any help is greatly appreciated.
I'm using glassfish version Sun Java System Application Server 9.1.1
(build b24c-fcs). This is from the admin GUI.
thanks,
Daniel.