I'm migrating some code from JBoss to Apache/TomEE.  The existing code uses a 
JNDI naming scheme that I think is 
{moduleId}/{ejbClass.simpleName}/{interfaceName.annotationTypeLC}.  I'm trying 
to figure out how to access my EJBs from TomEE without having to rewrite a 
bunch of code.

I've set up a very simple TomEE web app (tomeetest) where I have a JAX-RS web 
service accessing an EJB by its JNDI name.  If I don't pass in any properties 
to my InitialContext, the only way I've been able to access my EJB has been 
with its global name, i.e. java:global/tomeetest/ApplicationManager.

If I pass in a Properties with the following line:

p.put("java.naming.factory.initial", 
"org.apache.openejb.client.LocalInitialContextFactory");

I have more options with the JNDI names I use, namely, anything that shows up 
as an option in catalina.out when I deploy the WAR file.  I just can't 
understand how to use the openejb.jndiname.format property.  It doesn't seem to 
matter what I set that to; nothing changes.

I want to be able to access the local or remote interfaces using the following 
syntax:

tomeetest/ApplicationManager/local
tomeetest/ApplicationManager/remote

Here are my example files:

TestService.java:

import com.example.account.ApplicationManager;
import javax.naming.InitialContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Calendar;
import java.util.Properties;

@Path("test")
public class TestService {
    @GET
    @Path("/get")
    public String get() throws Exception {
        Properties p = new Properties();
        p.put("java.naming.factory.initial", 
"org.apache.openejb.client.LocalInitialContextFactory");
        p.put("openejb.jndiname.format", 
"{moduleId}/{ejbClass.simpleName}/{interfaceType.annotationNameLC}");
        InitialContext initialContext = new InitialContext(p);
        ApplicationManager applicationManager = (ApplicationManager) 
initialContext.lookup("ApplicationManagerBeanLocal"); 
        return "Customer simple get: " + 
applicationManager.findById(Calendar.getInstance().getTime().toString());
    }
}


ApplicationManagerBean.java:

package com.example.account;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless(mappedName = "ApplicationManagerMapped")
@Local(ApplicationManager.class)
@Remote(ApplicationManagerRemote.class)
public class ApplicationManagerBean {
    public String findById(String applicationId) {
        return applicationId;
    }
}


ApplicationManager.java:

package com.example.account;

public interface ApplicationManager {
    public String findById( String applicationId );
}


ApplicationManagerRemote.java:

package com.example.account;

public interface ApplicationManagerRemote extends ApplicationManager {
}


Thanks for any tips you can provide,
- Andrew.

Reply via email to