[jboss-user] [EJB 3.0] - Re: ant failed.

samwan809 do-not-reply at jboss.com
Sun Jul 19 03:45:49 EDT 2009


Hi, I finally got that working.
Now the problem is with my Client.java code.

Here is the errors I am getting:

  | ...
  | Test:
  |     [junit] Testsuite: com.ip6networks.calling_card_registration.test.Client
  |     [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1.497 sec
  |     [junit] 
  |     [junit] ------------- Standard Error -----------------
  |     [junit] javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
  |     [junit]     at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
  |     [junit]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
  | 
  | 

Here is the Client.java source code:

  | package com.ip6networks.calling_card_registration.test;
  | 
  | import junit.framework.*;
  | import  com.ip6networks.calling_card_registration.test.Calculator;
  | import  com.ip6networks.calling_card_registration.test.CalculatorRemote;
  | import  com.ip6networks.calling_card_registration.test.ServiceLocator;
  | 
  | public class Client extends TestCase
  | {
  | 
  |    public void testCalculator() throws Exception
  |    {
  |       Calculator calculator = getSession();
  |       System.out.println("in Client class");
  |       System.out.println("1 + 1 = " + calculator.add(1, 1));
  |       System.out.println("1 - 1 = " + calculator.subtract(1, 1));
  | 
  |    }
  | 
  |       private static Calculator  getSession() throws Exception {
  |              Calculator  mgr = null;
  |              mgr = (Calculator) ServiceLocator.getInstance().getService("Calculator");
  |                 if (mgr == null) {
  |                         //throw new SystemErrorException("Unable to connect to service");
  |                         throw new Exception("Unable to connect to service");
  |                 } else {
  |                         return mgr;
  |                 }
  |         }
  | }
  | 
  | 

Source code for ServiceLocator.java:

  | package com.ip6networks.calling_card_registration.test;
  | 
  |  import javax.naming.Context;
  |  import javax.naming.InitialContext;
  |  import java.util.*;
  |  import org.apache.commons.logging.LogFactory;
  |  import org.apache.commons.logging.Log;
  | 
  | public class ServiceLocator {
  |     private Map<String, java.lang.Object> cache;
  |     private static ServiceLocator ourInstance = new ServiceLocator();
  |     private static final Log logger = LogFactory
  |         .getLog(ServiceLocator.class);
  | 
  |     public static ServiceLocator getInstance() {
  |         return ourInstance;
  |     }
  | 
  |     private ServiceLocator() {
  |         this.cache = Collections.synchronizedMap(
  |                 new HashMap<String, java.lang.Object>());
  |     }
  | 
  |     public java.lang.Object getService(String serviceName) {
  |         String serviceHost = "192.168.1.242";
  |         if (this.cache.containsKey(serviceName)) {
  |             return this.cache.get(serviceName);
  |         }
  | 
  |             try {
  |                 java.lang.Object service = this.getContext(
  |                         serviceHost).lookup(
  |                                 serviceName + "Bean/remote");
  |                 cache.put(serviceName, service);
  |                 return service;
  |             } catch (Exception e) {
  |                 e.printStackTrace();
  |                 logger.error("Unable to bind to service "
  |                                    + serviceName + ". Hostname: " + serviceHost, e);
  |                 return null;
  |             } catch (Throwable e) {
  |                 e.printStackTrace();
  |                 logger.error("Unable to bind to service "
  |                                    + serviceName + ". Hostname: " + serviceHost, e);
  |                 return null;
  |             }
  | 
  |     }
  | 
  |     public java.lang.Object getService(String serviceName, String serviceHost) {
  |         String key = serviceHost + "." + serviceName;
  |         if (this.cache.containsKey(key)) {
  |             return this.cache.get(key);
  |         } else {
  |             try {
  |                 java.lang.Object service = this.getContext(
  |                         serviceHost).lookup(
  |                                 serviceName + "Bean/remote");
  |                 cache.put(key, service);
  |                 return service;
  |             } catch (Exception e) {
  |                 logger.error("Unable to bind to service "
  |                                    + serviceName + ". Hostname: " + serviceHost);
  |                 return null;
  |             }
  |         }
  |     }
  | 
  |     private Context getContext(String serviceHost) throws javax.naming.NamingException
  |     {
  |         Properties properties = new Properties();
  |         properties.put(Context.INITIAL_CONTEXT_FACTORY,
  |                        "org.jnp.interfaces.NamingContextFactory");
  |         properties.put(Context.URL_PKG_PREFIXES,
  |                        "org.jboss.naming:org.jnp.interfaces");
  |         properties.put(Context.PROVIDER_URL, serviceHost + ":1099");
  |         return new InitialContext(properties);
  |     }
  | }
  | 
  | 
If I run this code in the jboss environment (that is /usr/java-source/ejb3-tutorial/source/stateless), it runs well.

Thanks
Sam

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244500#4244500

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244500



More information about the jboss-user mailing list