EJB3 клиентский поиск - PullRequest
       38

EJB3 клиентский поиск

1 голос
/ 01 декабря 2011

Я пытаюсь вызвать EJB из автономного Java-клиента, получая приведенную ниже ошибку.

Код поиска

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 at 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 (неизвестный источник) в com.test.EJBClientTest.main (EJBClientTest.java:18)

Окружающая среда

RAD 7.5, EJB3. Websphere Application Server 7.0.

Ответы [ 4 ]

2 голосов
/ 01 декабря 2011

Схема ejbremote не существует в WebSphere Application Server (даже если «ejblocal» существует). Попробуйте использовать префикс ejb / вместо ejbremote: .

Для получения дополнительной информации см. Раздел Привязки приложений EJB *1008* в Инфоцентре.

1 голос
/ 05 июня 2013

Для удаленного поиска

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;
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 голос
/ 22 ноября 2012

Поскольку это автономный («тонкий») клиент, возможно, вам следует попробовать что-то вроде этого:

   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 Jars в вашем classpath для выполнения вышеуказанных вызовов.

0 голосов
/ 02 декабря 2011

Для запуска EJB необходим файл-заглушка, поэтому сначала создайте файл-заглушку.В websphere есть утилита, доступная в папке bin сервера приложений createEJBStubs.

...