WebSphere Liberty 8.0.0.3远程EJB查找失败



WebSphere Liberty 8.0.0.3 EJB查找失败:

我创建了一个具有以下代码的EJB,并在WebSphere Liberty 8.0.0.3。

itestejbremoteinterface.java

package ejb31.test;
import javax.ejb.EJB;
import javax.ejb.Remote;
@Remote
@EJB(name="ejb/checkName")
public interface ITestEJBRemoteInterface
{ 
    public boolean checkNames(String fsName);
}

testejb.java:

package ejb31.test;
import java.util.Arrays;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/** * Session Bean implementation class TestEJB */ 
@Stateless
@EJB(name="ejb/checkName")
public class TestEJB implements ITestEJBRemoteInterface 
{
    List<String> moListOfNames = Arrays.asList("Kevin","Jiten","Martina","Brian"); 
    /** * Default constructor. */
    public TestEJB() 
    { 
    } 
    /** * Find if the passed name is present in the default list of names 
     * 
     * 
     * 
     * @return */ 
    public boolean checkNames(String fsName)
    { 
        boolean lboolNamePresent = false; 
        if(fsName != null) 
        { 
            lboolNamePresent = moListOfNames.contains(fsName); 
        } 
        return lboolNamePresent; 
    }
}

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
 <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> 
 <display-name> TestEJB3.1 </display-name> 
 </ejb-jar>

EJB部署成功,日志文件抛出绑定位置:

java:global/testejb3.1ear/testejb3.1/testejb!ejb31.test.itestejbremoteinterface

问题是在调用EJB时。 webphereclient.java

package com.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class WebSphereClient {
    public static void main(String[] args) {
        String jndiPath = "corbaname:rir:#ejb/global/TestEJB3.1EAR/TestEJB3.1/TestEJB!ejb31.test.ITestEJBRemoteInterface";
        String provider = "corbaname:iiop:localhost:2809";
        Properties jndiLookupProps = new Properties();
        jndiLookupProps.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
         com.ibm.websphere.naming.PROPS.INITIAL_CONTEXT_FACTORY);
        jndiLookupProps.put(javax.naming.Context.PROVIDER_URL, provider);
        try {
            Object found = new InitialContext().lookup(jndiPath);
        } catch (NamingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

它引发了一个错误:javax.naming.invalidnameException:名称组件" testejb!ejb31.test.itestejbremoteinterface"违反了ins name语法。有一个以上的Unexaper ID/类型分离器("。")。

当我尝试逃脱jndipath时:

jndiPath = "corbaname:rir:#ejb/global/TestEJB3%5c.1EAR/TestEJB3%5c.1/TestEJB!ejb31%5c.test%5c.ITestEJBRemoteInterface";

jndiPath = "corbaname:rir:#ejb/global/TestEJB3.1EAR/TestEJB3.1/TestEJB!ejb31.test.ITestEJBRemoteInterface";

jndiPath = "corbaname:rir:#ejb/global/TestEJB3\.1EAR/TestEJB3\.1/TestEJB!ejb31\.test\.ITestEJBRemoteInterface";

它给出了相同的错误。如何使用远程客户端正确地调用已部署在WebSphere Liberty中的EJB?

我为了获得上述工作而挣扎了很长时间。IE。从独立的Java客户端访问EJB。不成功。但是,当我从另一个WLP实例运行客户端代码时,我确实确实可以访问远程EJB查找和调用工作。这很好。以下是客户端WLP中使用的方法来查找远程EJB并调用方法。

    public void invokeRemoteMethod() {
    dbg("invokeRemoteMethod called");
    String jndiName = "corbaname::localhost:2809/NameService#ejb/global/app1EAR/app1EJB/CalcImpl!test\.CalcRemote";
    Hashtable<String,String> env = new Hashtable<String,String>();
    env.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
    try {
        Context initialContext = new InitialContext(env);
        Object remoteObj = initialContext.lookup(jndiName);
        System.out.println("remoteObj found = " + ((remoteObj == null) ? "null" : remoteObj.getClass().getName()));
        CalcRemote remoteBean = CalcRemote.class.cast(PortableRemoteObject.narrow(remoteObj, CalcRemote.class));
        System.out.println("remoteBean name = " + ((remoteBean == null) ? remoteBean : remoteBean.getClass().getName()));
        System.out.println("add 1, 3 =" + remoteBean.add(1, 3));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

另一件事,我必须从.. usr server&lt; server-name&gt; resourtes resative security*复制文件键。p12和ltpa.keys。您将需要在客户端WLP上设置端口,以免它们发生冲突。

如果您想通过独立的Java客户端调用远程方法,则最好实现基于肥皂的Web服务。

最新更新