下面是示例。我们有一个部署在Oracle Weblogic Server中的应用程序。我们有客户使用我们的应用程序,他们使用如下的weblogic上下文创建连接。
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. **
WebLogic Server有一个传播API,可以将数据从客户端发送到WebLogic Server中托管的EJB或web服务
请先阅读本文档
用于将信息从T3客户端发送到WebLogicServer中托管的EJB的代码示例
客户端:
public static void main(String[] args) {
System.out.println("nnt 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端:
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);
}