A Simple Java Client Server Application using EJB3 and Glassfish3

Well, in this tutorial i want to show you how to create a simple client server application using java. Actually java has dozens of different network protocols, from a simple socket, hessian, burlap, SpringHttpInvoker, SOAP, XML and so on. But in this example, i will try to create a very simple client server application with EJB 3, using Glassfish 3 as JavaEE Container. As usual, i use Netbeans 6.9 with its default Glassfish3 installation.

First, i create a new JavaEE, EJB Module project, named CompressedEJBServer, and create a simple Stateless Session Bean in it

package com.edw.facade;

import javax.ejb.Remote;

/**
 *
 * @author edw
 */
@Remote
public interface ConnectionFacadeRemote {
    String sayHello(String string);
    int sayAge(int age);  
}

and its implementation

package com.edw.facade;

import javax.ejb.Stateless;

/**
 *
 * @author edw
 */
@Stateless
public class ConnectionFacade implements ConnectionFacadeRemote {

    public String sayHello(String string) {
        System.out.println("im at " + this.getClass().getName() + " method sayHello()");
        return "hello " + string;
    }

    public int sayAge(int age) {
        System.out.println("im at " + this.getClass().getName() + " method sayAge()");
        return age * 2;
    }
}

and that’s my EJB3 Server side files. Simple isn’t it?

Next step is creating a Standard Java Application project, for my EJB3 client application. It consist only 1 java file, for testing connection to the server.

package com.edw.main;

import com.edw.facade.ConnectionFacadeRemote;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;

/**
 *
 * @author edw
 */
public class Main {

    private Logger logger = Logger.getLogger(Main.class);

    private void connect() {
        try {
            Properties props = new Properties();
            props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
            props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
            
            // glassfish default port value will be 3700, 
            // but im using tcpviewer to redirect my 50005 port to 3700
            props.setProperty("org.omg.CORBA.ORBInitialPort", "50005");

            InitialContext ctx = new InitialContext(props);
            ConnectionFacadeRemote connectionFacadeRemote = (ConnectionFacadeRemote) ctx.lookup("com.edw.facade.ConnectionFacadeRemote");
            logger.debug(connectionFacadeRemote.sayHello("edwin "));
            logger.debug("my age is " + connectionFacadeRemote.sayAge(12) + " years");
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }

    public static void main(String[] args) {
        Main x = new Main();
        x.connect();
    }
}

include these jars to your client side’s application,

auto-depends.jar
common-util.jar
config.jar
config-api.jar
config-types.jar
connectors-internal-api.jar
container-common.jar
deployment-common.jar
dol.jar
ejb.security.jar
ejb-container.jar
glassfish-api.jar
glassfish-corba-asm.jar
glassfish-corba-codegen.jar
glassfish-corba-csiv2-idl.jar
glassfish-corba-newtimer.jar
glassfish-corba-omgapi.jar
glassfish-corba-orb.jar
glassfish-corba-orbgeneric.jar
glassfish-naming.jar
gmbal.jar
hk2-core.jar
internal-api.jar
javax.ejb.jar
javax.jms.jar
javax.resource.jar
javax.servlet.jar
javax.transaction.jar
jta.jar
kernel.jar
management-api.jar
orb-connector.jar
orb-iiop.jar
security.jar
tiger-types-osgi.jar
transaction-internal-api.jar 

and dont forget to add CompressedEJBServer project into CompressEJBClient’s project

this is what happen if i run my client side’s application

[Main] DEBUG com.edw.main.Main:30 - hello edwin 
[Main] DEBUG com.edw.main.Main:31 - my age is 24 years

this is my Server side’s project structures

and this is my Client side’s project structures
My Client Side's Project Structure

and this is my TCP Viewer logs, i try to redirect my localhost’s port 50005 into my localhost’s port 3700 (Glassfish’s port), so i can see what is passing through my 50005 port via TCP Viewer’s console.

Hope this can help, have fun and good luck. May the Source be with You.
(*)

82 thoughts on “A Simple Java Client Server Application using EJB3 and Glassfish3”

  1. Nice blog, Instead of including all the libraries in your classpath, you can also use AppClient which will automatically generate a client with all the dependencies.

  2. MAN YOUR AWESOME, I HAVE SPENDED A LOT OF HOURS SEARCHING FOR THE MINIMAL JAR LIBS REQUIRED FOR A GFV3 EJB CLIENT.

    YOU ROCK!

    Regards from México

    1. Thanks Hull, glad that it can help.
      Dont forget to Visit Indonesia, Dangerously Beautiful. 🙂

  3. How to add these jar files to client side’s application? actually i donno where they r located on my computer. I’m a newbie.

    1. hi Gowtham, thanks for asking,
      you can find these jars on your glassfish installation folder, they are in modules folder. For example, in my PC is, C:\Program Files\glassfish-3.0.1\glassfish\modules.

  4. Hello Edwin. Thanks for sharing. I´m also a newbie. I would like to know if you had to install client and server in a production environment, how would you install this program? How would you call the client in a user-friendly way?

    1. Hi Gerardo, thanks for ur question.
      Your question is a little bit confusing, but ill try my best to answer it. I like to use exe4j to create an executable application for my client, or you could also try JNLP web start to lauch ur client application from web so you dont have to distribute ur application. Dont forget to include Glassfish libraries on ur client classpath.
      And how can i call the client in a user-friendly way? Well, i dont know if the server can call the client, try using java.net.Socket or java.net.SocketServer for it.

  5. java.lang.NoClassDefFoundError: com/sun/enterprise/module/ModulesRegistry ??? why?… I did everything…

    1. hi fernando,
      you need to include hk2-core.jar from your glassfish installation lib, well in my PC it’s in C:\Program Files\glassfish-3.0.1\glassfish\modules\hk2-core.jar.
      cheers.

  6. Thanks for helping me get closer. I have a deadline looming and I am !!Desperate!! to get this stand alone client deployed (it runs fine inside Netbeans).

    I believe I did everything right but I’m getting a null pointer error:
    SerialContext.(SerialContext.java:198). Do you have any ideas?

    1. hi ron,
      i’m glad that your program is working well right now, perhaps you could share your complete exception stack trace, and how you managed to fixed it. Maybe it could help others too.

      Thanks before.

  7. Hi Edwin, thanks for your tutorial.

    I have a question about the client’s side application. Why everytime I build the client’s side application, the EJB component is undeployed so I have to deploy it again?

    Thanks man, as a fellow Indonesian I’m proud of you

    Jeffry

  8. hi Jeffry, thanks for the question.
    May i know how you deploy your EJB component, do you use netbeans’ to do it or you deploy it manually?

    Why dont you try to manually deploy your EJB components. First build your project into an EAR application, and then upload it into Glassfish’s environment.

  9. Hi,

    Thanks for this tutorial, but I have one question, this client works outside form netbeans?

    and in another computer?

    Thanks again

    1. Hi Antonio,
      yes this application works well with or without netbeans, and accessible from other computer.

  10. Hello edwin,
    Thanks a lot for the article.. although I had many many issues before I got it (partially) working.

    –the setup
    I have setup the server and the client separately, both with maven. I ended up using GF3.0.1 because GF3.1 has a bug with a jar – I don’t remember which one now sry.. So the server jar is deployed to GF as an EJB jar.

    –the problem
    When I run the client from inside eclipse it works OK. If I package the client to a jar and run it from command line it throws a null pointer exception.. it is thrown in the line `ctx = new InitialContext(props);`

    $ java -Djava.util.logging.config.file=logging.properties -cp client-1.0-jar-with-dependencies.jar gr.stk.testee.client.ConverterClient

    29 – 2011 1:27:19 – com.sun.enterprise.naming.impl.SerialContext
    FINE: SerialContext ==> SerialContext instance created : SerialContext

    java.lang.NullPointerException
    at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:198)
    at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:253)

    Any clues ?
    thanks in advance!

    1. hi Stefanos,
      It’s a little bit hard to see what’s wrong with your application. Because i cant see both your full exception stacktrace and your source code.
      My wild guess is, your application couldnt find Glassfish JNDI, so it throws NullPointerException.

      Do you see this exception?

      Caused by: javax.naming.NameNotFoundException:

  11. hi edwin, thankx for ur example. i tried this. I am able to get the “CompressedEJBServer” in glassfish admin page under “Applications” tab.

    when I ran the client,i could get the InitialContext object but my client code hangs while lookup for the bean (at line 29 in the Main.java under CompressedEJBClient, mentioned above).

    I have done all the configuration but am not able to look up. Also, I am not getting any JNDi external or internal resource on the GF admin console under JNDI tab. Kindly help me for the same.

    1. Hi Avinash,
      are you trying to connect from localhost or from other ip? Perhaps your glassfish port is blocked by firewall. Please paste your configuration here, especially your org.omg.CORBA.ORBInitialHost and org.omg.CORBA.ORBInitialPort.

    1. Hi, Jack Krauser
      Yes, how may i help you? Could you elaborate your problem more specific, Thank you 🙂

  12. Hi Edwin, I am Anderson, from São Paulo, Brazil…
    I did your tutorial but in console i have this error:

    java.lang.NoClassDefFoundError: com/sun/corba/ee/spi/folb/GroupInfoServiceObserver…
    Thanks…….

  13. Hi Edwin…
    First thanks for your code sample.
    I need your help, Can you please give me a guide? I have to build, in my newbie state of java, a complex application. It is a java web application that will be run on the glassfish server. the application runs normally waiting for client browser request like common web based application, Say if client by using browser, requests “localhost:8080/webApplication1/index.faces” then the application on the glassfish server executes the code within “index.faces” page and all corresponding MANAGEBEAN CODE inside “index.faces” page.
    All so far is not really a hard work, but the problem is how to make MANAGEBEAN CODE, that is called earlier, requests some data from another computer, by TCP socket connection like usual client-server app NOT websocket, and then MANAGEBEAN CODE forwards the data to client. and finally as the result the requested data appear on client side.
    Simply description, there would be an architecture like:

    Computer A APP on Glassfih —-> Client(Browser)

    We could say:
    1. Client communicates with Computer A INDIRECTLY through APP on Glassfih in purpose requesting some data.
    2. Computer A and APP on GlashFish communicate each other in two way communication manner. APP on Glafish applies socket server while Computer A uses client socket.
    3. computer-A like can be more than one connecting to APP on Glasfish say Computer A, Computer B…. Computer N! it’s like more than one client connecting to server.
    4. Client can choose what data form which Computer it will request by adding, for example, parameter in the url like “localhost:8080/webApplication1/index.faces?choice=Computer A”

    I don’t know if I have explained the problem well. From my opinion of a java newbie, it’s like combining web App and java socket programming. is it possible? or is there any simple solution?

    Sorry for addressing you my problem but I really need your help…

    Beforehand thank you very much! 🙂

    1. Hi exnesian, yes it’s very possible.
      In my latest app, ive connected Struts application ( a simple web app ) to another server using ISO requests ( socket ).
      basically, the architecure would be like, user — http request –> glassfish app — iso / socket request –> another server
      dont forget, the hard part is how to manage your socket response fast enough, before your http request time out.
      after all, http request is stateless

      i know you can do it, afterall you are an extraordinaryindonesian right? 😉

  14. Hi Edwin. (Subject: Standalone remote java client cannot access EJB3 in Open Source GlassFish3.1.2 running in Eclipse-Helios-OEPE). Any help is appreciated.

    My simple java client:
    —-
    package org.expense.client;

    import java.util.Properties;

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;

    import org.expense.stateless.ExpenseBeanRemote;

    public class ExpenseClient {
    private void standaloneTest()
    {
    try {
    Properties jndiProps = new Properties();
    jndiProps.put(“java.naming.factory.initial”, “com.sun.enterprise.naming.impl.SerialInitContextFactory”);
    jndiProps.put(“java.naming.factory.url.pkgs”, “com.sun.enterprise.naming”);
    jndiProps.put(“java.naming.factory.state”, “com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl”);
    jndiProps.setProperty(“org.omg.CORBA.ORBInitialHost”, “localhost”);
    jndiProps.setProperty(“org.omg.CORBA.ORBInitialPort”, “3700”);
    Context ctx;
    ctx = new InitialContext(jndiProps);
    ExpenseBeanRemote expenseBeanRemote = (ExpenseBeanRemote) ctx.lookup(“java:global/Expense/ExpenseEJB/ExpenseBean”);
    expenseBeanRemote.createItem(“0001”, “ITEM-1”, “I”);
    System.out.println(“Item created….”);
    } catch (NamingException e) {
    System.out.println(“Expense Client Exception: “+e.getMessage());
    e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    ExpenseClient expenseClient = new ExpenseClient();
    expenseClient.standaloneTest();
    }
    }
    —-
    Proof of JNDI in GlassFish server log:
    [#|2012-04-16T12:28:36.146-0400|INFO|glassfish3.0.1|javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions|_ThreadID=11;_ThreadName=Thread-1;|JTS5014: Recoverable JTS instance, serverId = [3700]|#]

    [#|2012-04-16T12:28:36.521-0400|INFO|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=11;_ThreadName=Thread-1;|Portable JNDI names for EJB ExpenseBean : |#]

    [#|2012-04-16T12:28:36.521-0400|INFO|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=11;_ThreadName=Thread-1;|Glassfish-specific (Non-portable) JNDI names for EJB ExpenseBean : [ejb/ExpenseEjb, ejb/ExpenseEjb#org.expense.stateless.ExpenseBeanRemote]|#]
    ————-
    Exception upon program execution:
    java.lang.NullPointerException
    Expense Client Exception: Lookup failed for ‘java:global/Expense/ExpenseEJB/ExpenseBean’ in SerialContext targetHost=localhost,targetPort=3700
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.expense.client.ExpenseClient.standaloneTest(ExpenseClient.java:35)
    at org.expense.client.ExpenseClient.main(ExpenseClient.java:49)
    javax.naming.NamingException: Lookup failed for ‘java:global/Expense/ExpenseEJB/ExpenseBean’ in SerialContext targetHost=localhost,targetPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.expense.client.ExpenseClient.standaloneTest(ExpenseClient.java:35)
    at org.expense.client.ExpenseClient.main(ExpenseClient.java:49)
    Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
    … 3 more
    Caused by: java.lang.NullPointerException
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
    … 4 more
    ————–
    Thanks.

    1. the main error cause would be
      Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException]
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)

      could you please paste here all the jars you’ve included in your project, perhaps the main cause of the error is because of missing libraries.

    2. Thanks Edwin for the clue. I added the missing libraries on the client side; as per your list above in this thread. Also, I had to change my persistence.xml (I’m pasting it for anyone’s reference). It worked for me now. By the way, I would appreciate if you have any sample to use “AppClient” from GlassFish to generate client.
      Thanks again.
      ——-

      org.eclipse.persistence.jpa.PersistenceProvider
      org.expense.jpa.Item
      org.expense.jpa.ItemExpense

      <!–

      –>

      ——-

    3. Hi Shahab, you could check on my latest writings regarding the appclient feature.

  15. persistence.xml
    ——————–

    org.eclipse.persistence.jpa.PersistenceProvider
    org.expense.jpa.Item
    org.expense.jpa.ItemExpense

    1. Hi, Shahab
      sorry, your comment seems not working very well, could you please paste your source to other website such as pastebin, and put the link here.

      Thank You.

  16. Hello evrybody,
    I tried to write almost the same under maven (a maven JEE/EJB-Module and a Java SE Application), unfortunatelly I don’t succed to get a connection from the “client”.
    I am frustrated and feel like a blind: I don’t know the use of all the jars and which to use.
    I tried almost anything.
    Any ideas?? Thank you in advance!

    Meziano

    1. Hi Meziano, could you please paste the error stacktrce you’ve found?
      Thank You

  17. Hello edwin,

    thank you so much for your answer.
    I am sorry for the delay, I was very busy this week.
    I tried ta add the libraries or better the dependencies (when working with maven a library is a dependency, isn’t it?)
    I get the following error message:

    Could not resolve dependencies for project xxx:
    The following artifacts could not be resolved: org.eclipse.persistence:javax.persistence:jar:2.0.3,
    org.eclipse.persistence:org.eclipse.persistence.core:jar:2.3.0,
    org.eclipse.persistence:org.eclipse.persistence.jpa:jar:2.3.0,
    org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen:jar:2.3.0,
    org.eclipse.persistence:org.eclipse.persistence.oracle:jar:2.3.0,
    org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.3.0,
    org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.3.0:
    Failure to find org.eclipse.persistence:javax.persistence:jar:2.0.3
    in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

    I know that this menas I must provide a valide repository, where the artifacts are available.

    I could resolve this problem last week and I got another error, I tried to reproduce this, but I had no time.
    Could you please tell me which dependencies to add and which repositories are valid??

    I have another problem: I am working at a JEE project, the GUI is writting by other persons. I cretaed the database, wrote a Java SE application which contains the entities (I let Netbeans generate these from database and fitted them), wrote the testclasses, wrote the ejbs and tested them.
    I than wrote a stateless webservice in which the other beans are injected.
    I the webservice, I got the expected result: it’s possible to get the list of all instances (rows in the database), get an instance of an instance by ID, update and save it: all CRUD operations are OK.
    In the Client, a Java SE Application, I added a “web service client” by specifying the WSDL URL.
    All what I got are detached objects. Every object with its all fields (as strings) EXCEPT THE ID (Primary Key).
    From an update, I got an insert (cause the edited object has no ID on the client).
    Remove doesn’t work at all.
    Other operations (findAll, findById) are OK.
    Do I have to use DTOs (Data Transfer Objects)??? I read that these are not more needed as of ejb3.1
    On the clients, for a findAll operation, Netbeans does not accept to use the entities: it forces me to use the autogenerated “dtos”, which have the almost the same fileds (except thhe primary key or ID) as the entities but as strings.
    Do I have misunderstand any thing?

    It will be great, and I am thankfull in advance if you could help.

    Meziano

  18. Januel Yee

    Hi Edwin,
    I found your post very helpful and just what we needed on our upcoming project. Unfortunately, while trying to run you example, I encountered these strange error messages:

    run:
    C:\Users\Januel\.netbeans\7.0\var\cache\executor-snippets\run.xml:52: java.io.IOException: Cannot run program “C:\Program Files\Java\jdk1.6.0_22\bin\java.exe” (in directory “D:\My Important Misc. Files\Programming Experiments\Java\J2EE and J2SE Crossbreed\CompressedEJBClient”): CreateProcess error=87, The parameter is incorrect
    at org.apache.tools.ant.taskdefs.Java.fork(Java.java:798)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:214)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
    Caused by: java.io.IOException: Cannot run program “C:\Program Files\Java\jdk1.6.0_22\bin\java.exe” (in directory “D:\My Important Misc. Files\Programming Experiments\Java\J2EE and J2SE Crossbreed\CompressedEJBClient”): CreateProcess error=87, The parameter is incorrect
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at java.lang.Runtime.exec(Runtime.java:593)
    at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
    at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
    at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
    at org.apache.tools.ant.taskdefs.Java.fork(Java.java:791)
    … 19 more
    Caused by: java.io.IOException: CreateProcess error=87, The parameter is incorrect
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
    … 24 more
    Java Result: -1

    I will be looking for some answers online too. Hopefully, you can help me with this error messages. Your example is a very good concept! Your help and advice will be very much appreciated.

    Regards,
    Januel Yee

    1. Hi Januel,
      it happen because your classpath is too long, try shorten it or remove some unnecessary libraries. Here is a short description regarding your error.
      http://stackoverflow.com/questions/2893970/fail-to-launch-application-createprocess-error-87-cant-use-shorten-classpath

  19. Dear edwin,
    we are trying to get this working on the lan but still getting the ComponentException: injection failed on com.sun.enterprise.iiop.security.IIOPSSLUtilImpl.sslUtils Exception. Is there any possibility to get this work on a lan. We have security turned off but still getting this message, thank you very much

    1. Hi Vena,
      looks like it has some issue with the SSL problem. I havent met that kind of error yet, so i cant give any suggestion. Sorry 🙁

  20. May 21, 2012 2:59:36 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
    INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
    log4j:WARN No appenders could be found for logger (com.edw.main.Main).
    log4j:WARN Please initialize the log4j system properly.

  21. Dear Edwin, please can you help me? I use similar thing and everything works fine in Netbeans but when I create the jar from client, I get an ClassNotFoundException: com.sun.corba.ee.spi.folb.GroupInfoserviceObserver, can you suggest what could be wrong, thank you very much.

    1. Hi Vena,
      it seems that you havent include glassfish jar libraries in your jar’s classpath.

    1. Hi Anirban, thank you for your comment.
      Im including all the jars from glassfish because im planning on moving the client’s application to computers which doesnt have any glassfish installation.

  22. Hi Edwin, thank you for your post.
    I have tried your method and it works if I connect to GF on localhost. As soon as I try to connect to remote GF, exception is thrown when calling ctx.lookup.

    WARNING: IOP00410019: Communications timeout waiting for response. Exceeded 1,800,000 milliseconds
    org.omg.CORBA.COMM_FAILURE: WARNING: IOP00410019: Communications timeout waiting for response. Exceeded 1,800,000 milliseconds vmcid: OMG minor code: 19 completed: Maybe

    Remote server is in local network, ORB listener is bound to 0.0.0.0 and is listening on port 3700, I also can telnet to that port.

    1. Hi Gnuce Lee,
      Communication timeout happen because it takes too long for client side’s ejb to find the server’s side.
      have you try to ping -t the target server and see whether there is Read Time Out errors, or try changing the target port? Or using packet sniffer software perhaps, like wireshark or tcpviewer?

      🙂

  23. Hi Edwin, thanks for your helpful post
    But I have a problem. When I create new session bean, I can’t choose the Remote Interface, It said: “There is no suitable project available into which Remote Interface could be” 🙁
    If I skip this by uncheck anything, I can not add the EJB module project to java application project. It said “can’t add cyclic references”.
    And if I create the EJB module after create java application, I can choose Remote Interface but the java package appear in java application project, not in EJB module project like your.
    Please, help!

    1. Hi MCKei,
      try creating an ejb project first, and then include your ejb project into your other java project. It supposed not too hard 😀

  24. Sudhir Dhumal

    Hi Edwin…
    The solution you provided is helpful for me.
    It is working nicely in eclipse IDE when added project containing business interface in classpath.

    but when i tried to run the application from command line got an exception.
    ———-
    Added all the jar files (using eclipse extraction functionality) in single jar.
    ———-

    ——-Stack Trace——-
    java.lang.NullPointerException
    at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:275)
    at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:334)
    at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext(SerialInitContextFactory.java:358)
    at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:353)
    at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:69)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.init(InitialContext.java:242)
    at javax.naming.InitialContext.(InitialContext.java:216)
    at ejb.desktopclient.FetchEJBMessage.main(FetchEJBMessage.java:26)

    1. Hi Sudhir Dhumal,
      i think it because you missed some libraries when you export it into a single jar, please share your complete exception stacktrace.

    2. Hi Edwin,
      I’ve included the all jars in my client , then I got the following exception
      java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.sql.DataSource

    3. Hi Rahul,
      I think it happen because of you are casting javax.naming.Reference to javax.sql.DataSource.
      Could you please share your complete sourcecode?

  25. hi edwin,

    I followed your post and created a client/server application. but when I run I am getting this error.

    Lookup failed for ‘com.jm.facade.ConnectionFacadeRemote’ in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}

    so, I have added all the jars from the modules directory, but still I am getting all these errors.

    can you help me.

    1. Hi rajneekanth, it happens because your client ejb could find your server ejb
      perhaps it’s because of missconfiguration or your glassfish app is not running yet.

  26. escuse me but if i would connect to a ejb that it is behind a router , how i can to get the app client to work?
    the orb communicate always on ip private adress af LAN and not for external IP publi adress.

    1. Hi Mauro,
      try to portforwarding your router to your server’s private ip. So whenever your client app hit your router’s port, your router would directly moved those requests to your server’s local ip.

    1. Can you telnet to the target server’s port? Or is it possible you have firewall blocked your ports on your Ubuntu?

  27. Hello edwin,
    i am still bigginer in ejb, and i am face a confusing to understand deplying ejb session bean project. I am using Eclipse(java EE) and glassfish server 3.1.2, i need to use i web application to deal with my ejb session bean.
    so, can you help me to get started with this point.

    1. Hi msama,
      you can start by trying to connect your web application to your local ejb, using a simple @EJB annotation.

    2. well how about trying to connect to database from your ejb service 🙂

    3. OK. Till now I build a complete application to connect to oracle database using stateless session bean on glassfish server 4 and using JPA to connect database. Everything going fine except one thing that when I try to insert Arabic data using jsp and servlets to DB, it became like this ‘?????’ but when i insert them directly from the application, it’s working fine. I tried to change the encoding but same result. Your advice please and hope don’t late.

    4. hi msama,
      try adding UTF8 CharacterEncoding to your request, or just create a simple servletfilter to do so,

      request.setCharacterEncoding("UTF-8");
      

      while on your jsp, create

      <%@ page pageEncoding="UTF-8" %>
      

      on top of your jsp file.

    5. I tried all this and finally the iso-8859-1 worked fine with some converting and I could insert arabic data correctly to DB. now i found problem, it’s the opposite which I can’t show arabic data on the page while the encoding is iso-8859-1.

  28. Hi, i tried this. when run by Netbean, it’s OK; but when i use CMD command, it got exception:

    C:\Users\mrhie_000\Desktop\Client\dist>java -jar Client.jar
    Exception in thread “main” java.lang.NoClassDefFoundError: com/sun/corba/ee/spi/
    folb/GroupInfoServiceObserver
    at com.sun.enterprise.naming.SerialInitContextFactory.(SerialInitC
    ontextFactory.java:62)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.init(Unknown Source)
    at javax.naming.InitialContext.(Unknown Source)
    at com.edw.main.Main.connect(Main.java:26)
    at com.edw.main.Main.main(Main.java:37)
    Caused by: java.lang.ClassNotFoundException: com.sun.corba.ee.spi.folb.GroupInfo
    ServiceObserver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 13 more
    Can you help me!!! sr for my english is not good…

    1. @@ Wow i update glassfish 4+ @@ it become better but still have an exception @@ help me pls

      Exception in thread “main” java.lang.NoSuchMethodError: com.sun.enterprise.modul
      e.ModulesRegistry.createServiceLocator(Ljava/lang/String;)Lorg/glassfish/hk2/api
      /ServiceLocator;
      at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:102)

      at com.sun.enterprise.naming.impl.SerialInitContextFactory.(Serial
      InitContextFactory.java:130)
      at com.sun.enterprise.naming.SerialInitContextFactory.(SerialInitC
      ontextFactory.java:62)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
      rce)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at java.lang.Class.newInstance0(Unknown Source)
      at java.lang.Class.newInstance(Unknown Source)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      at com.edw.main.Main.connect(Main.java:26)
      at com.edw.main.Main.main(Main.java:37)

    2. Hi MrHieu17,
      it happened because there is incompatibility between your classpath libraries and glassfish’s libraries,
      try to revert back to gf 3.1 instead.

    3. Hi MrHieu17,
      i think you need to include glassfish-corba-internal-api.jar into your classpath 🙂

  29. Hi,

    I run the same above applicatuon using glass fish server 4.1 then i got following error is

    MultiException stack 1 of 8
    java.lang.RuntimeException:java.util.concurrent.ExecutionException:java.lang.NoClassDefFoundError: org/glassfish/orb/admin/config/IiopService
    at org.glassfish.hk2.utilities.cache.LRUHybridCache.compute(LRUHybridCache.java:315)

  30. Henno Vermeulen

    When using Glassfish 4 and Maven you can just include a single dependency to the gf-client-module. It takes care of all the required (transitive) dependencies:

    org.glassfish.main.appclient
    gf-client-module
    4.1.1

  31. Hello Good People

    I have followed every instruction mentioned above my client program works as expected when I run it from my IDE (Netbeans) but as soon as I try running my client from the command prompt I get this error:

    —————————————————————————————————————

    C:\Program Files\Java\jre7>bin\java -jar C:\Users\Selaelo\Documents\NetBeansProjects\GreeterClient\d
    ist\GreeterClient.jar
    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(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at greeterclient.GreeterClient.main(GreeterClient.java:39)
    ————————————————————————————————————

    Please help me I am new to J2EE and I have been stuck with this problem the whole week, I am under a lot of pressure.
    Thanks in advance

    1. Hi Slyza,
      it is issue due to misconfiguration, you need to set the context parameter when doing lookup.

Leave a Reply to Ron Albury Cancel Reply

Your email address will not be published.