EJB3 Customer Search

I am trying to invoke EJB from a standalone Java client, getting the following error.

Search code

String localJNDIName = "ejbremote:gcmsnew/gcmsutilbeans.jar/CustomerSurveyManageQstBean#com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"; InitialContext ic = new InitialContext(); GCMSBaseRemote bean = (GCMSBaseRemote)ic.lookup(localJNDIName); 

Exception

javax.naming.ConfigurationException: NamingManager.getURLContext cannot find a factory for this circuit: ejbremote at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext (CNContextImpl.java:471) at com.ibm.ws.naming.util. WsnInitCtx.lookup (WsnInitCtx.java:160) in com.ibm.ws.naming.util.WsnInitCtx.lookup (WsnInitCtx.java:179) in javax.naming.InitialContext.lookup (Unknown source) in com.test.Etest.Test. main (EJBClientTest.java:18)

Wednesday

RAD 7.5, EJB3. WebSphere Application Server 7.0.

+1
websphere jndi
source share
4 answers

An ejbremote schema does not exist in WebSphere Application Server (although there is an "ejblocal"). Try using the ejb / prefix instead of ejbremote:.

For more information, see Overview of EJB Application Bindings in the Infocenter.

+2
source share

Since this is a standalone (thin) client, you can try something like this:

  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); 

You must also have the appropriate Jars Websphere in your classpath to complete the above calls.

+1
source share

For remote search

 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; } } 

For local search

 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); } } 
+1
source share

You need the stub file to call EJB, so first create a stub file. Websphere has a utility available in the bin folder of the createEJBStubs application.

0
source share

All Articles