Mircea Stanciu
Mircea Stanciu

Reputation: 3753

Wildfly 8 - ejb client issues

I am following a tutorial and:

deployed one ejb to Wildfly 8 -> checked

Wildfly returns this when 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

My client attempt:

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

Error:

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)

I added following library to the client (besides ejb itself): /Library/WildFly/modules/system/layers/base/org/jboss/as/appclient/main/wildfly-appclient-8.1.0.Final.jar (COMPILE SCOPE)

Honestly not sure what is wrong: jndi name, or because I am calling remote EJB from outside container, need something else.

PS: EJB is deployed fine

Any inputs pls?

Tnx

Upvotes: 1

Views: 3837

Answers (1)

Mircea Stanciu
Mircea Stanciu

Reputation: 3753

I modified:

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

And added file in the classpath: 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

Upvotes: 2

Related Questions