I have created a helloworld app in EJB 3.0 with Jboss 5. When i try to run my client class EjbClientApplication, it throws an exception.
Frequently I am getting below exception. I have done a lot of rnd about it but I couldn't found it as I am new to EJB please help.
Exception:
javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.hex.client.EjbClientApplication.main(EjbClientApplication.java:28) Caused by: javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734) ... 4 more Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305) ... 5 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:97) at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:82) at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301) ... 5 more
Jboss server is up with port 127.0.0.1:10001 but I trying to hit this url 127.0.0.1:1099 is this ryt?
Server Properties:
- Address:127.0.0.1
- port:8080
- JNDI port:1099
MyCode: These code comprises in a single EJB project
RemoteInterfaceClass:
package com.hex.statelessbean;
import javax.ejb.Remote;
@Remote
public interface StatelessSessionBeanRemote {
public String displayMessage();
}
StatelessBean:
/**
* Session Bean implementation class StatelessSessionBean
*/
package com.hex.statelessbean;
import javax.ejb.Stateless;
@Stateless
public class StatelessSessionBean implements StatelessSessionBeanRemote {
/**
* Default constructor.
*/
public StatelessSessionBean() {
// TODO Auto-generated constructor stub
}
@Override
public String displayMessage() {
// TODO Auto-generated method stub
return "Hello world";
}
}
Client:
package com.hex.client;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.hex.statelessbean.StatelessSessionBeanRemote;
public class EjbClientApplication {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx
.lookup("StatelessSessionBean/remote");
System.out.println("Message from Bean :" + bean.displayMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}