13 Replies Latest reply on Jun 26, 2013 9:13 PM by imen

    problem with jndi (java.naming.factory.initial)

    imen

      Hello,

      i'm trying to develop a server-client application with EJB and a swing-client.

      i'm working with Jboss developper studio and jboss 7.1.1-final

      here is my EJB class:

      package com.sagem.src;

       

       

      import javax.ejb.Stateless;

      import javax.swing.JDialog;

      import javax.swing.JFrame;

      import javax.swing.SwingUtilities;

      import com.sagem.interfaces.IApplication;

      import com.sagem.util.UniqueInstance;

       

       

      @Stateless

      public class Application implements IApplication{

       

       

                          /**

                           * Launch the application.

                           */

                public void LaunchApplication(final JFrame frame,JDialog dialog){

       

       

       

                          if (ControlUniqueInstance(frame)){

                                    frame.setVisible(true);

       

                          }

                          else{

                                    //bloquer toutes les fenêtres

                                    try {

                                                        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

                                                        dialog.setVisible(true);

                                              } catch (Exception e) {

                                                        e.printStackTrace();

                                              }

       

       

                }

                          }

       

       

                /**

                 * contrôle s'il y a une autre instance de l'application qui tourne

                 * **/

         public boolean ControlUniqueInstance(final JFrame Mainform){

                          final int PORT = 32145;

                          final String MESSAGE = "nomDeMonApplication";

                          final Runnable RUN_ON_RECEIVE = new Runnable() {

                              public void run() {

                                  SwingUtilities.invokeLater(new Runnable() {

                                      public void run() {

                                          if(Mainform != null) {

                                                    System.out.printf("if(MainForm != null) \n");

                                              if(!Mainform.isVisible())

                                                  Mainform.setVisible(true);

                                              System.out.printf("if(!MainForm.isVisible()) \n");

                                                  Mainform.toFront();

                                          }

                                      }

                                  });

                              }                  

                          };

                          

                          UniqueInstance uniqueInstance = new UniqueInstance(PORT, MESSAGE, RUN_ON_RECEIVE);

                          return uniqueInstance.launch();

      }

       

       

        

         public void KillAppli(){

                   //débloquer toutes les fenêtres

                   System.exit(-1);

                   System.out.println("Kill appli!!!!!!!!!!");

         }

       

       

      }

       

       

       

      and this is the interface:

       

      package com.sagem.interfaces;

       

       

      import javax.ejb.Remote;

      import javax.swing.JDialog;

      import javax.swing.JFrame;

       

       

      @Remote

      public interface IApplication {

       

       

                void LaunchApplication(JFrame frame,JDialog dialog);

       

       

                boolean ControlUniqueInstance(JFrame Mainform);

       

                void KillAppli();

       

       

      }

       

       

      and this is my swing client (the part where i invoke the EJB class)

       

      public static void main(String[] args) {

                          EventQueue.invokeLater(new Runnable() {

                                    public void run() {

                                    Application appli = null;

                                              try {

                                                        Main frame = new Main();

       

                                                        /***********************connexion EJB - Invocation de la méthode launch******************************************/

                                              try {

                                                                        

                                              InitialContext context = new InitialContext();

                                              System.out.println("initial context done!!!!!!!!");

                                              appli = (Application) context.lookup("/SGMpack_EJB_Project/Application!com.sagem.interfaces.IApplication");

                                                           }

                                                        catch (NamingException e)

                                                        {e.printStackTrace();}

       

                                              AlerteInstanceDouble dialog = new AlerteInstanceDouble();

                                              appli.LaunchApplication(frame, dialog);  

                                               }

                                              catch (Exception e) {e.printStackTrace();}

                                    }

                                                              });

                                                                  };

       

       

      i placed my jndi.properties file under the source package of my client

      here is it's content:

       

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

      java.naming.provider.url=remote://localhost:4447

      java.naming.security.principal=remote

      java.naming.security.credentials=testpassword


      when i run my application i'm getting the following error:

      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 com.sagem.FormInit.Main.main(Main.java:42)

        • 1. Re: problem with jndi (java.naming.factory.initial)
          imen

          i'm really desperate, couldn't figure out the problem, already read https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI and checked out redhat tutorial about jboss 7.1.1....

           

          does any one have i idea

          PS: sorry if my english is bad, it would be easier for me if any one here can speack french. but any help is welcome even in chinese ^^

          • 2. Re: problem with jndi (java.naming.factory.initial)
            imen

            please, is there anyone to help me?

            • 3. Re: problem with jndi (java.naming.factory.initial)
              wdfink

              Hi,

               

              as you use the remote-naming you should read https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

               

              From the behaviour it look like that your jndi.properties are not used.

              What if you put

              java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

              java.naming.provider.url=remote://localhost:4447

              java.naming.security.principal=remote

              java.naming.security.credentials=testpassword

              into Properties programatic and pass it to the new InitalContext(...)

              • 4. Re: problem with jndi (java.naming.factory.initial)
                imen

                thank you sooooo much for your answer,

                this is my new client (swing):

                public static void main(String[] args) {

                                    EventQueue.invokeLater(new Runnable() {

                                              public void run() {

                                              Application appli = null;

                                                        try {

                                                                  Main frame = new Main();

                 

                                                                  /***********************connexion EJB - Invocation de la méthode launch******************************************/

                                                        try {

                                                                                  

                                                                  Properties jndiProps = new Properties();

                                                                  jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                                                                  jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");

                                                                  // create a context passing these properties

                                                                  Context ctx = new InitialContext(jndiProps);       

                  appli = (Application) ctx.lookup("/SGMpack_EJB_Project/Application!"+IApplication.class.getCanonicalName());

                                                                     }

                                                                  catch (NamingException e)

                                                                  {e.printStackTrace();}

                 

                                                        AlerteInstanceDouble dialog = new AlerteInstanceDouble();

                                                        appli.LaunchApplication(frame, dialog);  

                                                         }

                                                        catch (Exception e) {e.printStackTrace();}

                                              }

                                                                        });

                                                                            };

                 

                 

                now i'm getting the following error:

                javax.naming.NameNotFoundException: SGMpack_EJB_Project/IApplication!sgmpack.ejb.application.Interfaces.IApplication -- service jboss.naming.context.java.jboss.exported.SGMpack_EJB_Project."IApplication!sgmpack.ejb.application.Interfaces.IApplication"

                          at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

                          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)

                          at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)

                          at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

                          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                          at java.lang.Thread.run(Unknown Source)

                java.lang.NullPointerException

                          at com.sagem.FormInit.Main$1.run(Main.java:56)

                          at java.awt.event.InvocationEvent.dispatch(Unknown Source)

                          at java.awt.EventQueue.dispatchEventImpl(Unknown Source)

                          at java.awt.EventQueue.access$200(Unknown Source)

                          at java.awt.EventQueue$3.run(Unknown Source)

                          at java.awt.EventQueue$3.run(Unknown Source)

                          at java.security.AccessController.doPrivileged(Native Method)

                          at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)

                          at java.awt.EventQueue.dispatchEvent(Unknown Source)

                          at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

                          at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

                          at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

                          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

                          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

                          at java.awt.EventDispatchThread.run(Unknown Source)

                • 5. Re: problem with jndi (java.naming.factory.initial)
                  sfcoy

                  Your problems are a lot deeper than JNDI issues.

                   

                  You cannot create server-side Swing components and render them in any kind of client application, remote or local.

                   

                  See §12.2.2 of the EJB 3.1 specification:

                  {quote}• An enterprise bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard.{quote}

                  • 6. Re: problem with jndi (java.naming.factory.initial)
                    imen

                    it seems that the problem is my computer...

                    this is what a jee developper to whom i showed my application told me

                    so now i'll format my comuter and see

                     

                    thank you for your help, i'll keep you informed, maybe this won't resolve the problem

                    • 7. Re: problem with jndi (java.naming.factory.initial)
                      sfcoy

                      That does not change the fact that what you are trying to do cannot and will not work.

                      • 8. Re: problem with jndi (java.naming.factory.initial)
                        imen

                        well you are right, that didn't resolve my problem.

                         

                        i created a java project and tried to use it as my client.

                        here is the code of my client java:

                         

                        public class TestInvocation {

                         

                                  public static void main(String[] args) {

                            IApplication appli=null; 

                             try {

                        InitialContext context = new InitialContext();

                                              System.out.println("initial context done!!!!!!!!");

                                                    appli = (IApplication) context.lookup("/SGMpackaging_EJB/Application!com.sagem.Interfaces.IApplication");

                                                    System.out.println("EJB call Done!!!!!!!!");          }

                                                              catch (NamingException e)

                                                              {e.printStackTrace();}

                                                                                                                         

                        }}

                         

                        this didn't work neither!!!

                        i get the following error:

                         

                        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(NamingManager.java:662)

                                  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

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

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

                                  at invocation.TestInvocation.main(TestInvocation.java:15)

                         

                        please help me i'm going crazy!!!! oO

                        • 9. Re: problem with jndi (java.naming.factory.initial)
                          imen

                          i tried to insert directly the jndi parameters this way:

                           

                            public class TestInvocation {

                           

                                    public static void main(String[] args) {

                              IApplication appli=null; 

                               try {

                                        

                                         Properties props = new Properties();

                          props.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");

                          props.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");

                          props.put("java.naming.provider.url","remote://127.0.0.1:4447");

                          props.put("jboss.naming.client.ejb.context","true");

                          props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");

                          InitialContext context = new InitialContext(props);

                                        

                                                System.out.println("initial context done!!!!!!!!");

                                                      appli = (IApplication) context.lookup("/SGMpackaging_EJB/Application!com.sagem.Interfaces.IApplication");

                                                      System.out.println("EJB call Done!!!!!!!!");          }

                                                                catch (NamingException e)

                                                                {e.printStackTrace();}

                                                                 

                          }}

                           

                          it worked, only have the following warning:

                          WARN: Unsupported message received with header 0xffffffff

                           

                          so i have 2 questions:

                          1- what does this warning mean?

                          2- why doesn't my application see the jndi file (i placed it directly under my project and here is a snapshot of it):

                          snapshot.jpg

                          • 10. Re: problem with jndi (java.naming.factory.initial)
                            imen

                            i tried the same thing in my swing client (inserting directly the jndi properties) and i've gor the following errors:

                             

                            juin 27, 2013 2:02:16 AM org.xnio.Xnio <clinit>

                            INFO: XNIO Version 3.0.3.GA

                            juin 27, 2013 2:02:16 AM org.xnio.nio.NioXnio <clinit>

                            INFO: XNIO NIO Implementation Version 3.0.3.GA

                            juin 27, 2013 2:02:16 AM org.jboss.remoting3.EndpointImpl <clinit>

                            INFO: JBoss Remoting version 3.2.3.GA

                            juin 27, 2013 2:02:17 AM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                            INFO: Received server version 1 and marshalling strategies [river]

                            juin 27, 2013 2:02:17 AM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                            INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6e22f51b, receiver=Remoting connection EJB receiver [connection=Remoting connection <354c3f42>,channel=jboss.ejb,nodename=imen-pc]} on channel Channel ID ba653be4 (outbound) of Remoting connection 43bf9dec to /127.0.0.1:4447

                            juin 27, 2013 2:02:17 AM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

                            WARN: Unsupported message received with header 0xffffffff

                            juin 27, 2013 2:02:18 AM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd

                            ERROR: Channel end notification received, closing channel Channel ID e702d868 (outbound) of Remoting connection 43bf9dec to /127.0.0.1:4447

                            juin 27, 2013 2:02:18 AM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleEnd

                            INFO: Channel Channel ID ba653be4 (outbound) of Remoting connection 43bf9dec to /127.0.0.1:4447 can no longer process messages

                            java.lang.reflect.UndeclaredThrowableException

                                      at com.sun.proxy.$Proxy0.LaunchApplication(Unknown Source)

                                      at com.sagem.Forms.MainForm$1.run(MainForm.java:45)

                                      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)

                                      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)

                                      at java.awt.EventQueue.access$200(EventQueue.java:103)

                                      at java.awt.EventQueue$3.run(EventQueue.java:688)

                                      at java.awt.EventQueue$3.run(EventQueue.java:686)

                                      at java.security.AccessController.doPrivileged(Native Method)

                                      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)

                                      at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)

                                      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)

                                      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)

                                      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

                                      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)

                                      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

                                      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

                            Caused by: java.io.IOException: Stream is closed

                                      at org.xnio.streams.BufferPipeOutputStream.closed(BufferPipeOutputStream.java:61)

                                      at org.xnio.streams.BufferPipeOutputStream.checkClosed(BufferPipeOutputStream.java:67)

                                      at org.xnio.streams.BufferPipeOutputStream.write(BufferPipeOutputStream.java:85)

                                      at org.jboss.remoting3.remote.OutboundMessage.write(OutboundMessage.java:168)

                                      at java.io.DataOutputStream.write(DataOutputStream.java:88)

                                      at org.jboss.ejb.client.remoting.AbstractMessageWriter$1.write(AbstractMessageWriter.java:78)

                                      at java.io.OutputStream.write(OutputStream.java:116)

                                      at org.jboss.marshalling.OutputStreamByteOutput.write(OutputStreamByteOutput.java:56)

                                      at org.jboss.marshalling.UTFUtils.writeUTFBytes(UTFUtils.java:135)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeUTF(RiverMarshaller.java:1460)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewSerializableClass(RiverMarshaller.java:1371)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewClass(RiverMarshaller.java:1292)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeClass(RiverMarshaller.java:1146)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeObjectArrayClass(RiverMarshaller.java:1140)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewClass(RiverMarshaller.java:1287)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeClass(RiverMarshaller.java:1146)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewSerializableClass(RiverMarshaller.java:1373)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewClass(RiverMarshaller.java:1292)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeClass(RiverMarshaller.java:1146)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewSerializableClass(RiverMarshaller.java:1380)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewClass(RiverMarshaller.java:1292)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeClass(RiverMarshaller.java:1146)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewSerializableClass(RiverMarshaller.java:1380)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewClass(RiverMarshaller.java:1292)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeClass(RiverMarshaller.java:1146)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeNewSerializableClass(RiverMarshaller.java:1373)

                                      at org.jboss.marshalling.river.RiverMarshaller.writeSerializableClass(RiverMarshaller.java:1345)

                                      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:883)

                                      at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62)

                                      at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:119)

                                      at org.jboss.ejb.client.remoting.MethodInvocationMessageWriter.writeMessage(MethodInvocationMessageWriter.java:105)

                                      at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.processInvocation(RemotingConnectionEJBReceiver.java:199)

                                      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:179)

                                      at org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43)

                                      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)

                                      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)

                                      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)

                                      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)

                                      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

                                      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

                                      ... 16 more

                            Caused by: an exception which occurred:

                                      in object com.sagem.Forms.MainForm@7a711bc2

                             

                            so formatting my computer did help somehow.... but i still have a problem somewhere

                             

                            any ideas please?

                            • 11. Re: problem with jndi (java.naming.factory.initial)
                              imen

                              i placed my jndi.properties file under the source package.

                              now my code seem to "see" it. and i get the same errors as when i insert the parameters in the code.

                               

                              PS: sorry if i am sending too much messages but i'm in a hurry (this is my end of studies project)

                              • 12. Re: problem with jndi (java.naming.factory.initial)
                                sfcoy

                                Please have a look at http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/ejb-remote/ and get that working.

                                 

                                After that, try to build up your Swing client using the client code above as a start.

                                 

                                DO NOT USE ANY SWING OR AWT COMPONENTS IN THE SERVER SIDE (EJB) CODE. It will not work!

                                • 13. Re: problem with jndi (java.naming.factory.initial)
                                  imen

                                  ok i'll do that

                                  thank you very much for helping me