troubleshooting Question

Specifiying port and host when using dependency injection?

Avatar of endasil
endasil asked on
JavaJava EE
2 Comments1 Solution603 ViewsLast Modified:
I need to communicate with a ejb on another machine from my standalone client and need a way of doing this without using lookup. Dependency injection was suggested to me as an alternative. A problem with this is that i need the communication to go trough another computer that will proccess some of the data before sending it on to the machine with glassfish and my ejb.

With lookup and initial context i could specify properties for the communication like in code attachment 1. But using dependency injection, i can't see a way of specifying any such properties. If it is possible, how would i do it? Is there any other way i can do this?

// Doing it with initial context and lookup.

public class Main {

    public static void main(String[] args) 
    {
        ProgrammaticLogin pm = new ProgrammaticLogin();        
        pm.login(user, "dummy"); 

        env.put("java.naming.factory.initial",  "com.sun.enterprise.naming.SerialInitContextFactory");
        env.put("java.naming.factory.url.pkgs",    "com.sun.enterprise.naming");
        env.put("java.naming.factory.state",   "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryIm pl");

       env.put("org.omg.CORBA.ORBInitialHost", host);
       env.put("org.omg.CORBA.ORBInitialPort", port);


       ctx = new InitialContext(env);            
       Object ref = ctx.lookup("demo.SB3Remote");     
       SB3Remote calc = (SB3Remote)              PortableRemoteObject.narrow(ref, SB3Remote.class);
javax.swing.JOptionPane.showMessageDialog(null, " " + calc.Hello(user));
}
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros