3

I can't find a simple example of code for a Java standalone client obtaining a valid InitialContext from WildFly. Does it exist?

I gave up on Glassfish 4 because Oracal will never fix its JMS problem (the real reason I need WildFly's Context. Now I'm failing with WildFly.

I'm sure one simple example would help a lot of people new to WildFly. (Note: Not getting WildFly's Context from an Enterprise container. Getting it from a standalone Java client -- so it can then implement JMS messaging.)

Here's the code as trivial as I know how to make it.

Minor related question: How do I kill the Derby not available warning. Everyone says it need derbycleint.jar. S0 I put that (and derby-driver.jar) literally everywhere. Still get the warning.

Primary question: I can't find a set of properties needed by new IntialContext (env). It seems to need security credentials of some kind. I just can't find where to start looking and reading to figure out what I need to do. Any help? (I'd like to find simple code that works, because it would sure help other WildFly newbies get started. Even add the JMS part since Glassfish is out of the picture for that.)

CODE:

package org.america3.wildfly.jms;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import com.sun.messaging.ConnectionFactory;

public class JMSSendAndReceive {

  static Hashtable<String, String> jndiProperties = new Hashtable<String,String>() {
    private static final long serialVersionUID = 1L;
    {
      put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      /*after posting I added these properties*/
        put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
      /*That produced CONSOLE 2 below for new result -- DERBY is gone!
         I think all that's needed is to get
         org.jboss.naming.remote.client.InitialContextFactory 
         into the Eclipse build path.

         No luck.  That led to adding addtional classes 
         ... see commments below.
         They led to CONSOLE 3 output that offers no hope at all.
         I give up. Can anyone help?
       */
     }
  };

  static public void main (String[] args) {
    System.out.println("AS_DERBY_INSTALL: " + System.getenv("AS_DERBY_INSTALL"));
    System.out.println("JAVA_HOME: " + System.getenv("JAVA_HOME"));
    try {
      final Context context = new InitialContext(jndiProperties);
      ConnectionFactory factory = (ConnectionFactory) context.lookup("java:comp/DefaultJMSConnectionFactory");
      System.out.println(factory);
    } catch (Exception e) {
      System.out.println("Try Failed");
      System.out.println(e.getClass().getName());
      System.out.println(e.getMessage());
    }
  }

  /*
   * derbyclient.jar and derby-driver.jar are stored in these files:
   * <WILDFLY_HOME>\standalone\deployments
   * <WILDFLY_HOME>\standalone\deployments\lib
   * C:\Program Files\Java\jdk1.8.0_05\lib
   * C:\Program Files\Java\jdk1.8.0_05\jre\lib
   * 
   * The entire Derby API and derby-driver.jar are also added to the Eclipse 
   * build path for this class.
   * 
   * Adding these to Eclipse build produced CONSOLE 3
   * <WILDFLY_HOME>\modules\system\layers\base\org\jboss\remote-naming\main\jboss-remote-naming-2.0.4.Final.jar
   * <WILDFLY_HOME>\modules\system\layers\base\org\jboss\xnio\main\xnio-api-3.3.1.Final.jar
   * <WILDFLY_HOME>\modules\system\layers\base\org\jboss\remoting\main\jboss-remoting-4.0.9.Final.jar
   * <WILDFLY_HOME>\\modules\system\layers\base\org\jboss\ejb-client\main\jboss-ejb-client-2.1.1.Final.jar
   */

   /*
    *Tracked these down

   */

}

CONSOLE:

AS_DERBY_INSTALL: D:\Bulletproof\bpDerby
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_05
Nov 03, 2015 2:40:35 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700  vmcid: OMG  minor code: 1  completed: No
    at com.sun.proxy.$Proxy20.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:253)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:276)
    at com.sun.corba.ee.impl.transport.ContactInfoImpl.createConnection(ContactInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.beginRequest(ClientRequestDispatcherImpl.java:242)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.request(ClientDelegateImpl.java:220)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.is_a(ClientDelegateImpl.java:378)
    at org.omg.CORBA.portable.ObjectImpl._is_a(Unknown Source)
    at org.omg.CosNaming.NamingContextHelper.narrow(Unknown Source)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1205)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:393)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at com.sun.enterprise.connectors.jms.system.DefaultJMSConnectionFactory.handle(DefaultJMSConnectionFactory.java:83)
    at com.sun.enterprise.naming.impl.NamedNamingObjectManager.tryNamedProxies(NamedNamingObjectManager.java:134)
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:164)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.america3.wildfly.jms.JMSSendAndReceive.main(JMSSendAndReceive.java:25)
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:344)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:250)
    ... 20 more
Caused by: java.net.ConnectException: Connection refused: connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Unknown Source)
    at sun.nio.ch.Net.connect(Unknown Source)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:110)
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:329)
    ... 21 more
Try Failed
javax.naming.NamingException
Lookup failed for 'java:comp/DefaultJMSConnectionFactory' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

CONSOLE 2:

AS_DERBY_INSTALL: D:\Bulletproof\bpDerby
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_05
Try Failed
javax.naming.NoInitialContextException
Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory

CONSOLE 3:

AS_DERBY_INSTALL: D:\Bulletproof\bpDerby
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_05
Nov 03, 2015 4:11:12 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.1.Final
Try Failed
javax.naming.NamingException
Failed to create remoting connection
George
  • 509
  • 2
  • 9
  • 25
  • Does this example help? https://github.com/wildfly/quickstart/blob/10.x/helloworld-jms/src/main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java – James R. Perkins Nov 05 '15 at 16:56

1 Answers1

2

You can try these, they are mainly of JBoss but it's the same as wildfly:

http://www.mastertheboss.com/jboss-server/jboss-as-7/jboss-as-7-remote-ejb-client-tutorial

or

https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

or

http://javahowto.blogspot.com/2012/05/standalone-java-client-for-jboss-as-711.html

reos
  • 8,766
  • 6
  • 28
  • 34
  • I appreciate the suggestion but its the same problem: #1 uses the env property in my first try;#2 is for a remote client running in an container; #3 Same thing - a client deployed in a container inside WildFly. I think one problem is with "Standalone" Java client. I need JMS messaging between an app deployed in Wildfly and a java program launched from a browser via WebStart. Not running in an EE container. I'm starting to wonder if its possilble anymore. Did it 4 years ago with GF 2. Now can't get JMS from GF or Payara or WildFly. Thanks again. – George Nov 05 '15 at 01:10
  • In your StackTrace you have Caused by: java.net.ConnectException: Connection refused: connect. Did you try making a telnet to the IP/port of the EJB server ? – reos Nov 05 '15 at 13:32
  • No. I'm sure esoteric workarounds exist, but that's always been my problem with JBoss. It's made for high end server-side folks, so Its documentation writers no longer understand beginners need to start simple, because in their world only those "into" JBoss forever exist. Anyway, WildFly runs on local host with Java client on same machine so telnet feels out of place as a way for the Java client to get WF's context to get a JMS connection and swap messages. Old GF made it simple till Oracal messed up. My gut says env needs an ID & PW or something security related. But don't know what. – George Nov 06 '15 at 02:15