Ajay thakur
Ajay thakur

Reputation: 13

How to get remoteHost name from EJB java application which is deployed in weblogic

Below is the example. We have an application which is deployed in Oracle Weblogic Server. And We have client who use our application by creating connection using weblogic context like below.

  env.put(Context.INITIAL_CONTEXT_FACTORY,
          "weblogic.jndi.WLInitialContextFactory");
  env.put(Context.PROVIDER_URL,
          "t3://weblogicServer:7001");
  Context ctx = new InitialContext(env);```
** Now When they make this connection we want to get their hostname in our application.
Is there any way to achieve this. **

Upvotes: 0

Views: 207

Answers (1)

Emmanuel Collin
Emmanuel Collin

Reputation: 2606

WebLogic Server has a propagation API that enables to send data from client to EJBs or web services hosted in WebLogic Server.
Read this documentation first.
Code sample used to send an information from a T3 client to an EJB hosted in WebLogic Server.
Client side :

public static void main(String[] args) {

    System.out.println("\n\n\t Hello ...");
    try{
            Properties pr=new Properties();
            pr.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
            pr.put(Context.PROVIDER_URL,"t3://localhost:8001");

            InitialContext ic=new InitialContext(pr);
            
            WorkContextMap map = WorkContextHelper.getWorkContextHelper().getWorkContextMap();
            if (null == map) return;
            
            WorkContext serializedCustomContext = PrimitiveContextFactory.create("test envoi context");
            map.put("mycontext",serializedCustomContext, PropagationMode.RMI);
            
            WorkContextTestRemote remote=(WorkContextTestRemote)ic.lookup("WorkContextTestMappedName#ejbs.WorkContextTestRemote");
            remote.sayHello();
    }
    catch(Exception e){ e.printStackTrace(); }

}

EJB Side :

public void sayHello() {
    System.out.println("\nHello !");
    
    WorkContextMap map = WorkContextHelper.getWorkContextHelper().getWorkContextMap();
    
    WorkContext customContext = (WorkContext)map.get("mycontext");
    StringWorkContext sc = (StringWorkContext)customContext;
    Object s = sc.get();
    System.out.println("context : "+s);
}   

Upvotes: 0

Related Questions