我需要为我的本地ejb做一个ejb测试客户端,所以这里是我的ejb应用程序详细信息:
这是我要查找的bean:
ServiceFacadeRemote
@Remote
public interface ServiceFacadeRemote {
ServiceFacade
// ServiceFacade implementation class
@Stateless
public class ServiceFacade implements ServiceFacadeRemote,ServiceFacadeLocal{
...
在" Deployments"在JBoss 6.4面板部分,我还可以看到该服务的jndi名称: ServiceFacade
还有deployead ear的信息
ear name: ecommerce.ear
ejb name: ecommerce-ejb-0.0.1-SNAPSHOT.jar
我按照此链接上的指南进行了操作:
https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI
这是我的junit测试:
static Object lookupRemoteStatelessEjb(Class<?> clazz, Context context) throws NamingException {
// The app name is the application name of the deployed EJBs. This is typically the ear name
// without the .ear suffix. However, the application name could be overridden in the application.xml of the
// EJB deployment on the server.
// Since we haven't deployed the application as a .ear, the app name for us will be an empty string
final String appName = "ecommerce";
// This is the module name of the deployed EJBs on the server. This is typically the jar name of the
// EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
// In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
// jboss-as-ejb-remote-app
final String moduleName = "ecommerce-ejb-0.0.1-SNAPSHOT";
// AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
// our EJB deployment, so this is an empty string
final String distinctName = "";
// The EJB name which by default is the simple class name of the bean implementation class
final String beanName = clazz.getSimpleName();
// the remote view fully qualified class name
final String viewClassName = clazz.getName();
// let's do the lookup
return context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}
@Test
public void readService() {
final Hashtable<Object,Object> jndiProperties = new Hashtable<Object,Object>();
jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
jndiProperties.put("jboss.naming.client.ejb.context", true);
Context ctx;
try {
ctx = new InitialContext(jndiProperties);
ServiceFacadeRemote service = (ServiceFacadeRemote)lookupRemoteStatelessEjb(ServiceFacadeRemote.class, ctx);
Assert.assertNotNull(service);
Object output = service.readService(..)
Assert.assertNotNull(output);
} catch (NamingException e) {
Assert.fail(e.getMessage());
}
}
在线:
Object output = service.readService(..)
我收到此错误:
java.lang.IllegalStateException:EJBCLIENT000025:没有EJB接收器可用于处理[appName:ecommerce-backend,...
更糟糕的是更改 appName 或 moduleName ,错误是一样的,所以我认为我正在做的事情存在一个基本错误。 ..
任何解决方案?
更新
使用以下方式更改通话:
ejb:ecommerce/ecommerce-ejb-0.0.1-SNAPSHOT//ServiceFacade!it.infocert.shop.facade.remote.ServiceFacadeRemote
但仍然无法正常工作。
但是,下面的调用(没有ejb:前缀)似乎有效:
ecommerce/ecommerce-ejb-0.0.1-SNAPSHOT/ServiceFacade!it.infocert.shop.facade.remote.ServiceFacadeRemote
重点是什么?
答案 0 :(得分:1)
默认情况下,lookupRemoteStatelessEjb()
beanName
是'bean实现的简单类名'
假设所有远程接口都以FacadeRemote
结束,所有无状态类结束于Facade
,您可以编码
final String beanName = clazz.getSimpleName().replaceAll("Remote$","");