java using rmi with ejb3 to talk to remote server

Posted on 2009-02-11
Medium Priority
Last Modified: 2013-11-24

Im trying to make a call to a remote server using rmi and ejb.My service locator is recieving a null value.

The interfaces are registered in the servers JNDI and i seem to be connecting(if i change the ip i get a timeout error instead)

The registered interfaces are contained within a jar in the deploy directory of jboss.

Below is my code and the out - can anybody see an obvious error, or have any suggestions about what to look for?

thanks in advance
public static void main(String args[]){
		BD bd = new BD();
public class BD {
	private SBRemote rmi;
	  // Default Constructor. Looks up home and connects
	  // to session by creating a new one
	  public BD() throws ResourceException {
	    try {
	    	rmi = (SBRemote)ServiceLocator.getLocator().getService(SBRemote.RemoteJNDIName);			
	    } catch(ServiceLocatorException ex) {
	      // Translate Service Locator exception into
	      // application exception
	      throw new ResourceException("Unable to locate the remote service: " + ex);
	  public InterfaceOutput getPrices(InterfaceInput input){
			  System.out.println("RMI is not null" + rmi.getClass());
			  return rmi.getPs(input);
			  System.out.println("RMI is null");
		  return null;
public class ServiceLocator {
	private static ServiceLocator serviceLocator = new ServiceLocator();
	private Hashtable homeCache;
	private InitialContext defaultContext;
	private ServiceLocator() {
		try {
			Properties properties = new Properties();
			properties.put(Context.PROVIDER_URL, "jnp://xxx.xx.xx.xx:1099");
			// initialize context			
			defaultContext = new InitialContext(properties);			
			homeCache = new Hashtable();
		} catch (Exception ex) {
					.println("Exception in the constructor of ServiceLocator "
							+ "class : " + ex.toString());
	public static ServiceLocator getLocator() {
		return serviceLocator;
	public Object getService(String jndiName) throws ServiceLocatorException {
		try {
			if (!homeCache.containsKey(jndiName)) {
				homeCache.put(jndiName, defaultContext.lookup(jndiName));
		} catch (NamingException ex) {
			throw new ServiceLocatorException(
					"Exception thrown from getService "
							+ "method of ServiceLocator class : "
							+ ex.getMessage());
		} catch (SecurityException ex) {
			throw new ServiceLocatorException(
					"Exception thrown from from getService "
							+ "method of ServiceLocator class : "
							+ ex.getMessage());
		return homeCache.get(jndiName);
import javax.ejb.Remote;
import InterfaceInput;
import InterfaceOutput;
public interface SBRemote {
	   public InterfaceOutput getPrices(InterfaceInput input);
	   //public static final String RemoteJNDIName = "sessionbean.stateless.interfaces.SBRemote";
	   public static final String RemoteJNDIName = "engine/SB/remote";

Open in new window

Question by:alzzz

Author Comment

ID: 23612378
seems im getting an unknown host exception -  java.rmi.UnknownHostException: Unknown host: xxxxx

where 'xxxxx' is the server name of the ip address i called
LVL 10

Accepted Solution

Nellios earned 2000 total points
ID: 23632592
I can't see an obvious error. The code seems to be correct.
Things you could try:
a) Pass directly the IP and see if you can establish connection. If this works then your jvm cannot perform correctly the dns lookup.
b) Try to lookup the ejb directly without a the use of the service locator pattern. I don't think that will do much difference but it will allow you to test a simplified version of your source.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question