Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1293
  • Last Modified:

How to deploy and access stateful session bean in JBOSS

Using JBOSS: JBOSS4.2.3GA

I have a one stateful and one stateless session bean in my project. Apart from that I have a servlet (deployed as a war) which interacts with both these stateful and stateless session beans. I am able to successfully interact with stateless session from my servlet. But for a stateful session lookup is giving "ClassCastException" when my servlet interact with stateful session bean. Don't know why. Surprisingly when I wrote a standalone java client, it was able to communicate properly with both the session beans. Not sure why I am getting "ClassCastException" when I am trying to contact Stateful session bean only from my servlet.

Questions:
-------------

1) Why JNDI view of the Stateful session bean does not implement its remote interface?
2) I get LoginSession object when I call the method getLoginSession from a standalone java client. Why this fails when I call the same method from a servlet?

Can somebody help me to resolve this problem?
Stateful session bean:
---------------------------
@Stateful(name = "uhomeSession")
@Remote( { LoginSession.class })
public class LoginSessionBean implements LoginSession {
    @PersistenceContext(unitName = "Model")
    .......
}
 
@Remote
public interface LoginSession {
  .....
}
 
JNDI view in JBOSS:
-------------------------
 
and JNDI VIEW is
 +- uhome (class: org.jnp.interfaces.NamingContext)
  |   +- DefaultSessionBean (class: org.jnp.interfaces.NamingContext)
  |   |   +- remote (proxy: $Proxy96 implements interface com.vs.uhome.model.session.DefaultSession,interface org.jboss.ejb3.JBossProxy)
  |   +- uhomeSession (class: org.jnp.interfaces.NamingContext)
  |   |   +- remote (class: java.lang.Object)
  |   |   +- remoteStatefulProxyFactory (proxy: $Proxy65 implements interface org.jboss.ejb3.ProxyFactory)
 
Doing lookup for LoginSession:
------------------------------------
 
public static LoginSession getLoginSession() throws UnknownException, WarningException {
  LoginSession ls;
  Context ctx;
  try {
    ctx = getInitialContext();
  } catch (NamingException ne) {
    throw new Exception (ne);
  }
  try {
    ls = (LoginSession)ctx.lookup("uhome/LoginSessionBean/remote");
    return ls;
  } catch (NamingException ne) {
    throw new Exception (ne);
  }
}
 
ClassCastException while doing lookup:
------------------------------------------------
 
java.lang.ClassCastException: $Proxy96 cannot be cast to com.vs.uhome.model.session.LoginSession
com.vs.uhome.model.util.PropertyUtil.getLoginSession(PropertyUtil.java:239)
com.vs.uhome.view.serv.mainServ.onLogin(mainServ.java:101)
com.vs.uhome.view.serv.mainServ.doPost(mainServ.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
 
 
 
application.xml:
------------------
 
<!DOCTYPE application PUBLIC "-//Sun Microsystems,
Inc.//DTD J2EE Application 1.2//EN"
"http://java.sun.com/j2ee/dtds/application_1_2.dtd">
<application>
    <display-name>Uhome Application</display-name>
    <module>
        <web>
            <web-uri>ViewController.war</web-uri>
            <context-root>/ViewController</context-root>
        </web>
    </module>
    <module>
        <ejb>Model.jar</ejb>
    </module>
</application>

Open in new window

0
svgkraju
Asked:
svgkraju
  • 2
1 Solution
 
svgkrajuAuthor Commented:
Is there anybody who can answer my question?
0
 
ramazanyichCommented:
Strange enough because classcast exception showing that it tries to give you a proxy for defaultsessionbean
Could you also post a code for you defaultsessionbean ?
0
 
svgkrajuAuthor Commented:
I figured out the problem. While doing the build for ViewController, somehow stateful session classes were part of the war. After removing those classes, lookup is working fine.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now