2

I'm trying to access an EJB3 from a Java EE client-application, but keep getting nothing but lookup failures. The client application is running within the Java EE Application Client Container.

My Java EE Application 'CoreServer' is exposing a number of beans with remote interfaces. I have no problem accessing them from a Web Application deployed on the same Glassfish v3.0.1.

Now I'm trying to access it from a client-application:

public class Main {

  public static void main(String[] args) {
    CampaignControllerRemote bean = null;

    try {
        InitialContext ctx = new InitialContext();
        bean = (CampaignControllerRemote) ctx.lookup("java:global/CoreServer/CampaignController");

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    if (bean != null) {
        Campaign campaign = bean.get(361);
        if (campaign != null) {
            System.out.println("Got "+ campaign);
        }
    }
  }

}

When I run deploy it to Glassfish and run it from the appclient, I get this error:

Lookup failed for 'java:global/CoreServer/CampaignController' in SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=localhost,orb'sInitialPort=3700

However, that's exactly the same JNDI-name I use when I lookup the bean from the WebApplication (via SessionContext, not InitialContext - does that matter?). Also, when I deploy 'CoreServer', Glassfish reports:

Portable JNDI names for EJB CampaignController : [java:global/CoreServer/CampaignController!mvs.api.CampaignControllerRemote, java:global/CoreServer/CampaignController]
Glassfish-specific (Non-portable) JNDI names for EJB CampaignController : [mvs.api.CampaignControllerRemote, mvs.api.CampaignControllerRemote#mvs.api.CampaignControllerRemote]

I tried all four names, none worked. Is the appclient unable to access beans with (only) Remote interfaces?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Hank
  • 4,597
  • 5
  • 42
  • 84
  • I would recommend that you switch to using dependency injection for both use-cases... (your web app and app client). – vkraemer May 12 '10 at 05:13
  • how is the CORBA lookup accomplished with dependency injection on the app client? Can you be more specific? – Thufir Mar 11 '15 at 15:43

3 Answers3

1

If you are talking about an application client use this answer:

Don't bother with jndi lookup; you can use @EJB injection into static fields of the application class.

Brian Leathem
  • 4,609
  • 1
  • 24
  • 44
1

Have you tried java:global/CoreServer/CampaignController!mvs.api.CampaignControllerRemote instead of java:global/CoreServer/CampaignController ?

Ravindra Gullapalli
  • 9,049
  • 3
  • 48
  • 70
0

If you are talking about a stand-alone client, use this answer:

Here's the method I use for JNDI lookup for glassfish v2, it may be quite similar for v3:

private void lookupJndi() {
    final Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
    String host = "hostname.domain";
    logger.log(Level.INFO, "Connecting to CORBA Host: " + host);
    props.setProperty("org.omg.CORBA.ORBInitialHost", host);
    try {
        InitialContext ic = new InitialContext(props);
        scheduleManager = (ScheduleManagerRemote) ic.lookup("ScheduleManagerRemote");
        experimentManager = (ExperimentManagerRemote) ic.lookup("ExperimentManager");
        facilityManager = (FacilityManagerRemote) ic.lookup("FacilityManager");
    } catch (NamingException e) {
        ...
    }

The key part is getting the com.sun INITIAL_CONTEXT_FACTORY. Also make sure you have all the glassfish dependencies bundled with your app. For glassfish v2, there are a lot. The v2 jars are: javaee, appserv-rt, appserv-ext, appserv-admin, appserv-deployment-client.

Things may be a lot simpler with v3, but this definitely works for v2.x

Brian Leathem
  • 4,609
  • 1
  • 24
  • 44
  • is bundling all the dependencies different from using `appclient`? – Thufir Mar 11 '15 at 15:44
  • 1
    @Thufir it's been a *long* time since I looked at this, but IIRC the difference with the appclient as compared to a standalone client is that the appclient is a managed container, your object instances are injected. The associated set of dependencies if different for the two use cases. – Brian Leathem Mar 11 '15 at 16:31