Hi all,i'm trying to implements a simple
EJB application using NetBeans 6.0.1 and
jboss 4.2.2 . This is my code:
package ejb;
import javax.ejb.Stateless;
@Stateless
public class NewSessionBean implements NewSessionRemote {
public void helloWorld() {
System.out.println("HelloWorld");
}
/**********************************************************************/
package ejb;
import javax.ejb.Remote;
@Remote
public interface NewSessionRemote {
void helloWorld();
}
/******************************************************************/
package try_pkg;
import ejb.NewSessionRemote;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
NewSessionRemote nsr;
ServiceLocator(){
nsr= this.lookupNewSessionBean();
}
private NewSessionRemote lookupNewSessionBean() {
try {
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming
rg.jnp.interfaces");
Context ctx = new InitialContext(env);
return (NewSessionRemote) ctx.lookup("NewSessionBean");
} catch (NamingException ne) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
public void helloWorld(){
nsr.helloWorld();
}
}
/***********************************************************************/
package try_pkg;
public class MainClass {
public static void main(
String []args)
{
ServiceLocator sl=new ServiceLocator();
sl.helloWorld();
}
}
/********************************************************************/
And this is my jndi namespace in
http://localhost:8080/jmx-console/HtmlAdaptor +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
+- jmx (class: org.jnp.interfaces.NamingContext)
| +- invoker (class: org.jnp.interfaces.NamingContext)
| | +- RMIAdaptor (proxy: $Proxy47 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
| +- rmi (class: org.jnp.interfaces.NamingContext)
| | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
+- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+- UserTransactionSessionFactory (proxy: $Proxy14 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
+- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)
+- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
+- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
+- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
+- queue (class: org.jnp.interfaces.NamingContext)
| +- A (class: org.jboss.mq.SpyQueue)
| +- testQueue (class: org.jboss.mq.SpyQueue)
| +- ex (class: org.jboss.mq.SpyQueue)
| +- DLQ (class: org.jboss.mq.SpyQueue)
| +- D (class: org.jboss.mq.SpyQueue)
| +- C (class: org.jboss.mq.SpyQueue)
| +- B (class: org.jboss.mq.SpyQueue)
+- topic (class: org.jnp.interfaces.NamingContext)
| +- testDurableTopic (class: org.jboss.mq.SpyTopic)
| +- testTopic (class: org.jboss.mq.SpyTopic)
| +- securedTopic (class: org.jboss.mq.SpyTopic)
+- console (class: org.jnp.interfaces.NamingContext)
| +- PluginManager (proxy: $Proxy48 implements interface org.jboss.console.manager.PluginManagerMBean)
+- NewSessionBean (class: org.jnp.interfaces.NamingContext)
| +- remote (proxy: $Proxy63 implements interface ejb.NewSessionRemote,interface org.jboss.ejb3.JBossProxy)
+- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
+- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
+- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
+- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
+- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
/*************************************************************************/
Depends on the String that i pass to lookup method i have different errors
1)Exception in
thread "main" java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be cast to ejb.NewSessionRemote
2)not bound
i suppose that i have to configure the .xml file of my application....somebody can help me?