Why is there only one stateful session bean? - jboss

I tried following example for a stateful session bean http://www.roseindia.net/ejb/example-of-statelfulbean.shtml, but when I use two browsers I only get the same session bean.
I thought there is a session bean for each connection/client. What is wrong?
I use the JBoss 5.0.1 AS for testing and deploying.
Thanks for any advices.

The problem was that I got the session bean in the servlet once, but I have to get it for each session and store it in the session data.

Related

No EJB receiver available for handling after some time

I am using Jboss 7.1 Final. I have setup remote ejb using jboss-ejb-client.properties and standalone.xml accordingly. But after the server running for sometime it will throw this exception while trying to lookup the remote ejb. Is there anything I need to set in the jboss-ejb-client.properties in order for it to work. Note that I already defined the HEARTBEAT_INTERVAL, is that not enough?
Here is the properties file:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connections=default
remote.connection.default.host=222.222.23.222
remote.connection.default.port=4447
remote.connection.default.username=us
remote.connection.default.password=ps
remote.connection.default.connect.options.org.jboss.remoting3.RemotingOptions.HEARTBEAT_INTERVAL=60000
Since no takers to this question, I found some possible solutions by googling. It might be that I have been opening too many connections by calling new InitialContext() -- I might be calling it every few minutes!!! See this link:
https://developer.jboss.org/thread/222883
In there someone mentioned GC and the connection closing etc. That might be helpful.
How do you lookup to your EJB from your EJB Client ? Incase you are using java:/ namespace the problem will happen.
Please use ejb:/ namespace to eliminate the problem.

Are No Interface View (#LocalBean) EJB beans initialized at server startup

I am using Glassfish server. It seems that the #LocalBean is getting initialized at server startup. For other beans they are correctly initialized on look up. Is this the correct behaviour for LocalBean ?
There is no rule saying that #LocalBean should be eagerly initialized and others should not. It's left to the container provider to decide when particular bean should be initialized.
The only case you have control over when bean is initialized is to use #Singleton EJB with #Startup annotation. This will force container provider to create an instance of the singleton bean during server startup. This is a good place to put your initialization logic within.
The behavior you've observed might be correct in case of Glassfish but I would not relay on it because other container providers might choose different approach.

A system exception occurred during an invocation on EJB AuthenticationRequestFilter method public com.sun.jersey.spi.container.ContainerRequest

I am Using RESTful APIs in my application using Jersey 1.6.
Some database is also there.
I have created two .war files in my application. These are deployed on Glassfish server3.0.1 with no issues.(no errors/exceptions).
They make some REST calls to each other for transactions.(It has a proper xml format to send a transaction).
When I try to make a transaction it gives me exceptions like
A system exception occurred during an invocation on EJB AuthenticationRequestFilter method public com.sun.jersey.spi.container.ContainerRequest com.mypack1.mypack2.resources.filters.AuthenticationRequestFilter.filter(com.sun.jersey.spi.container.ContainerRequest)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
and at the end it says
[#|2011-04-26T12:06:32.356+0530|WARNING|glassfish3.0.1|org.apache.http.impl.client.DefaultHttpClient|_ThreadID=27;_ThreadName=Thread-1;|Authentication error: Unable to respond to any of these challenges: {}|#]
I am sure that the xml I send is correct according to database entries.(including authentication for the particular URL).
Is there anything like "container security". Whats may go wrong in this case.
Thanks in advance.

session time-out jax-rs

Does it make sense do define session-timeout with restful web services like jax-rs? For what I know the rest is stateless (or should be stateless) so what the point of storing a session?
If I don't define the session-timeout in the configuration file web.xml for how long session will be stored in servlet container?
Basically REST should be stateless and you should not create a session for the rest calls.
If you don't specify the session timeout, it uses the default one specified by the container. In tomcat the default is 30 minutes.

injected #EJB reference is null after redeployment

I have two ear applications (EJB 3.0) deployed on Jboss 5.1. SLSB from application A calls remote SLSB from application B via #EJB annotation.
Everything works fine, until I redeploy application B. Then the bean from A application tries to call the one from B and its reference turns to be null.
I suppose that SLSBs are pooled and references are injected on creation time, and after redeployment those proxies are not refreshed somehow.
How can I cope with that? Is it ok to put an interceptor on that bean and check if all annotated references are not null?
If the application is redeployed/undeployed or there is network failure, the proxy objects are invalidated.
You can use ServiceLocator pattern for caching the references of the remote objects. You can remove & again re-create them with JNDI lookup in case of failure.
Else, instead of using #EJB to inject remote bean, you have to manually lookup each time which is resource consuming, but former is much better approach.