[EJB 3.0] - $Proxy146 cannot be cast to servlet... Access ejb bean from
by int2
Hi,
Thank you for read my post,
I'm new to ejb 3.0, there's a problem when I try to access an example session bean from servlet. Anyone please help :-)
The code of the test session bean is:
BLocal.java
| import ...;
| @Local
| public interface BLocal{
| public String Say(String s);
| }
|
BBean.java
| import ...
|
| @Stateless
| public class BBean implement BLocal{
| String Say(String s){
| return "hello " + s;
| }
| }
|
And the servlet,
| Context ctx = new InitialContext();
| BLocal b = (BLocal)ctx.lookup("BBean/local");
| out.println(b.Say(" world"));
|
For the class Blocal in servlet, I just copy it from the session bean above (remove annotation)
When I run the servlet, I get the result:
| ype Exception report
|
| message
|
| description The server encountered an internal error () that prevented it from fulfilling this request.
|
| exception
|
| java.lang.ClassCastException: $Proxy146 cannot be cast to servlet.Bean1Local
| servlet.S.processRequest(S.java:49)
| servlet.S.doGet(S.java:70)
| javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
| javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
| org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
|
| note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
|
If the servlet and the session bean is inside an EAR, the servlet worked fine. But if the two project (servelet, session bean) deploy separately then I got the error above.
Anyone can help ?
Thank you a lot and regards
Lee
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043066#4043066
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043066
18 years, 12 months
[Management, JMX/JBoss] - Programatically creating XMBean Instance
by toddjtidwell
I've developed an XMBean that works fine when deployed through a jboss-service.xml. However, I've come to a point where I would like to deploy multiple instances of this XMBean programatically.
In the past, with a standard MBean, you'd do something like this:
| ArrayList serverList = MBeanServerFactory.findMBeanServer(null);
|
| MBeanServer server = (MBeanServer) serverList.get(0);
|
| ObjectName on=new ObjectName("my.domain:service=Test");
|
| ObjectInstance mbean = server.createMBean(MyMBean.class.getName(), on);
|
Sadly, with an XMBean the following Exception is thrown:
| javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object
|
Obviously this is because I haven't tied it to the XML descriptor. Is there a way to programatically do this?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043063#4043063
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043063
18 years, 12 months
[JNDI/Naming/Network] - lookup database source weird problem
by joshuayeo
Hi all ,
I am using jdk 1.6.0_01 and jboss 4.0.5.GA.
I have setup jndi lookup in my startup servlet init() method , however it did not lookup the jndi database name at all.
It always give me error message cannot lookup the jndi name.
Anyone have any ideas what is happening here ? Thanks
Below is the startup servlet for my webapps:
public class AdminStartupServlet extends HttpServlet {
protected Logger logger = LoggerManager.getLogger();
public void init(ServletConfig config) throws ServletException {
super.init(config);
DatabaseAction databaseAction = ActionManager.getDatabaseAction();
try{
databaseAction.process();
} catch(NamingException ne){
ne.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
}
}
This is DatabaseAction :
public class DatabaseAction {
protected DatabaseAction() {
}
public void process() throws Exception
{
try {
OracleDatabaseManager.config();
} catch(Exception ex) {
throw new Exception("Fail to config ORACLE database connection.", ex);
}
}
}
This is the Database Manager to lookup database jndi name
public class OracleDatabaseManager {
protected static DataSource oracleDS;
public static synchronized void config() throws Exception {
try{
InitialContext initialContext = new InitialContext();
oracleDS = (javax.sql.DataSource) initialContext.lookup("jdbc/OracleDS");
}catch(Exception ex){
ex.printStackTrace();
}
}
public static Connection getOracleConnection() throws Exception {
try {
//InitialContext initialContext = new InitialContext();
//oracleDS = (javax.sql.DataSource) //initialContext.lookup("jdbc/OracleDS");
return oracleDS.getConnection();
} catch (Exception ex) {
throw new Exception(ex);
}
}
}
web.xml resource-ref tag
<resource-ref>
Oracle DB Connection
<res-ref-name>jdbc/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jboss-web.xml tag
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
jboss.jca:service=LocalTxCM,name=jdbc/OracleDS
<context-root>/</context->
<resource-ref>
<res-ref-name>jdbc/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>jdbc/OracleDS</jndi-name>
</resource-ref>
</jboss-web>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043062#4043062
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043062
18 years, 12 months