Discussions

EJB programming & troubleshooting: how to access deployed beans form remote machines?

  1. how to access deployed beans form remote machines? (2 messages)

    We know that when a test client is located on the same machine as the deployed beans,it can access the beans like this:(take the bean's name as Hello)
       Context context = getInitialContext();
          //look up jndi name
          Object ref = context.lookup("Hello");
          //look up jndi name and cast to Home interface
          helloHome = (HelloHome) PortableRemoteObject.narrow(ref, HelloHome.class);

    Specifically,when we get the IitialContext,the code may be:
    private Context getInitialContext() throws Exception {
        String url = "t3://localhost:7001";
        String user = null;
        String password = null;
        Properties properties = null;
          properties = new Properties();
          properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          properties.put(Context.PROVIDER_URL, url);
          if (user != null) {
            properties.put(Context.SECURITY_PRINCIPAL, user);
            properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
             return new InitialContext(properties);
       }

    So the question is:if I want to access the Hello bean from a remote machine,how will the client code look like?I tried to modify the PROVIDER_URL as :
    String url="http://EJB server address:7001",but it turned to be a failure.What shoud I do?What's the meaning for "t3"?
  2. We know that when a test client is located on the same machine as the deployed beans,it can access the beans like this:(take the bean's name as Hello)

    > Context context = getInitialContext();
    > //look up jndi name
    > Object ref = context.lookup("Hello");
    > //look up jndi name and cast to Home interface
    > helloHome = (HelloHome) PortableRemoteObject.narrow(ref, HelloHome.class);
    >
    > Specifically,when we get the IitialContext,the code may be:
    > private Context getInitialContext() throws Exception {
    > String url = "t3://localhost:7001";
    > String user = null;
    > String password = null;
    > Properties properties = null;
    > properties = new Properties();
    > properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    > properties.put(Context.PROVIDER_URL, url);
    > if (user != null) {
    > properties.put(Context.SECURITY_PRINCIPAL, user);
    > properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
    > return new InitialContext(properties);
    > }
    >
    > So the question is:if I want to access the Hello bean from a remote machine,how will the client code look like?I tried to modify the PROVIDER_URL as :
    > String url="http://EJB server address:7001",but it turned to be a failure.What shoud I do?What's the meaning for "t3"?

    use the t3://ejb_server:7001 as the url string in the remote client ,as the t3 is the protocol of the server so an http will fail
  3. Also, I'm sure weblogic has some kind of client.jar with the neccessary classes.