how to client look up ejb object from sybase-EA server4.0

Discussions

EJB design: how to client look up ejb object from sybase-EA server4.0

  1. hi all

    plesae tell me if any one knows the client code to look up an ejb object deployed in sybase-ea4.0 app server.
    (what jndi look up context code)

    thanx
    raghav
  2. Certainly, here ya go. FYI, you may want to check out our public newsgroups at forums.sybase.com where we have very extensive coverage by our engineers as well as our partners.

    Jason Weiss
    Manager, Software Engineering
    eBusiness Systems Group

    import javax.naming.*;
    import java.rmi.*;
    import java.util.*;
    import Calculator.*;

    public class ConsoleClient
    {
      public static Context getInitialContext() throws Exception
      {
         Properties p = new Properties();
    /* change provider_url property accordingly. replace weissj-nt with
    machine name, which can be obtain by jaguar manager-> listener */
    p.put(Context.PROVIDER_URL,"iiop://weissj-nt:9000");
          p.put(Context.INITIAL_CONTEXT_FACTORY,"com.sybase.ejb.InitialContextFactory");
          p.put(Context.SECURITY_PRINCIPAL,"your user id here");
          p.put(Context.SECURITY_CREDENTIALS,"your password here");

         return new InitialContext(p);
      }

      public static void main(String args[])
      {
    Calculate calculate;
    CalculateHome calculateHome;

    try
    {
    Context jndiContext = getInitialContext();
    Object obj = jndiContext.lookup("Currencybean");
    calculateHome = (CalculateHome)javax.rmi.PortableRemoteObject.narrow(obj,CalculateHome.class);
    calculate= calculateHome.create();
    double abc = calculate.calculateCurrency("USD",15.5,"Y");
    System.out.println("Currency value is :" +abc);

    }catch(Exception e)
    {
    System.out.println("exception has occoured" + e.toString());
    e.printStackTrace();

    }

       }
     }