EJB3 over SSL in WildFly 10 automation using Apache Maven plugins.

Hi,

In our some of the previous demos we have seen how the WildFly8 onwards we use the “http-remoting” protocol (using default http connector port 8080) in order to invoke the EJBs. That might not be the case when we want to make sire that the EJB client to the EJB server communication happens in a secure fashion. Many times it is desired to invoke the EJBs over SSL. This is because SSL creates an encrypted connection between your EJB application deployed on WildFly and the EJB client allowing the private information to be transmitted without the problems of eavesdropping, data tampering, or message forgery.

The primary reason why SSL is used is to keep sensitive information sent across the Internet encrypted so that only the intended recipient can understand it. This is important because the information you send on the Internet is passed from computer to computer to get to the destination server. Any computer in between you and the server can see your credit card numbers, usernames and passwords, and other sensitive information if it is not encrypted with an SSL certificate. When an SSL certificate is used, the information becomes unreadable to everyone except for the server you are sending the information to. This protects it from hackers and identity thieves.

What this demo is about?

As part of this demo we will learn about the following things:

– 1. How to create client and server keystores using “keytool”.

– 2. How to create a new SSL based security realm on WildFly.

– 3. Setting up the “https” listener for the undertow subsystem using jboss-cli.sh.

– 4. How to configure the “https-remoting-connector” and refer to it from the EJB3 subsystem using jboss-cli.sh.

– 5. Developing and running EJB3 based application with SSL based client using “https-remoting” protocol on 8443 port.

– 6. How to lookup the DataSource from the Nashorn java script and fetch customer table data from database.

– 7. We will also see how to use various maven plugin like “exec-maven-plugin” and WildFly specific “wildfly-maven-plugin”.

– 8. Troubleshooting some common SSL related issues and finding the solution.

Creating Keystores using keytool

Lets create a directory like “EJB_SSL_Wildfly10/keystores” in our filesystem where we are going to keep the generated keystores. Then create a simple shell script which will use the “$JAVA_HOME/bin/keytool” utility to create the server side keystore and the client side truststore. The same shell script will also export the server’s key and it will import that key to the clients truststore.
So lets create the “EJB_SSL_Wildfly10/keystores/createKeyStore.sh” script as following:


########################################
# Creating Server and Client KeyStores.
########################################
# NOTE: "keytool" is a utility that can be found inside the "$JAVA_HOME/bin" so make sire the PATH includes the JDK's bin directory.

WILDFLY_KEYSTORE="middlewaremagic_server.keystore"
CLIENT_TRUSTSTORE="clientTrustStore.keystore"

WILDFLY_STORE_PWD="middleware+magic"
CLIENT_STORE_PWD="middleware+magic+client"

WILDFLY_EXPORTED_CERTIFICATE="middlewaremagic_server.cer"

WILDFLY_STORE_ALIAS="middlewaremagic_server"
CLIENT_STORE_ALIAS="clientalias"

echo ""
echo ""
echo "Creating WildFly Server side Keystore. (${WILDFLY_KEYSTORE})"
echo "----------------------------------------"
keytool -genkey -v -alias ${WILDFLY_STORE_ALIAS} -keyalg RSA -keysize 1024 -keystore ${WILDFLY_KEYSTORE} -validity 3650 -keypass ${WILDFLY_STORE_PWD} -storepass ${WILDFLY_STORE_PWD} -dname "CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, S=Karnataka, C=IN"


echo ""
echo ""
echo "Exporting the key (${WILDFLY_EXPORTED_CERTIFICATE}) from the  WildFly ServerSide keystore."
echo "----------------------------------------"
keytool -export -keystore ${WILDFLY_KEYSTORE} -alias ${WILDFLY_STORE_ALIAS} -file ${WILDFLY_EXPORTED_CERTIFICATE} -keypass ${WILDFLY_STORE_PWD} -storepass ${WILDFLY_STORE_PWD}


echo ""
echo ""
echo "Creating Client side Keystore/truststore. (${CLIENT_TRUSTSTORE})"
echo "----------------------------------------"
keytool -genkey -v -alias ${CLIENT_STORE_ALIAS} -keyalg RSA -keysize 1024 -keystore ${CLIENT_TRUSTSTORE} -validity 3650 -keypass ${CLIENT_STORE_PWD} -storepass ${CLIENT_STORE_PWD} -dname "CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, S=Karnataka, C=IN"


echo ""
echo ""
echo "Importing the WildFLy Servers key ${WILDFLY_EXPORTED_CERTIFICATE} to the Client's truststore ${CLIENT_TRUSTSTORE}."
echo "----------------------------------------"
keytool -import -v -trustcacerts -alias ${WILDFLY_STORE_ALIAS} -file ${WILDFLY_EXPORTED_CERTIFICATE} -keystore ${CLIENT_TRUSTSTORE} -keypass ${CLIENT_STORE_PWD} -storepass ${CLIENT_STORE_PWD}


echo "Certificates created Successfully !!!"

Configuring WildFly 10 to use SSL

As the Keystores/Truststores are created properly hence lets configure the WildFly to use the SSL configuration. We will follow the below steps to achieve the needed configuration:

Step-1). Copy the keystore file “EJB_SSL_Wildfly10/keystores/middlewaremagic_server.keystore” inside the “wildfly-10.0.0.CR5/standalone/configuration” directory.

Step-2). Create an empty file with name “httpsrealm-users.properties” inside the “wildfly-10.0.0.CR5/standalone/configuration” directory. This file we will use to store the user informations for our custom realm “HttpsRealm” related users. These users will be able to invoke the EJBs deployed on WildFly over SSL.

Step-3). Now lets execute the following CLI commands which will configure the “HttpsRealm” and the Https listener along with the required “https-remoting-connector”. So lets start the “$WILDFLY_HOME/bin/jboss-cli.sh” and execute the following commands:


##### 1). Creating SSL based "HttpsRealm"  #####

/core-service=management/security-realm=HttpsRealm/:add
/core-service=management/security-realm=HttpsRealm/server-identity=ssl:add(keystore-path="middlewaremagic_server.keystore", keystore-password="middleware+magic", key-password="middleware+magic", alias="middlewaremagic_server", keystore-relative-to=jboss.server.config.dir)
/core-service=management/security-realm=HttpsRealm/authentication=properties:add(path=httpsrealm-users.properties, relative-to=jboss.server.config.dir, plain-text=false)
:reload

##### 2). Configuring Undertow to add https connector and setting up the "remoting" and "ejb3" subsystems.  #####

/subsystem=undertow/server=default-server/https-listener=default-https/:add(security-realm=HttpsRealm,socket-binding=https,enabled-protocols=TLSv1.2)
/subsystem=remoting/http-connector=https-remoting-connector/:add(connector-ref=default-https,sasl-protocol=remote,security-realm=HttpsRealm)
/subsystem=ejb3/service=remote/:write-attribute(name=connector-ref,value=https-remoting-connector)
:reload

Step-4). Add a user to the “HttpsRealm” using the following command so that the users information will be stored inside the “httpsrealm-users.properties” file.

$ cd /PATH/TO/wildfly-10.0.0.CR5/bin

$ ./add-user.sh --user-properties httpsrealm-users.properties --realm HttpsRealm -u ejbUserOne -p ejbPasswordOne@123

Added user 'ejbUserOne' to file '/PATH/TO//wildfly-10.0.0.CR5/standalone/configuration/httpsrealm-users.properties'
Added user 'ejbUserOne' to file '/PATH/TO//wildfly-10.0.0.CR5/domain/configuration/httpsrealm-users.properties'

Developing EJB3 Application and SSL based Client

Step-5). As we are going to create a Maven based project which will have the “EJB” project and the “EJB client” project modules. Hence lets create the needed directory structure first as following:

$ mkdir -p EJB_SSL_Wildfly10/client/src/main/java/client

$ mkdir -p EJB_SSL_Wildfly10/client/src/main/java/ejb3

$ mkdir -p EJB_SSL_Wildfly10/client/src/main/resources

$ mkdir -p EJB_SSL_Wildfly10/ejb/src/main/java/ejb3

Step-6). Now we will start creating the “MathRemote.java” EJB remote interface inside the “EJB_SSL_Wildfly10/ejb/src/main/java/ejb3” directory as following:

package ejb3;
import javax.ejb.Remote;

@Remote
public interface MathRemote {
	public int add(int x, int y);
	public String sayHello(String name);
}

Step-7). Lets create the Stateless Session Bean the “MathBean.java” inside the “EJB_SSL_Wildfly10/ejb/src/main/java/ejb3” directory as following:

package ejb3;
import javax.ejb.Stateless;
import ejb3.MathRemote;

@Stateless
public class MathBean implements MathRemote {

	public int add(int x, int y){
		int result=x+y;
		System.out.println("[MathBean] add(int x, int y) is called returning : " + result);
		return result;
	}
	
	public String sayHello(String name) {
	    String result = "[MathBean] Hello, " + name;
		System.out.println("[MathBean] sayHello(String "+name+") is called returning : " + result);
		return result;
	}
}

Step-8). As the EJBs are written hence lets write the EJB client code using the WildFly ejb client API based approach. Create a class “StandaloneClient.java” inside the “EJB_SSL_Wildfly10/client/src/main/java/client” as following:

package client;
import ejb3.MathRemote;
import javax.naming.*;
import java.util.*;

public class StandaloneClient {
	public static void main(String args[]) {
          Context context=null;
          String JNDI_NAME="ejb:/EJB_WildFly_Https/MathBean!ejb3.MathRemote"; 
             
          // We are passing the following properties via the maven-exec-plugin
          //System.setProperty("javax.net.ssl.trustStorePassword","middleware+magic+client");
          //System.setProperty("javax.net.ssl.trustStore","/PATH/TO/clientTrustStore.keystore");
          
          try { 
                Properties props = new Properties();
                props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");    
                context = new InitialContext(props);	
                
	            System.out.println("\n\tGot initial Context: "+context);		
           } catch (Exception e) {
                e.printStackTrace();
           }

           try {
		        MathRemote remote=(MathRemote)context.lookup(JNDI_NAME);
	   	        int sum=remote.add(2,10);	
	   	        String result = remote.sayHello("MiddlewareMagic");	
		        System.out.println("\n\t remote.add(2,10) => "+ sum);
		        System.out.println("\n\t remote.sayHello('MiddlewareMagic') => "+ result);		        
    	   } catch(Exception e) {
		       e.printStackTrace();
	       }
	}
}

Step-9). As in the above code we are not using the remote naming based approach to lookup the EJB hence we will need to place a class “jboss-ejb-client.properties” in clients classpath. Hence lets create a file with name “jboss-ejb-client.properties” inside the “EJB_SSL_Wildfly10/client/src/main/resources” directory:

remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8443
remote.connection.default.protocol=https-remoting
remote.connection.default.username=ejbUserOne
remote.connection.default.password=ejbPasswordOne@123

remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS=true
remote.connection.default.connect.options.org.xnio.Options.SSL_PROTOCOL=TLSv1.2
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=true

Step-10). We want to package the “MathRemote.java” interface inside the Client jar hence lets place the “MathRemote.java” interface inside the “EJB_SSL_Wildfly10/client/src/main/java/ejb3” directory so that it will be included in the Client JAR.

package ejb3;
import javax.ejb.Remote;

@Remote
public interface MathRemote {
	public int add(int x, int y);
	public String sayHello(String name);
}

Step-11). Lets create the Main “pom.xml” file inside the “EJB_SSL_Wildfly10” directory which will have the “ejb” and “client” modules defined in it as following:

<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>middleware.magic</groupId>
	<artifactId>EJB_WildFly_Https_Demo</artifactId>
	<packaging>pom</packaging>
	<version>1.0</version>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <version.wildfly.bom>10.0.0.CR2</version.wildfly.bom>
        <version.wildfly-maven-plugin>1.0.2.Final</version.wildfly-maven-plugin>
		<version.jboss.spec.javaee7>1.0.3.Final</version.jboss.spec.javaee7>
        <version.exec.plugin>1.2.1</version.exec.plugin>		
		<maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
	</properties>

    <modules>
        <module>ejb</module>
        <module>client</module>
    </modules>

   <repositories>
        <repository>
            <id>jboss-wildfly-group</id>
            <name>JBoss WildFly Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    
    <pluginRepositories>
        <pluginRepository>
            <id>jboss-wildfly-plugin-group</id>
            <name>JBoss WildFly Maven Plugin Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-7.0</artifactId>
                <version>${version.jboss.spec.javaee7}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-wildfly</artifactId>
                <version>${version.wildfly.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

Step-12). Now Lets create the “pom.xml” for the “ejb” module. Create a file with name “pom.xml” inside “EJB_SSL_Wildfly10/ejb” as following:

<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
    <parent>
    	<groupId>middleware.magic</groupId>
        <artifactId>EJB_WildFly_Https_Demo</artifactId>
        <version>1.0</version>
    </parent>
	<artifactId>EJB_WildFly_Https</artifactId>
	<packaging>jar</packaging>
	<version>1.0</version>
 
    <dependencies>
        <!-- Import the EJB API , Just if needed -->    
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        </dependency>        
        
        <!-- Import the transaction spec API, Just if needed -->
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
        </dependency>
    </dependencies>

	<build>
		<defaultGoal>install</defaultGoal>
		<finalName>${artifactId}</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>${maven.compiler.target}</source>
					<target>${maven.compiler.target}</target>
				</configuration>
			</plugin>
			
            <!-- The WildFly Maven Plugin deploys your war to a local WildFly container -->
            <!-- To use, set the JBOSS_HOME environment variable and run: mvn clean install wildfly:deploy -->
            <plugin>
               <groupId>org.wildfly.plugins</groupId>
               <artifactId>wildfly-maven-plugin</artifactId>
               <version>${version.wildfly-maven-plugin}</version>
            </plugin>
		</plugins>
	</build>

</project>

Step-13). Now we will create the “pom.xml” for the “client” module. So lets create another “pom.xml” file inside the “EJB_SSL_Wildfly10/client” as following:

<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
    <parent>
    	<groupId>middleware.magic</groupId>
        <artifactId>EJB_WildFly_Https_Demo</artifactId>
        <version>1.0</version>
    </parent>
	<artifactId>EJB_WildFly_Https_Client</artifactId>
	<packaging>jar</packaging>
	<version>1.0</version>
 
    <dependencies>
        <!-- Import the EJB API , Just if needed -->    
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
        </dependency>        
        
        <!-- Import the transaction spec API, Just if needed -->
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
        </dependency>
        
        <!-- Needed by the Wildfly EJB Client -->
        <dependency>
	        <groupId>org.wildfly</groupId>
	        <artifactId>wildfly-ejb-client-bom</artifactId>
	        <version>${version.wildfly.bom}</version>
	        <type>pom</type>
	        <scope>runtime</scope>
        </dependency>
        
        <!-- jboss-logging API -->
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <scope>runtime</scope>
        </dependency>

    </dependencies>

	<build>
		<defaultGoal>install</defaultGoal>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>${maven.compiler.target}</source>
					<target>${maven.compiler.target}</target>
				</configuration>
			</plugin>
            <!-- Following plugin will help us in running the Client program mvn exec:exec -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${version.exec.plugin}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions> 
                <configuration>
                    <executable>java</executable>
                       <arguments>
                           <argument>-Xms512m</argument>
                           <argument>-Xmx512m</argument>
                           <argument>-classpath</argument>
                           <classpath/>   
    <!--CHANGE ME!!! -->   <!--argument>-Djavax.net.debug=all</argument -->       <!-- Use this only for debugging purpose -->                                        
    <!--CHANGE ME!!! -->   <argument>-Djavax.net.ssl.trustStorePassword=middleware+magic+client</argument>
    <!--CHANGE ME!!! -->   <argument>-Djavax.net.ssl.trustStore=/Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/keystores/clientTrustStore.keystore</argument>
                           <argument>client.StandaloneClient</argument>                 
                       </arguments>
                </configuration>                
            </plugin>
		</plugins>
	</build>

</project>

Building and Deploying the application

Step-14). Lets build and deploy this application as following , Start WildFly 10 and open a terminal to run the maven build.

Setting up the environment:
For Unix Based OS

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ cd EJB_SSL_Wildfly10
$ mvn clean install

For Windows Based OS

$ set M2_HOME=C:\PATH\TO\apache_maven_3.2.3
$ set JAVA_HOME=C:\PATH\TO\jdk1.8.0_60
$ set PATH=%JAVA_HOME%/bin;C:\PATH\TO\apache_maven_3.2.3\bin;%PATH%

$ cd C:\EJB_SSL_Wildfly10
$ mvn clean install 

Now make sure that wildfly is ruinning on localhost:9990 , run the maven build as following [mvn clean install wildfly:deploy] the wildfly:deploy task will find the running wildfly instance and will automatically deploy the WAR.


$ cd  EJB_SSL_Wildfly10

$ mvn clean install

########
OUTOUT
########

$ mvn clean install 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for middleware.magic:EJB_WildFly_Https:jar:1.0
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] EJB_WildFly_Https_Demo
[INFO] EJB_WildFly_Https
[INFO] EJB_WildFly_Https_Client
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB_WildFly_Https_Demo 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EJB_WildFly_Https_Demo ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ EJB_WildFly_Https_Demo ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https_Demo/1.0/EJB_WildFly_Https_Demo-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB_WildFly_Https 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EJB_WildFly_Https ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EJB_WildFly_Https ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ EJB_WildFly_Https ---
[INFO] Compiling 2 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ EJB_WildFly_Https ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ EJB_WildFly_Https ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ EJB_WildFly_Https ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ EJB_WildFly_Https ---
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/target/EJB_WildFly_Https.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ EJB_WildFly_Https ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/target/EJB_WildFly_Https.jar to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https/1.0/EJB_WildFly_Https-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https/1.0/EJB_WildFly_Https-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB_WildFly_Https_Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EJB_WildFly_Https_Client ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EJB_WildFly_Https_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ EJB_WildFly_Https_Client ---
[INFO] Compiling 2 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ EJB_WildFly_Https_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ EJB_WildFly_Https_Client ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ EJB_WildFly_Https_Client ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ EJB_WildFly_Https_Client ---
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/EJB_WildFly_Https_Client.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ EJB_WildFly_Https_Client ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/EJB_WildFly_Https_Client.jar to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https_Client/1.0/EJB_WildFly_Https_Client-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https_Client/1.0/EJB_WildFly_Https_Client-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] EJB_WildFly_Https_Demo ............................. SUCCESS [  0.214 s]
[INFO] EJB_WildFly_Https .................................. SUCCESS [  0.848 s]
[INFO] EJB_WildFly_Https_Client ........................... SUCCESS [  0.228 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.557 s
[INFO] Finished at: 2016-01-03T23:53:01+05:30
[INFO] Final Memory: 16M/310M
[INFO] ------------------------------------------------------------------------

Deploying EJB project using wildfly-maven-plugin

Step-15). As the project is build not so lets deploy the EJB project to wildfly as following (First move inside the “EJB_SSL_Wildfly10/ejb” directory) and the run the following command:


$ cd  EJB_SSL_Wildfly10/ejb

$ mvn wildfly:deploy

######
OUTPUT
######
$ mvn wildfly:deploy
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for middleware.magic:EJB_WildFly_Https:jar:1.0
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB_WildFly_Https 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) > package @ EJB_WildFly_Https >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EJB_WildFly_Https ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ EJB_WildFly_Https ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ EJB_WildFly_Https ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/ejb/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ EJB_WildFly_Https ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ EJB_WildFly_Https ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ EJB_WildFly_Https ---
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) < package @ EJB_WildFly_Https <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) @ EJB_WildFly_Https ---
Jan 03, 2016 11:55:29 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.2.Final
Jan 03, 2016 11:55:29 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.2.Final
Jan 03, 2016 11:55:29 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.3.Final
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.587 s
[INFO] Finished at: 2016-01-03T23:55:29+05:30
[INFO] Final Memory: 17M/310M
[INFO] ------------------------------------------------------------------------

Once the application is deployed on WildFLy we should be able to see the following output on the WildFly logs/console:

23:55:29,283 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "EJB_WildFly_Https.jar" (runtime-name: "EJB_WildFly_Https.jar")
23:55:29,291 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment EJB_WildFly_Https.jar
23:55:29,301 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'MathBean' in deployment unit 'deployment "EJB_WildFly_Https.jar"' are as follows:

	java:global/EJB_WildFly_Https/MathBean!ejb3.MathRemote
	java:app/EJB_WildFly_Https/MathBean!ejb3.MathRemote
	java:module/MathBean!ejb3.MathRemote
	java:jboss/exported/EJB_WildFly_Https/MathBean!ejb3.MathRemote
	java:global/EJB_WildFly_Https/MathBean
	java:app/EJB_WildFly_Https/MathBean
	java:module/MathBean

23:55:29,306 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0006: Starting Services for CDI deployment: EJB_WildFly_Https.jar
23:55:29,306 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:55:29,307 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:55:29,307 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0009: Starting weld service for deployment EJB_WildFly_Https.jar
23:55:29,308 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:55:29,309 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 64) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
23:55:29,317 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 64) WFLYCLINF0002: Started client-mappings cache from ejb container
23:55:29,390 INFO  [org.jboss.as.server] (management-handler-thread - 6) WFLYSRV0013: Redeployed "EJB_WildFly_Https.jar"
23:55:29,390 INFO  [org.jboss.as.server] (management-handler-thread - 6) WFLYSRV0016: Replaced deployment "EJB_WildFly_Https.jar" with deployment "EJB_WildFly_Https.jar"

Running the SSL based EJB Client project

Step-16). Lets Run the client project in which we are using the WildFly EJB client API based approach to invoke the EJBs deployed on WildFly 10 over SSL. As we have already configured the “maven-exec-plugin” in the client’s pom.xml hence we can run it simply as following: “mvn clean install exec:exec”

$ cd EJB_SSL_Wildfly10/client

$ mvn clean install exec:exec


#######
OUTPUT
#######

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building EJB_WildFly_Https_Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ EJB_WildFly_Https_Client ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EJB_WildFly_Https_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ EJB_WildFly_Https_Client ---
[INFO] Compiling 2 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ EJB_WildFly_Https_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ EJB_WildFly_Https_Client ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ EJB_WildFly_Https_Client ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ EJB_WildFly_Https_Client ---
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/EJB_WildFly_Https_Client.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ EJB_WildFly_Https_Client ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/target/EJB_WildFly_Https_Client.jar to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https_Client/1.0/EJB_WildFly_Https_Client-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/EJB_SSL_Wildfly10/client/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/EJB_WildFly_Https_Client/1.0/EJB_WildFly_Https_Client-1.0.pom
[INFO] 
[INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) @ EJB_WildFly_Https_Client ---

	Got initial Context: javax.naming.InitialContext@2eb481ba
Jan 04, 2016 8:55:34 AM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.2.Final
Jan 04, 2016 8:55:34 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.2.Final
Jan 04, 2016 8:55:34 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.2.Final
Jan 04, 2016 8:55:34 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.14.Final
Jan 04, 2016 8:55:35 AM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Jan 04, 2016 8:55:35 AM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3da9b5c7, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@50dd3b71,channel=jboss.ejb,nodename=banl13bca644a-6]} on channel Channel ID bdd0d839 (outbound) of Remoting connection 1cf9bb77 to localhost/127.0.0.1:8443

	 remote.add(2,10) => 12

	 remote.sayHello('MiddlewareMagic') => [MathBean] Hello, MiddlewareMagic
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.983 s
[INFO] Finished at: 2016-01-04T08:55:35+05:30
[INFO] Final Memory: 14M/245M
[INFO] ------------------------------------------------------------------------

Some Common Issues

Now we can see that in the above example we are able to invoke the EJB deployed on WildFly using the “https-remoting” protocol over SSL on port 8443. However due to some misconfiguration or incorrect approach we might encounter some issues while running the above sample. Here we are going to discuss about those very common issues which you might encounter while invoking EJB3 over SSL on WildFly. So check the “createKeyStore.sh” script commands got executed properly or not. Specially the “keytool -import -v -trustcacerts” command.

Usually to troubleshoot the SSL related issues it is best to run your code is SSL debug mode which can be done simply by adding the following system property to the JVM start options: “-Djavax.net.debug=all”

Issue-1) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException
If you encounter the following error then one of the reason might be that you have not included the Server’s key/certificate in the Client’s truststore.

Jan 03, 2016 6:27:09 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.2.Final
Jan 03, 2016 6:27:09 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.2.Final
Jan 03, 2016 6:27:09 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.2.Final
Jan 03, 2016 6:27:09 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.14.Final
Jan 03, 2016 6:27:09 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to localhost:8443
java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80)
	at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:158)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
	at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:281)
	at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy19.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1336)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:519)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1169)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.xnio.ssl.JsseSslConduitEngine.engineWrap(JsseSslConduitEngine.java:353)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:310)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
	at ...asynchronous invocation...(Unknown Source)
	at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:288)
	at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:404)
	at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78)
	... 16 more
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1703)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:281)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:273)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1446)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:841)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:839)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1273)
	at org.xnio.ssl.JsseSslConduitEngine.handleHandshake(JsseSslConduitEngine.java:543)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:314)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
	at sun.security.validator.Validator.validate(Validator.java:260)
	at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:283)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:138)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1433)
	... 18 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
	... 24 more

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJB_WildFly_Https, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@41016a75
	at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
	at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
	at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
	at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy19.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
	at java.lang.Thread.run(Thread.java:745)

Issue-2) InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
If you encounter the following error then one of the reason might be that you have not entered correct path for the Client trustStore in the “-Djavax.net.ssl.trustStore”. So check the path of your truststore is correct or not and if it has the read permission or not.

Jan 04, 2016 9:04:15 AM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.2.Final
Jan 04, 2016 9:04:15 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.2.Final
Jan 04, 2016 9:04:15 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.2.Final
Jan 04, 2016 9:04:15 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.14.Final
Jan 04, 2016 9:04:16 AM org.xnio.ChannelListeners invokeChannelListener
ERROR: XNIO001007: A channel event listener threw an exception
java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1333)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:519)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1169)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.xnio.ssl.JsseSslConduitEngine.engineWrap(JsseSslConduitEngine.java:353)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:310)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:90)
	at sun.security.validator.Validator.getInstance(Validator.java:179)
	at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:314)
	at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:173)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:241)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:138)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1433)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:841)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:839)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1273)
	at org.xnio.ssl.JsseSslConduitEngine.handleHandshake(JsseSslConduitEngine.java:543)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:314)
	... 10 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
	at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:120)
	at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:104)
	at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:88)
	... 24 more

Jan 04, 2016 9:04:16 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to localhost:8443
java.lang.RuntimeException: java.nio.channels.ClosedChannelException
	at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80)
	at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:158)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
	at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:281)
	at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy0.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:27)
Caused by: java.nio.channels.ClosedChannelException
	at org.xnio.ssl.JsseSslConduitEngine.handleWrapResult(JsseSslConduitEngine.java:401)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:310)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
	at ...asynchronous invocation...(Unknown Source)
	at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:288)
	at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:404)
	at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78)
	... 10 more

Jan 04, 2016 9:04:16 AM org.xnio.ChannelListeners invokeChannelListener
ERROR: XNIO001007: A channel event listener threw an exception
java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1333)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:519)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1169)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.xnio.ssl.JsseSslConduitEngine.engineWrap(JsseSslConduitEngine.java:353)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:310)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:90)
	at sun.security.validator.Validator.getInstance(Validator.java:179)
	at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:314)
	at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:173)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:241)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:138)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1433)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:841)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:839)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1273)
	at org.xnio.ssl.JsseSslConduitEngine.handleHandshake(JsseSslConduitEngine.java:543)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:314)
	... 10 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
	at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
	at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:120)
	at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:104)
	at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:88)
	... 24 more

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJB_WildFly_Https, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@dc8a29
	at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
	at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
	at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
	at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy0.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:27)

Issue-3) DIGEST-MD5: Server rejected authentication
If you encounter the following error then double check if you have created correct user in the correct security-realm using the add-user.sh script or not? Make sure that the user is created properly in the Security Realm which you are using. Foe example in this case check the “wildfly-10.0.0.CR5/standalone/configuration/httpsrealm-users.properties” and validate if the user is created properly in that file or not. If not then create a user using add-user.sh script as following:

$ ./add-user.sh –user-properties httpsrealm-users.properties –realm HttpsRealm -u ejbUserOne -p ejbPasswordOne@123

Jan 03, 2016 7:28:21 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.2.Final
Jan 03, 2016 7:28:21 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.2.Final
Jan 03, 2016 7:28:21 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.2.Final
Jan 03, 2016 7:28:21 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.14.Final
Jan 03, 2016 7:28:22 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to localhost:8443
java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed:
   DIGEST-MD5: Server rejected authentication
	at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80)
	at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:158)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
	at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:281)
	at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy19.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed:
   DIGEST-MD5: Server rejected authentication
	at org.jboss.remoting3.remote.ClientConnectionOpenListener.allMechanismsFailed(ClientConnectionOpenListener.java:114)
	at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:393)
	at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:243)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:199)
	at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:113)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.ChannelListeners$DelegatingChannelListener.handleEvent(ChannelListeners.java:1092)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
	at ...asynchronous invocation...(Unknown Source)
	at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:288)
	at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:404)
	at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78)
	... 16 more

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJB_WildFly_Https, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@58675bc2
	at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
	at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
	at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
	at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy19.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
	at java.lang.Thread.run(Thread.java:745)

Issue-4) CertificateException: No X509TrustManager implementation available
If you encounter the following error then one of the reason might be that you have not entered a correct “trustStorePassword”. Make sure that the truststore password is “-Djavax.net.ssl.trustStorePassword” correct. Again check the “createKeyStore.sh” script to find the correct passwords. Or check if you have your own custom trustStore implementation class defined.

Jan 04, 2016 9:02:05 AM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.2.Final
Jan 04, 2016 9:02:05 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.2.Final
Jan 04, 2016 9:02:05 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.2.Final
Jan 04, 2016 9:02:05 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.14.Final
Jan 04, 2016 9:02:05 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to localhost:8443
java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80)
	at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:158)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
	at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
	at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:281)
	at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:291)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy0.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:27)
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1336)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:519)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1169)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.xnio.ssl.JsseSslConduitEngine.engineWrap(JsseSslConduitEngine.java:353)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:310)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
	at ...asynchronous invocation...(Unknown Source)
	at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:288)
	at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:404)
	at org.jboss.ejb.client.remoting.EndpointPool$PooledEndpoint.connect(EndpointPool.java:192)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:153)
	at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:133)
	at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:78)
	... 10 more
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1703)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:281)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:273)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1446)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:841)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:839)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1273)
	at org.xnio.ssl.JsseSslConduitEngine.handleHandshake(JsseSslConduitEngine.java:543)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:314)
	at org.xnio.ssl.JsseSslConduitEngine.wrap(JsseSslConduitEngine.java:204)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:98)
	at org.xnio.ssl.JsseSslStreamSinkConduit.write(JsseSslStreamSinkConduit.java:72)
	at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:385)
	at org.xnio.http.HttpUpgrade$HttpUpgradeState$StringWriteListener.handleEvent(HttpUpgrade.java:372)
	at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
	at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
	at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:93)
	at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)
Caused by: java.security.cert.CertificateException: No X509TrustManager implementation available
	at sun.security.ssl.DummyX509TrustManager.checkServerTrusted(SSLContextImpl.java:1096)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1433)
	... 18 more

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJB_WildFly_Https, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2da8bc4f
	at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
	at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
	at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
	at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
	at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
	at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
	at com.sun.proxy.$Proxy0.add(Unknown Source)
	at client.StandaloneClient.main(StandaloneClient.java:27)

.

Source code for this demo is present in :
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/EJB/EJB_SSL_Wildfly10
.
.
Regards
Jay SenSharma


Server Side Java Script Nashorn, WildFly10, Undertow with MySQL (part-3)

Hi,

This is the third part of in the series of JavaScript in which we are going to see how to implement the Server Side Java Script inside the WildFly 10 Container. As we know that WildFly provides the “undertow” container inside it. Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO. Undertow has a composition based architecture that allows users to build a web server by combining small single purpose handlers. In order to know more about undertow please refer to: http://undertow.io/

WildFly 10 allows users to use the JavaScript on the server side with the help of the Nashorn JavaScript engine offered by JDK8. So far as part of our previous part-1 and part-2 articles we have learned about Nashorn javascript, jjs command line tool and the JSR-292 APIs which allows us to execute and javascript. If you have not gone through those articles then it is better to have a look at them before we start this demo:

Why Nashorn Java Scripting in Java8, Is it Poisonous for Java? (part-1)

JDK8 Based Nashorn JavaScript & Java to interact with MySQL Database. (part-2)

What this demo is about?

As part of this demo we will learn about the following things:

1. How to create a MySQL DataSource inide the WildFly 10 using jboss-cli.

2. How to include the *.js (java script files) inside the application in WildFly and what is the use of “WEB-INF/undertow-scripts.conf” file.

3. How to execute simple JavaScript inside wildfly/undertow.

4. How to execute Plain JDBC based java script inside the wildfly/undertow.

5. How to lookup the DataSource from the Nashorn java script and fetch customer table data from database.

6. We will also see how to use the “wildfly-maven-plugin” to deploy the Application on Wildfly.

Setting up MySQL Database

Start the MySQL database and then do the following steps which will basically do the following things:
A. Creating a simple Database with name “TestJavaScriptDB”
B. Creating a table with name “CUSTOMER”.
C. Insert some dummy records inside the “CUSTOMER” table.

mysql -u root -p 
password:


mysql> create database TestJavaScriptDB;
Query OK, 1 row affected (0.00 sec)


mysql> use TestJavaScriptDB;
Database changed


mysql> CREATE TABLE CUSTOMER (custId INT(10) NOT NULL, custName CHAR(20) NOT NULL);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO CUSTOMER VALUES (1000, "MiddlewareMagic");
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO CUSTOMER VALUES (2000, "Customer-2");
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO CUSTOMER VALUES (3000, "Customer-3");
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM CUSTOMER;
+--------+-----------------+
| custId | custName        |
+--------+-----------------+
|   1000 | MiddlewareMagic |
|   2000 | Customer-2      |
|   3000 | Customer-3      |
+--------+-----------------+
3 rows in set (0.01 sec)

Creating DataSource on WildFly10 side.

Now lets create a simple MySQL datasource using jboss-cli.sh script provided by WildFly.

[standalone@localhost:9990 /] module add --name=com.mysql  --dependencies=javax.api,javax.transaction.api --resources=/PATH/TO/mysql-connector-java-5.1.37-bin.jar 


[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql/:add(driver-module-name=com.mysql,driver-name=mysql,jdbc-compliant=false,driver-class-name=com.mysql.jdbc.Driver) 
{"outcome" => "success"}

[standalone@localhost:9990 /] /subsystem=datasources/data-source="MySqlDS":add(jndi-name="java:jboss/MySqlDS",driver-name="mysql",connection-url="jdbc:mysql://localhost:3306/TestJavaScriptDB",user-name="root",password="testpwd")
{"outcome" => "success"}

[standalone@localhost:9990 /] :reload
{
    "outcome" => "success",
    "result" => undefined
}

[standalone@localhost:9990 /] /subsystem=datasources/data-source="MySqlDS":test-connection-in-pool()
{
    "outcome" => "success",
    "result" => [true]
}

Once the above jboss-cli commands are executed we should be able to see the following kind of DataSource created inside our wildfly profile (i am using “standalone.xml”).

        <subsystem xmlns="urn:jboss:domain:datasources:4.0">
            <datasources>
                <datasource jndi-name="java:jboss/MySqlDS" pool-name="MySqlDS">
                    <connection-url>jdbc:mysql://localhost:3306/TestJavaScriptDB</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>root</user-name>
                        <password>testpwd</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="mysql" module="com.mysql">
                        <driver-class>com.mysql.jdbc.Driver</driver-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

Developing WebApplication containing the Nashorn Script

Now lets start developing the WebApplication so in order to do that lets create some directory structure and to understand where we are going to place which file.

Step-1). Create a directory “Part-3_WildFly_ServerSide_JavaScript” some there in your filesystem.

mkdir Part-3_WildFly_ServerSide_JavaScript

mkdir -p Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/WEB-INF

Step-2). Now lets write the “hello.js” simple script inside the “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/” directory as following, Where we will define the resource uri “/hello” and its actions.

$undertow.onGet("/hello",
                  { headers: {"content-type": "text/plain"}},
                      [function ($exchange) {
                         return "Hello, MiddlewareMagic!!!";
                   }])

Step-3). Similarly we will write another javascript inside the “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/” directory with name “testDB.js”. This is a simple javascript file which uses the plain JDBC approach to interact with the Database.

//  ## JDBC Based JavaScript  ##

$undertow
    .onGet("/getCustomerRecords",
        {headers: {"content-type": "text/plain"}},
        [function ($exchange) {
            var con1 = getConnection();
            var customerData = runQuery(con1, "select * from CUSTOMER");
            return "Got Customer Data: " + customerData;
        }])
        
     
     
//  Java Script Functions  //        
var getConnection = function() {
    var Properties = Java.type("java.util.Properties");
    var Driver = Java.type("com.mysql.jdbc.Driver");
    var driver = new Driver();
    var properties = new Properties();
    var conn = null;
    try {
        properties.setProperty("user", "root");
        properties.setProperty("password", "testpwd");
        conn = driver.connect("jdbc:mysql://localhost:3306/TestJavaScriptDB", properties);
        print("****** Got the JDBC Connection : " +conn);
        return conn;
    } finally {
    }
}

// Declaring runQuery function
var runQuery = function(conA, query) {
   var result = "";
   try {
       var stmt = conA.prepareStatement(query);
       var resultSet = stmt.executeQuery();
       print("      --------------------------- ");
       while (resultSet.next()) {
          result = result + " [";
          var rowData = resultSet.getString("custId") + " - " + resultSet.getString("custName");
          print("\t" + rowData);
          result = result + rowData + "], "; 
       }
       print("      --------------------------- ");
       return result;
    } finally {
      if (resultSet)
         try {
            resultSet.close();
            print("\nResultSet Closed.");
         }
         catch(e) {}
      if (stmt)
         try {
            stmt.close();
            print("Statement Closed.");            
         } catch (e) { print( e );  }
      if (conA)        
         try { 
            conA.close();
            print( "Connection Closed." );
         } catch (e) { print( e );  }          
      }  
 } 

//  Following Cals are commended else those wil be executed as soon as WildFly startes deploying this WebApplication.
//var con1 = getConnection();
//runQuery(con1, "select * from CUSTOMER");

Step-4). As above we have seen a plain JDBC interaction based javascript. However we want to use the DataSource concept as well in order to interact with the Database. So here we will be writing another simple Hava Script file “testDataSource.js” inside the directory “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/” directory with name “testDB.js” and will performa simple JNDI lookup of the DataSource. This shows that we do not need to write so lengthy java scripts as mentioned above in order to interact with the database.

$undertow
    .onGet("/getCustomersViaDataSource",
        {headers: {"content-type": "application/json"}},
        ['jndi:java:jboss/MySqlDS', function ($exchange, db) {
            return db.select("select * from CUSTOMER");
        }])

Step-5). Lets write a simple “index.jsp” page which will have the URL of the above mentioned javascript Get Resources. Lets place this index.jsp file inside the “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp” directory as following:

<HTML>
  <HEAD>
     </TITLE>Nashorn Server Side Java Script Demo Undertow/WildFly</TITLE>
  </HEAD>
  <BODY>
     <Center>

<h3>This is a simple demo explaining how to use Server Side Java Script in WildFly</h3>

       <a href="hello">Click Here to execute to "/hello" resource</a>
       <BR/><BR/>
       <a href="getCustomerRecords">Click Here "/getCustomerRecords" to access customers records from Database</a>  
       <BR/><BR/>
       <a href="getCustomersViaDataSource">Click Here "/getCustomersViaDataSource" to access customers records from Database via DataSource lookup</a>         
      </Center>      
  </BODY>
</HTML>   

Step-6). If needed then we can add the “web.xml” file inside the “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/WEB-INF” as following (in my case as i do not have anything specific to be written in this file so i am keeping a dummy file here)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> 
</web-app>

Step-7). Now the Most important part. We are going to add the file “undertow-scripts.conf” inside the “Part-3_WildFly_ServerSide_JavaScript/src/main/webapp/WEB-INF”

hello.js
testDB.js
testDataSource.js

NOTE: We need to tell WildFly/Undertow container that where to find our javascript files. So in order to do this we create a file “WEB-INF/undertow-scripts.conf”. In this file we list all our server side JavaScript files one per line. See: http://undertow.io/undertow-docs/undertow-docs-1.3.0/index.html

Step-8). Now we will simply write our Maven “pom.xml” file to build the WAR file containing all the above contents in it and it will also use the “wildfly-maven-plugin<” plugin which will help us in deploying it on WildFly (running on localhost:9990). So lets create “pom.xml” file inside the “Part-3_WildFly_ServerSide_JavaScript” directory as following:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>middleware.magic</groupId>
  <artifactId>WildFlyServerSideJavaScript</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>
  <name>WildFlyServerSideJavaScript</name>
  
  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
        <version.wildfly.bom>10.0.0.CR2</version.wildfly.bom>
        <version.wildfly-maven-plugin>1.0.2.Final</version.wildfly-maven-plugin>
        
        <!-- Compiler Related versions -->
        <version.war.plugin>2.5</version.war.plugin>
        <version.maven.compiler.plugin>3.3</version.maven.compiler.plugin>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
  </properties>  
  
  
  <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>jboss-javaee-7.0-wildfly</artifactId>
            <version>${version.wildfly.bom}</version>
            <scope>import</scope>
         </dependency>
      </dependencies>
  </dependencyManagement> 

  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.37</version>
   </dependency>
  </dependencies>
  
  <build>
   <finalName>WildFlyServerSideJavaScript</finalName>   <!-- WAR name -->
   <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${version.maven.compiler.plugin}</version>
        <configuration>
          <source>${maven.compiler.target}</source>
          <target>${maven.compiler.source}</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>${version.war.plugin}</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
        
        <!-- The WildFly Maven Plugin deploys your war to a local WildFly container -->
        <!-- To use, set the JBOSS_HOME environment variable and run: mvn package wildfly:deploy -->
      <plugin>
         <groupId>org.wildfly.plugins</groupId>
         <artifactId>wildfly-maven-plugin</artifactId>
         <version>${version.wildfly-maven-plugin}</version>
      </plugin>
   </plugins>
  </build>
  
</project>

Building and Deploying the application

Lets build and deploy this application as following , Start WildFly default profile “standalone.xml” and open a terminal to run the maven build.

Setting up the environment:
For Unix Based OS

$ export M2_HOME=/PATH/TO/apache_maven_3.2.3
$ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
$ export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$PATH

$ cd Part-3_WildFly_ServerSide_JavaScript
$ mvn clean install

For Windows Based OS

$ set M2_HOME=C:\PATH\TO\apache_maven_3.2.3
$ set JAVA_HOME=C:\PATH\TO\jdk1.8.0_60
$ set PATH=%JAVA_HOME%/bin;C:\PATH\TO\apache_maven_3.2.3\bin;%PATH%

$ cd C:\Part-3_WildFly_ServerSide_JavaScript
$ mvn clean install 

Now make sure that wildfly is ruinning on localhost:9990 , run the maven build as following [mvn clean install wildfly:deploy] the wildfly:deploy task will find the running wildfly instance and will automatically deploy the WAR.


$ mvn clean install wildfly:deploy

########
OUTOUT
########
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for middleware.magic:WildFlyServerSideJavaScript:war:1.0
[WARNING] 'dependencyManagement.dependencies.dependency.type' for org.wildfly.bom:jboss-javaee-7.0-wildfly:jar must be 'pom' to import the managed dependencies. @ line 28, column 22
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WildFlyServerSideJavaScript 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WildFlyServerSideJavaScript ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WildFlyServerSideJavaScript ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ WildFlyServerSideJavaScript ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WildFlyServerSideJavaScript ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ WildFlyServerSideJavaScript ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WildFlyServerSideJavaScript ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.5:war (default-war) @ WildFlyServerSideJavaScript ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WildFlyServerSideJavaScript] in [/Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target/WildFlyServerSideJavaScript]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/main/webapp]
[INFO] Webapp assembled in [54 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target/WildFlyServerSideJavaScript.war
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WildFlyServerSideJavaScript ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target/WildFlyServerSideJavaScript.war to /Users/jsensharma/.m2/repository/middleware/magic/WildFlyServerSideJavaScript/1.0/WildFlyServerSideJavaScript-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WildFlyServerSideJavaScript/1.0/WildFlyServerSideJavaScript-1.0.pom
[INFO] 
[INFO] >>> wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) > package @ WildFlyServerSideJavaScript >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WildFlyServerSideJavaScript ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ WildFlyServerSideJavaScript ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WildFlyServerSideJavaScript ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ WildFlyServerSideJavaScript ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WildFlyServerSideJavaScript ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-war-plugin:2.5:war (default-war) @ WildFlyServerSideJavaScript ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WildFlyServerSideJavaScript] in [/Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target/WildFlyServerSideJavaScript]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/src/main/webapp]
[INFO] Webapp assembled in [5 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WildFly/JavaScript/Java_8_Nashorn_WildFly/Part-3_WildFly_ServerSide_JavaScript/target/WildFlyServerSideJavaScript.war
[INFO] 
[INFO] <<< wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) < package @ WildFlyServerSideJavaScript <<<
[INFO] 
[INFO] --- wildfly-maven-plugin:1.0.2.Final:deploy (default-cli) @ WildFlyServerSideJavaScript ---
Nov 27, 2015 4:18:54 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.2.Final
Nov 27, 2015 4:18:55 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.2.Final
Nov 27, 2015 4:18:55 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.3.Final
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.741 s
[INFO] Finished at: 2015-11-27T16:18:55+05:30
[INFO] Final Memory: 14M/245M
[INFO] ------------------------------------------------------------------------

Source code for this demo is present in :
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/Java_8/ServerSideJavaScript/Part-3_WildFly_ServerSide_JavaScript
.
.
Regards
Jay SenSharma


JDK8 Based Nashorn JavaScript & Java to interact with MySQL Database. (part-2)

Hi,

As part of out previous article “Why Nashorn Java Scripting in Java8, Is it Poisonous for Java? (part-1)”, We discussed some very basics of JDK8, Nashorn Java Script and about the “$JAVA_HOME/bin/jjs” command line tool. We also learned that how we can invoke a JavaScript snippet or script file from inside a java code and Also how to use the Java APIs inside a simple Java Script code.

So now lets move a step ahead and see how to interact with the Database using Nashorn Java Script. In this demo we will extensively focus on how to use various java APIs and java packages inside the Nashorn Script.

What this demo is about?

As part of this demo we will learn about the following things:

1. How to create a Database and some sample tables in MySQL database.

2. How to write a simple Nashorn Java Script to interact with MySQL.

3. How to execute the Nashorn Script using jjs.

4. How to Invoke the Nashorn Java Script from inside a java code.

Other Parts of this articles are:

Why Nashorn Java Scripting in Java8, Is it Poisonous for Java? (part-1)

Server Side Java Script Nashorn, WildFly10, Undertow with MySQL (part-3)

Setting up MySQL Database

Start the MySQL database and then do the following steps which will basically do the following things:
A. Creating a simple Database with name “TestJavaScriptDB”
B. Creating a table with name “CUSTOMER”.
C. Insert some dummy records inside the “CUSTOMER” table.

mysql -u root -p 
password:


mysql> create database TestJavaScriptDB;
Query OK, 1 row affected (0.00 sec)


mysql> use TestJavaScriptDB;
Database changed


mysql> CREATE TABLE CUSTOMER (custId INT(10) NOT NULL, custName CHAR(20) NOT NULL);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO CUSTOMER VALUES (1000, "MiddlewareMagic");
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO CUSTOMER VALUES (2000, "Customer-2");
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO CUSTOMER VALUES (3000, "Customer-3");
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM CUSTOMER;
+--------+-----------------+
| custId | custName        |
+--------+-----------------+
|   1000 | MiddlewareMagic |
|   2000 | Customer-2      |
|   3000 | Customer-3      |
+--------+-----------------+
3 rows in set (0.01 sec)

Writing Nashorn JavaScript

Now lets start writing the Java Script to interact with the Database. So lets create a file “testDB.js” somewhere in the filesystem as following:

//  ## JDBC Based JavaScript  ##

// Declaring the getConnection function
var getConnection = function() {
    var Properties = Java.type("java.util.Properties");
    var Driver = Java.type("com.mysql.jdbc.Driver");
    var driver = new Driver();
    var properties = new Properties();
    var conn = null;
    try {
        properties.setProperty("user", "root");
        properties.setProperty("password", "testpwd");
        conn = driver.connect("jdbc:mysql://localhost:3306/TestJavaScriptDB", properties);
        return conn;
    } finally {
    
    }
}

print("****** conn : " + getConnection());

// Declaring the runQuery function
function runQuery(conA, query) {
   try {
       var stmt = conA.prepareStatement(query);
       var resultSet = stmt.executeQuery();
       print("      --------------------------- ");
       while (resultSet.next()) {
          print("\t" + resultSet.getString("custId") + " - "+ resultSet.getString("custName"))
       }
       print("      --------------------------- ");
       
    } finally {
      if (resultSet)
         try {
            resultSet.close();
            print("\nResultSet Closed.");
         }
         catch(e) {}
      if (stmt)
         try {
            stmt.close();
            print("Statement Closed.");            
         } catch (e) { print( e );  }
      if (conA)        
         try { 
            conA.close();
            print( "Connection Closed." );
         } catch (e) { print( e );  }          
      }  
 } 


// Invoking the getConnection and runQuery() functions.
var con1 = getConnection();
runQuery(con1, "select * from CUSTOMER");

Running testDB.js script using jjs

As we know that JDK8 provides the “jjs” utility as part of “$JAVA_HOME/bin” directory which is a command line utility to execute the Nashorn Java Script. Here we will be using that utility to run the testDB.js script. Open a terminal and then run the following commands in order to set the JDK8 in the path.

Unix Based OS

export JAVA_HOME=/PATH/TO/jdk1.8.0_60
export PATH=$JAVA_HOME/bin/jjs:$PATH

Windows Based OS

set JAVA_HOME=C:\jdk1.8.0_60
set PATH=%JAVA_HOME%\bin;%PATH%

After setting the path lets run the Java Script.

$ jjs -cp /PATH/TO/mysql-connector-java-5.1.37-bin.jar:.: testDB.js 

****** conn : com.mysql.jdbc.JDBC4Connection@384ad17b
      --------------------------- 
	1000 - MiddlewareMagic
	2000 - Customer-2
	3000 - Customer-3
      --------------------------- 

ResultSet Closed.
Statement Closed.
Connection Closed.

NOTICE: while running the “testDB.js” script make sure to set the Classpath using the “-cp” option provided by “jjs” utility.
Windows users need to use “;” semi colon rather than using the “:” Colon while defining the classpath. as following:
-cp C:\PATH\TO\mysql-connector-java-5.1.37-bin.jar;.;

If users will not set the classpath properly then it will throw the following kind of error because it won’t be able to find the MySQL JDBC Driver.

$ jjs testDB.js 

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397)
	at jdk.nashorn.tools.Shell.apply(Shell.java:397)
	at jdk.nashorn.tools.Shell.runScripts(Shell.java:326)
	at jdk.nashorn.tools.Shell.run(Shell.java:172)
	at jdk.nashorn.tools.Shell.main(Shell.java:136)
	at jdk.nashorn.tools.Shell.main(Shell.java:112)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1051)
	at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:493)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:322)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:310)
	at jdk.nashorn.internal.scripts.Script$Recompilation$1$65$testDB.getConnection(testDB.js:5)
	at jdk.nashorn.internal.scripts.Script$testDB.:program(testDB.js:19)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
	... 5 more

Invoking testDB.js script from Java code

Just now we have seen that how we can use the “$JAVA_HOME/bin/jjs” command line utility in order to execute the Nashorn JavaScript. Now we will write a simple java code using the “javax.script.ScriptEngineManager” and “javax.script.ScriptEngine” APIs.
Hence lets write a java program “ExampleNashornJdbc.java” somewhere in the filesystem as following:

import javax.script.*;
import java.io.*;

public class ExampleNashornJdbc {
	public static void main(String ar[]) throws Exception {
		ScriptEngineManager enginManager = new ScriptEngineManager();
		ScriptEngine engine = enginManager.getEngineByName("Nashorn");
		try {
			// Executing a simple java script file
			FileReader javaScriptFileReader = new FileReader(new File("testDB.js"));
            engine.eval(javaScriptFileReader);
            
		 } catch(final ScriptException se) {
			se.printStackTrace();
		 }
	}
}

Running Java ScriptEngine to execute testDB.js

Lets run the above code which will internally evaluate the “testDB.js” script.

$ java -cp /PATH/TO/mysql-connector-java-5.1.37-bin.jar:.: ExampleNashornJdbc
****** conn : com.mysql.jdbc.JDBC4Connection@7c729a55
      --------------------------- 
	1000 - MiddlewareMagic
	2000 - Customer-2
	3000 - Customer-3
      --------------------------- 

ResultSet Closed.
Statement Closed.
Connection Closed.

Do not forget to append the “.” in the classpath “-cp” else java virtual machine will search for the ExampleNashornJdbc class also inside the same “mysql-connector-java-5.1.37-bin.jar” and it wont find that class there ;).

If the Classpath is not set properly with the JDBC driver jar included in it then you may see the following kind of exception:

$ java ExampleNashornJdbc


Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397)
	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
	at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
	at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:150)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
	at ExampleNashornJdbc.main(ExampleNashornJdbc.java:11)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1051)
	at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:493)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:322)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314)
	at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:310)
	at jdk.nashorn.internal.scripts.Script$Recompilation$1$65$\^eval\_.getConnection(<eval>:5)
	at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:19)
	at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
	at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
	at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
	... 6 more

Source code for this demo is present in :
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/Java_8/ServerSideJavaScript/Part-2-Jdbc

.
.
Regards
Jay SenSharma


Copyright © 2010-2012 Middleware Magic. All rights reserved. |