java using rmi with ejb3 to talk to remote server

Posted on 2009-02-11
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

    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

    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

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
    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.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now