JNDI远程调用 - Weblogic

时间:2016-11-09 20:50:18

标签: java java-ee weblogic jndi

我正在尝试通过JNDI远程调用访问部署在Weblogic中的应用程序中的某些服务。 这是JNDI远程调用:

    public class 
    {
      private static MyService myService = null;

      public static void main(String[] args)
      {
        try
        {
          final Context context = getInitialContext();
          System.out.println("looking up MyService...");
          myService = (MyService) context
      .lookup("java:global.MyApp-app.Component.MyServiceImp!com.company.app.domain.api.boundary.MyService");

      }
        catch (Exception e)
        {
          System.out.println("error using facade bean...\n");
          e.printStackTrace();
          e.printStackTrace();
        }
        if (myService == null)
        {
          System.out.println("No connection to the service!");
        }
      }

      private static Context getInitialContext() throws NamingException
      {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        env.put(Context.PROVIDER_URL, "t3://localhost:7002");
        env.put(Context.SECURITY_PRINCIPAL, "user");
        env.put(Context.SECURITY_CREDENTIALS, "pass");
        return new InitialContext(env);
      }
    }

有一点需要提及:   - 在weblogic控制台中,当我访问受管服务器然后访问JNDI树结构时,我可以在列表中看到这个&#34; JNDI名称&#34;但是当点击它以查看除BindingName之外的BindingName时,我还会看到以下消息:  **意外异常:无法加载返回类型; class java.lang.Object嵌套异常是:java.lang.ClassNotFoundException:com.company.app.domain.api.boundary.MyService **

当我运行此客户端时,我得到以下异常:

javax.naming.NameNotFoundException: remaining name: java:global.MyApp-app.Component.MyServiceImpl!com.company.app.domain.api.boundary.MyService
at weblogic.j2eeclient.SimpleContext.internalLookup(SimpleContext.java:77)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:39)
at weblogic.jndi.SimpleContext.lookup(SimpleContext.java:86)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at arberkuci.MainClass.main(MainClass.java:27)

由于我这么多天都在挣扎,所以我非常感谢你们! : - )

更新

我将查找方法的参数值更改为=&gt; &#34;的java:全球/ MyApp的应用内/组件/ MyServiceImpl&#34;结果是:

  Exception in thread "main" java.lang.AssertionError: Context may not be null
at weblogic.j2eeclient.SimpleContext.checkForNameUnderRemoteNode(SimpleContext.java:103)
at weblogic.j2eeclient.SimpleContext.internalLookup(SimpleContext.java:68)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:39)
at weblogic.jndi.SimpleContext.lookup(SimpleContext.java:86)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at arberkuci.MainClass.main(MainClass.java:29)

0 个答案:

没有答案