0

Do you know why I'm getting this exception ?

String url = "corbaloc:iiop:localhost:2809";
String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";
String jndi = "ejblocal:my/ejb/PeriodoBO";

Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put("java.naming.provider.url", url);
pdEnv.put("java.naming.factory.initial", initial);
Context initialContext = new InitialContext(pdEnv);

try{
    Object ejbHome = initialContext.lookup(jndi); // <-- here
    Object obj = PortableRemoteObject.narrow(ejbHome, PeriodoBO.class);
}catch(NamingException e){
    System.err.println(e.toString());
}

I'm sure that the JNDI is ok, I was struggling to get it (What's the default JNDI name of an EJB in Websphere Application Server 7 (WAS)?).

Could you help me please?

This is my run configuration :

enter image description here

UPDATE, I have just got the stack trace, I'm analyzing it :

WSCL0910I: Initializing component: com.ibm.ws.websvcs.component.WASAxis2ClientImpl
WSCL0911I: Component initialized successfully.
WSCL0910I: Initializing component: com.ibm.ejs.jms.JMSClientRegistration
WSCL0911I: Component initialized successfully.
WSCL0901I: Component initialization completed successfully.
WSCL0035I: Initialization of the Java EE Application Client Environment has completed.
WSCL0014I: Invoking the Application Client class xxxxx.tests.AllTests
.[02/06/14 17:21:45:963 COT] 00000000  W UOW=1-46884688-4040963:dmflores source=com.ibm.websphere.naming.genericURLInitialContextFactory org=IBM prod=WebSphere component=Application Server thread=[P=704708:O=0:CT]
          NMSV0907E: Could not invoke method "getObjectInstance" on object of type "com.ibm.ws.naming.urlns.genericURLContextFactory".
E.
Time: 0,011
There was 1 error:
1) testCursosLlevados(xxxxx.CursosTest)javax.naming.ConfigurationException: Could not invoke method getObjectInstance on object of type com.ibm.ws.naming.urlns.genericURLContextFactory. [Root exception is java.lang.reflect.InvocationTargetException]
    at com.ibm.websphere.naming.genericURLInitialContextFactory.getAndInvokeMethod(genericURLInitialContextFactory.java:480)
    at com.ibm.websphere.naming.genericURLContextFactory.getObjectInstance(genericURLContextFactory.java:165)
    at javax.naming.spi.NamingManager.getURLContext(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at xxxxxxx.tests.CursosTest.testCursosLlevados(CursosTest.java:59)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at xxxxxx.tests.AllTests.main(AllTests.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.ws.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:797)
    at com.ibm.ws.client.applicationclient.launchClient.main(launchClient.java:502)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:213)
    at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:93)
    at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:74)
    at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
    at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
    at org.eclipse.core.launcher.Main.run(Main.java:981)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:341)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:111)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.websphere.naming.genericURLInitialContextFactory.getAndInvokeMethod(genericURLInitialContextFactory.java:466)
    ... 49 more
Caused by: javax.naming.ConfigurationException: There is no name space
    at com.ibm.ws.naming.urlns.genericURLContextFactory.isNameSpaceAccessable(genericURLContextFactory.java:96)
    at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:84)
    ... 54 more
Community
  • 1
  • 1
Daniel Flores
  • 770
  • 3
  • 12
  • 31
  • What type of a program are you calling from? is it from a standalone Java application? a JEE Application Client? an EJB? a Web module? what? – Isaac May 31 '14 at 01:11
  • it's from a JEE application client. I updated my websphere from 7.0.0.0 to 7.0.0.31 and the problem persists. – Daniel Flores Jun 02 '14 at 20:35

2 Answers2

2

ejblocal:my/ejb/PeriodoBO points to the local interface. Local interface cannot be accessed by the Java EE Application Client. You need the Remote interface.

Add @Remote with correct interface to your bean. Then during app initialization you will find in the SystemOut.log binding name to which the interface was bound in the JNDI. Then in initialContext.lookup(jndi); use that JNDI name.

Hope it helps

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Gas
  • 17,601
  • 4
  • 46
  • 93
  • Thanks Gas, at least I'm not getting the same error. Now I have a problem about casting from stub interfaces to objects (in the line next to the lookup method), I'm going to post this problem tomorrow. Thanks ! – Daniel Flores Jun 03 '14 at 06:19
  • Thanks Gas, now all is working ok, but could you explain me why is it remote? isn't supposed that it's running in the same JVM of the local interface, because it's in the same EAR of where the ejb is located (as the first picture) ? – Daniel Flores Jun 03 '14 at 20:23
  • 1
    @DanielFlores You wrote that you have a JEE Application Client - although application client is run by invoking Ear, it runs in separate JVM - the client container - which connects remotely to the application server JVM and components running there. The local interfaces can be only used in the same JVM and they are not published to the global JNDI accessible externally. So because you are in external JVM you have to use remote ones. – Gas Jun 04 '14 at 01:20
1

As this code is invoked from within a Java EE Application Client, and the Java EE Application Client is launched by the WAS libraries, much of the code you have there is unneeded and might as well be the reason for your problems. Try this:

String jndi = "ejblocal:my/ejb/PeriodoBO";
Context initialContext = new InitialContext();
Object ejbHome = initialContext.lookup(jndi);
Object obj = PortableRemoteObject.narrow(ejbHome, PeriodoBO.class);

EDIT to that, add @Gas's solution (which really addresses the root of your problem).

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Isaac
  • 16,458
  • 5
  • 57
  • 81