I have the following situation: Request-scoped JAX-RS service invokes stateless EJB3 bean and the EJB3 bean retains state between successive invocation of the web service from a client.
Code as follows:
web service
@javax.enterprise.context.RequestScoped
@Path("/actions")
public class CounterFrontEnd {
@EJB
private ICounterService.ILocal counterService;
@GET @Produces("application/text;") @Path("/counter")
public String counter() {
return String.format("%d ", counterService.incCounter());
}
stateless EJB3 bean
@Stateless
@Local (ICounterService.ILocal.class)
@Remote(ICounterService.IRemote.class)
public class CounterService implements ICounterService.ILocal, ICounterService.IRemote {
public int counter = 0;
@Override
public int incCounter() {
return counter++;
}
I then invoke the service with the following python script:
for i in range(100):
os.system( 'curl http://somewhere:8080/counter-ws/rest/actions/counter' )
Surprisingly, the output is:
1 2 3 4 5 ...