WebSphere Application Server & Liberty

WebSphere Application Server & Liberty

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Can't call an EJB from a Java standalone client

    Posted Wed October 22, 2014 11:32 AM
    Hello,

    I've spent hours to perform one of the most simple operation that, with any other application server, is really obvious and I'm very surprized to see the confusion and the lack of information and examples when it comes to use WebSphere.

    I'm running WebSphere 8.5.5 on windows, I have a seesion bean deployed and its JNDI binding displayed by the log file is java:global/TestEAR/TestEJB/Test123!com.ing.tests.Test123.  
     
    So, I'm trying to call it from a Java standalone client like this:   
       
    Map props = new HashMap();
    props.put(EJBContainer.MODULES, new File ("C:/RADWorkspace/Workspace_WAS_8.5_New/TestEJB\build"));
    props.put(EJBContainer.PROVIDER, "com.ibm.websphere.ejbcontainer.EmbeddableContainerProvider");
    EJBContainer ec = EJBContainer.createEJBContainer(props);
    Object o = ec.getContext().lookup("java:global/TestEAR/TestEJB/Test123!com.ing.tests.Test123");

    This raises the following exception:

    Exception in thread "P=929450:O=0:CT"javax.ejb.EJBException: nested exception is: com.ibm.ws.exception.ConfigurationError: java.lang.Exception: Cannot find BundleContext for service com.ibm.ws.runtime.component.MetaDataMgrImpl

    at com.ibm.websphere.ejbcontainer.EmbeddableContainer.initialize(EmbeddableContainer.java:499)



    at com.ibm.websphere.ejbcontainer.EmbeddableContainer.open(EmbeddableContainer.java:442)



    at com.ibm.websphere.ejbcontainer.EmbeddableContainer.newContainer(EmbeddableContainer.java:396)



    at com.ibm.websphere.ejbcontainer.EmbeddableContainerProvider.createEJBContainer(EmbeddableContainerProvider.java:75)



    at javax.ejb.embeddable.EJBContainer.createEJBContainer(


    EJBContainer.java:56)



    at com.ing.tests.Test123.main(Test123.java:21)



    Caused by: com.ibm.ws.exception.ConfigurationError:



    java.lang.Exception: Cannot find BundleContext for service com.ibm.ws.runtime.component.MetaDataMgrImpl



    at com.ibm.ws.runtime.component.MetaDataMgrImpl.initialize(



    MetaDataMgrImpl.java:511)



    at com.ibm.websphere.ejbcontainer.EmbeddableContainer.initialize(



    EmbeddableContainer.java:497)



    I tried also using the following code :
      

    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2809");
    Context ctx = new InitialContext(props);
    Object o = ctx.lookup("java:global/TestEAR/TestEJB/Test123!com.ing.tests.Test123");


    This raises the following exception:


    NMSV0307E: A java: URL name was used, but Naming was not configured to handle java: URL names. The likely cause is a user in error attempting to specify a java: URL name in a non-J2EE client or server environment. Throwing ConfigurationException.



    Exception in thread "main"
    javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.


    at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:109)
    at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:85)


    at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:612)


    at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:561)


    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)


    at javax.naming.InitialContext.lookup(InitialContext.java:422)


    at com.ing.tests.Test123.main(Test123.java:20)


    Does anybody have a simple example ? Many thanks in advance.


    Nicolas  



     



  • 2.  Can't call an EJB from a Java standalone client

    Posted Thu October 23, 2014 03:19 AM
    Hi,
    try this:

    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.ibm.websphere.naming.WsnInitialContextFactory");
    p.put(Context.SECURITY_PRINCIPAL, "username");
    p.put(Context.SECURITY_CREDENTIALS, "password");
    p.put(Context.PROVIDER_URL, "corbaloc:iiop:IP:PORT_BOOTSTRAP_ADDRESS");
    Context ctx = new InitialContext(props);
    Object o = ctx.lookup("path_to_bean");


  • 3.  Can't call an EJB from a Java standalone client

    Posted Thu October 23, 2014 05:14 AM
    Hi Ryman,

    Thank you for taking the time to reply to my post. What do you mean by "try that" ? Didn't I try it ? Didn't you read the code I posted and didnr't you see that was this post was saying was that this code, that you're also suggesting me to try, doesn't work and raises the mentioned exception ?

    Kind regards,

    Nicolas


  • 4.  Can't call an EJB from a Java standalone client

    Posted Thu October 23, 2014 06:24 AM
    You use iiop://localhost:2809. In my example we have: corbaloc:iiop:IP:PORT_BOOTSTRAP_ADDRESS.


  • 5.  Can't call an EJB from a Java standalone client

    Posted Thu October 23, 2014 10:00 AM
    Oh, my bad, I didn't notice that, sorry. I don't know what this prefix is ment to do but using it doesn't change anything, the same exception is raised. As you certainly have seen, the error message is saying that using java:global in a standalone client is not supported but only in a Java EE client. So, I don't know what JNDI name to use for the lookup as the only bindings displayed in the log file is in ejblocal and java:global. ejblocal cannot be used, of course, but I was expecting that java:global can.

    So, if it's true that java:global is not supported in standalone clients, then only EJBContainer can be used in this case and, this doesn't work neither for some obscure locale reason: missing the locale message bundle or something.


  • 6.  Can't call an EJB from a Java standalone client

    Posted Fri October 24, 2014 02:59 AM
    Nocolas, if your bean are local try this path:
    java:comp/env/ejb/local/YourBean


  • 7.  Can't call an EJB from a Java standalone client

    Posted Fri October 24, 2014 03:06 AM



    You can also try this piece of code:

    public EJBHome getHome(String name, Class clazz) throws Exception {
            Object objref = context.lookup(name);
            EJBHome home = (EJBHome) PortableRemoteObject.narrow(objref, clazz);
            return home;
        }





  • 8.  Can't call an EJB from a Java standalone client

    Posted Fri October 24, 2014 05:43 AM
    Hi Ryman,

    "if your bean are (is) local"

    You probably mean "if the bean is called on its local interface". Of course not, how could it be called on its local interface since it is called by a standalone client (for example a Swing app, a JUnit test, etc.) ?

    Concerning the piece of code you suggest me to try, last time I've seen something like this it was 10 years ago when I was using EJB 2. You don't seem to be too old, so how come you're suggesting me to use home interfaces and PortableRemoteObject ? Time have changed and since EJB 3, i.e. since many years, home interfaces and PortableRemoteObject don't exist any more.

    But thank you anyway for your good intention to help and for taking on your time to reply to my post. I really appreciate it. But without wanting to be rude, if you're not sure you understand the basis of this topic, please don't feel obligated to reply.

    Kind regards,

    Nicolas


  • 9.  Can't call an EJB from a Java standalone client

    Posted Tue December 02, 2014 08:08 AM
    Do you have this jar in the classpath?

    com.ibm.ws.webservices.thinclient-8.5.0.jar

    I am getting the same error when this jar in the classpath, otherwise its fine. But I need this jar as I need to consume some web services.

    Hope this helps