Websphere EJB3客户端查找
我试图从独立Java客户机调用EJB,得到以下错误 查找代码Websphere EJB3客户端查找,websphere,ejb-3.0,jndi,Websphere,Ejb 3.0,Jndi,我试图从独立Java客户机调用EJB,得到以下错误 查找代码 String localJNDIName = "ejbremote:gcmsnew/gcmsutilbeans.jar/CustomerSurveyManageQstBean#com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"; InitialContext ic = new InitialContext(); GCMSBaseRemote bean
String localJNDIName = "ejbremote:gcmsnew/gcmsutilbeans.jar/CustomerSurveyManageQstBean#com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote";
InitialContext ic = new InitialContext();
GCMSBaseRemote bean = (GCMSBaseRemote)ic.lookup(localJNDIName);
例外情况
javax.naming.ConfigurationException:NamingManager.getURLContext
找不到此方案的工厂:ejbremote位于
com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:471)
位于com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:160)
com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)位于
javax.naming.InitialContext.lookup(未知源)位于
main(ejbclientset.java:18)
环境
RAD 7.5,EJB3。Websphere Application Server 7.0。Websphere Application Server中不存在ejbremote方案(即使“ejblocal”确实存在)。尝试使用ejb/前缀代替ejbremote:
有关更多信息,请参阅信息中心中的主题。WebSphere Application Server中不存在ejbremote方案(即使存在“ejblocal”)。尝试使用ejb/前缀代替ejbremote:
有关更多信息,请参阅信息中心中的主题。您需要有存根文件来调用EJB,因此首先生成存根文件。在websphere中,appserver bin文件夹CreateJBSubs中有可用的实用程序。您需要有存根文件来调用EJB,因此首先生成存根文件。在websphere中,appserver bin文件夹CreateJBSubs中有一个可用的实用程序。由于这是一个独立(“瘦”)客户端,因此您应该尝试以下操作:
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2809"); //localhost=the host where your EJB is located, 2809=BOOTSTRAP_ADDRESS port
Context initCtx = new InitialContext(properties);
Object homeObject = initCtx.lookup("com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"); //by default the JNDI name of your Remote Interface is its full class name
// Narrow to a real object
csmo = (CustomerSurveyManageQstRemote) javax.rmi.PortableRemoteObject.narrow(homeObject, com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote.class);
为了进行上述调用,您的类路径中还应该有相应的Websphere JAR。由于这是一个独立(“瘦”)客户端,您可能需要尝试以下操作:
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2809"); //localhost=the host where your EJB is located, 2809=BOOTSTRAP_ADDRESS port
Context initCtx = new InitialContext(properties);
Object homeObject = initCtx.lookup("com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"); //by default the JNDI name of your Remote Interface is its full class name
// Narrow to a real object
csmo = (CustomerSurveyManageQstRemote) javax.rmi.PortableRemoteObject.narrow(homeObject, com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote.class);
为了进行上述调用,您的类路径中还应该有适当的Websphere JAR。用于远程查找
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
static String url = "corbaloc:iiop:localhost:2809";
static String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";
static String jndi = "ejb/enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.remote.impl.interface";
private static ServiceLocator serviceLocator = null;
InitialContext context = null;
private ServiceLocator() throws NamingException, IOException {
Hashtable<String,String> env = new Hashtable<String,String> ();
env.put("java.naming.provider.url", url );
env.put("java.naming.factory.initial", initial );
context = new InitialContext(env);
}
public synchronized static ServiceLocator getInstance() throws NamingException, IOException {
if (serviceLocator == null) {
serviceLocator = new ServiceLocator();
}
return serviceLocator;
}
public Object getService(String jndiName) throws NamingException {
return context.lookup(jndiName);
}
public <T>T getRemoteObject(Class<T> remoteInterfaceClass) {
try {
return (T)javax.rmi.PortableRemoteObject.narrow( context.lookup(jndi), remoteInterfaceClass);
} catch (NamingException nexc) {
nexc.printStackTrace();
}
return null;
}
}
import java.io.IOException;
导入java.util.Hashtable;
导入javax.naming.InitialContext;
导入javax.naming.NamingException;
公共类服务定位器{
静态字符串url=“corbaloc:iiop:localhost:2809”;
静态字符串initial=“com.ibm.websphere.naming.WsnInitialContextFactory”;
静态字符串jndi=“ejb/enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.remote.impl.interface”;
私有静态ServiceLocator ServiceLocator=null;
InitialContext=null;
私有ServiceLocator()引发NamingException,IOException{
Hashtable env=新的Hashtable();
put(“java.naming.provider.url”,url);
put(“java.naming.factory.initial”,initial);
上下文=新的初始上下文(env);
}
公共同步静态ServiceLocator getInstance()引发NamingException,IOException{
如果(serviceLocator==null){
serviceLocator=新的serviceLocator();
}
返回服务定位器;
}
公共对象getService(字符串jndiName)引发NamingException{
返回context.lookup(jndiName);
}
公共T getRemoteObject(类remoteInterfaceClass){
试一试{
return(T)javax.rmi.PortableRemoteObject.窄带(context.lookup(jndi),remoteInterfaceClass);
}捕获(NamingException nexc){
printStackTrace();
}
返回null;
}
}
用于本地查找
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
static String url = "iiop://localhost";
static String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";
static String jndi = "ejblocal:enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.local.impl.interface";
private static ServiceLocator serviceLocator = null;
InitialContext context = null;
private ServiceLocator() throws NamingException, IOException {
Hashtable<String,String> env = new Hashtable<String,String> ();
env.put("java.naming.provider.url", url );
env.put("java.naming.factory.initial", initial );
context = new InitialContext(env);
}
public synchronized static ServiceLocator getInstance() throws NamingException, IOException {
if (serviceLocator == null) {
serviceLocator = new ServiceLocator();
}
return serviceLocator;
}
public Object getService(String jndiName) throws NamingException {
return context.lookup(jndiName);
}
public Object getService() throws NamingException {
return context.lookup(jndi);
}
}
import java.io.IOException;
导入java.util.Hashtable;
导入javax.naming.InitialContext;
导入javax.naming.NamingException;
公共类服务定位器{
静态字符串url=”iiop://localhost";
静态字符串initial=“com.ibm.websphere.naming.WsnInitialContextFactory”;
静态字符串jndi=“ejblocal:enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.local.impl.interface”;
私有静态ServiceLocator ServiceLocator=null;
InitialContext=null;
私有ServiceLocator()引发NamingException,IOException{
Hashtable env=新的Hashtable();
put(“java.naming.provider.url”,url);
put(“java.naming.factory.initial”,initial);
上下文=新的初始上下文(env);
}
公共同步静态ServiceLocator getInstance()引发NamingException,IOException{
如果(serviceLocator==null){
serviceLocator=新的serviceLocator();
}
返回服务定位器;
}
公共对象getService(字符串jndiName)引发NamingException{
返回context.lookup(jndiName);
}
公共对象getService()引发NamingException{
返回context.lookup(jndi);
}
}
用于远程查找
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ServiceLocator {
static String url = "corbaloc:iiop:localhost:2809";
static String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";
static String jndi = "ejb/enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.remote.impl.interface";
private static ServiceLocator serviceLocator = null;
InitialContext context = null;
private ServiceLocator() throws NamingException, IOException {
Hashtable<String,String> env = new Hashtable<String,String> ();
env.put("java.naming.provider.url", url );
env.put("java.naming.factory.initial", initial );
context = new InitialContext(env);
}
public synchronized static ServiceLocator getInstance() throws NamingException, IOException {
if (serviceLocator == null) {
serviceLocator = new ServiceLocator();
}
return serviceLocator;
}
public Object getService(String jndiName) throws NamingException {
return context.lookup(jndiName);
}
public <T>T getRemoteObject(Class<T> remoteInterfaceClass) {
try {
return (T)javax.rmi.PortableRemoteObject.narrow( context.lookup(jndi), remoteInterfaceClass);
} catch (NamingException nexc) {
nexc.printStackTrace();
}
return null;
}
}
import java.io.IOException;
导入java.util.Hashtable;
导入javax.naming.InitialContext;
导入javax.naming.NamingException;
公共类服务定位器{
静态字符串url=“corbaloc:iiop:localhost:2809”;
静态字符串initial=“com.ibm.websphere.naming.WsnInitialContextFactory”;
静态字符串jndi=“ejb/enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.remote.impl.interface”;
私有静态ServiceLocator ServiceLocator=null;
InitialContext=null;
私有ServiceLocator()引发NamingException,IOException{
Hashtable env=新的Hashtable();
put(“java.naming.provider.url”,url);
put(“java.naming.factory.initial”,initial);
上下文=新的初始上下文(env);
}
公共同步静态ServiceLocator getInstance()引发NamingException,IOException{
如果(serviceLocator==null){
serviceLocator=新的serviceLocator();
}
返回服务定位器;
}
公共对象getService(字符串jndiName)引发NamingException{
返回context.lookup(jndiName);
}
公共T getRemoteObject(类remoteInterfaceClass){
试一试{