2014-06-19 4 views
1

Я следую учебник и:Wildfly 8 - EJB клиент выдает

развернутую один EJB к Wildfly 8 -> проверено

Wildfly возвращает это когда Deploy EJB:

java:global/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService 
java:app/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService 
java:module/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService 
java:jboss/exported/ejb/EmployeeManagementServiceImpl!staffmanagement.EmployeeManagementService 
java:global/ejb/EmployeeManagementServiceImpl 
java:app/ejb/EmployeeManagementServiceImpl 
java:module/EmployeeManagementServiceImpl 

Мой клиент попытка :

public class ClientApplicationTest { 

public static void main(String[] args) { 
    System.out.println("Hello World ClientApplicationTest!"); 
    try { 
     Context jndi = new InitialContext(); 
     String name = "java:module/EmployeeManagementServiceImpl"; 
     EmployeeManagementService service = (EmployeeManagementService) jndi.lookup(name); 

     List<Employee> employees = service.getAllEmployees(); 
     for(Employee employee :employees) { 
      System.out.println(employee); 
     } 
    } catch (NamingException e) { 
     e.printStackTrace(); 
    } 
} 

Ошибка:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) 
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) 
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) 
at javax.naming.InitialContext.lookup(InitialContext.java:411) 
at j2ee.staffmanagement.client.ClientApplicationTest.main(ClientApplicationTest.java:25) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:606) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 

Я добавил следующее: библиотека клиенту (помимо EJB само по себе): /Library/WildFly/modules/system/layers/base/org/jboss/as/appclient/main/wildfly-appclient-8.1. 0.Final.jar (COMPILE SCOPE)

Честно говоря, не знаю, что не так: имя jndi или потому, что я звоню удаленному EJB из-за границы контейнера, нужно что-то еще.

PS: EJB развернут отлично

Все входы пожалуйста?

Tnx

ответ

2

Я модифицировал:

Properties jndiProperties = new Properties(); 
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 

    try { 
     Context jndi = new InitialContext(jndiProperties); 
     String appName = ""; 
     String moduleName = "staff"; 
     String distinctName = ""; 
     String beanName = "EmployeeManagementServiceImpl"; 
     String interfaceFullName = "staffmanagement.EmployeeManagementService"; 
     String jndiName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + interfaceFullName; 
     //ejb:{app-Name}/{module-Name}/{distinct-Name}/{bean-Name}!{fullPath-remote-Interface} 
     EmployeeManagementService service = (EmployeeManagementService) jndi.lookup(jndiName); 
     ... 

И добавил файл в путь к классам: jboss-ejb-client.properties

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false 
remote.connections=default 
remote.connection.default.host=localhost 
remote.connection.default.port = 8080 
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false 
Смежные вопросы