WebLogic12c with t3s (SSL) secure protocol and the JMX client

Hi,

As part of this article we will see how to use the “t3s” SSL based secure protocol to interact with WebLogic 12.2.1. We will be developing a simple MBean client which will access sime of the MBeans present on weblogic over the SSL. We are going to implement One Way SSL for this demo. With one-way SSL, the server must present a certificate to the client, but the client is not required to present a certificate to the server. The client must authenticate the server, but the server accepts a connection from any client. One-way SSL is common on the Internet where customers want to create secure connections before they share personal data. Often, clients will also use SSL to log on in order that the server can authenticate them.

Secure Sockets Layer (SSL) provides secure connections by allowing two applications connecting over a network to authenticate each other’s identity and by encrypting the data exchaoged between the applications. Authentication allows a server and optionally a client to verify the identity of the application on the other end of a network connection. Encryption makes data transmitted over the network intelligible only to the intended recipient.

What this demo is about ?

As part of this demo we will see how to use implement One way SSL on weblogic so that a Client can interact with it using https/t3s in a secure manner.

1. How to configure the “CustomIdentityAndJavaStandardTrust” on weblogic, In a complete automated way using WLST scripting.

2. How to configure the SSL port on WebLogic 12.2.1 using WLST.

3. How to create Server side Keystore and Client side truststore.

4. Running a simple MBean Client which will use “t3s” protocol to access/query the MBeans which are present on WLS server.

5. Troubleshooting some very common issues which users might encounter while implementing SSL on WebLogic 12c.

Creating Keystores and Truststore.

Step-1). Lets create a simple keystore which will be deployed on the WLS side and then we will be exporting the public key from that which will be imported on the Client side truststore. In order to simplify the keystore and truststore creation and importing / exporting the certificates, We will be writing a very simple shell script. Please change the store password and keystore/truststore file name based on your choice.
Create a shell script “createKeyStore.sh” somewhere in your filesystem 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.

mkdir Keystores
cd Keystores/

echo ""
echo ""
echo "Creating WLS Server side Keystore. (wls12c.keystore)"
echo "----------------------------------------"
keytool -genkey -v -alias wlsalias -keyalg RSA -keysize 1024 -keystore wls12c.keystore -validity 3650 -keypass middleware+magic -storepass middleware+magic -dname "CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, S=Karnataka, C=IN"


echo ""
echo ""
echo "Exporting public key (wls12c_server.cer) from the  WLS ServerSide keystore."
echo "----------------------------------------"
keytool -export -keystore wls12c.keystore -alias wlsalias -file wls12c_server.cer -keypass middleware+magic -storepass middleware+magic


echo ""
echo ""
echo "Creating Client side Keystore/truststore. (clientTrustStore.keystore)"
echo "----------------------------------------"
keytool -genkey -v -alias clientalias -keyalg RSA -keysize 1024 -keystore clientTrustStore.keystore -validity 3650 -keypass middleware+magic+client -storepass middleware+magic+client -dname "CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, S=Karnataka, C=IN"


echo ""
echo ""
echo "Importing the WLS Servers public key to the Client's truststore."
echo "----------------------------------------"
keytool -import -v -trustcacerts -alias wlsalias -file wls12c_server.cer -keystore clientTrustStore.keystore -keypass middleware+magic+client -storepass middleware+magic+client


echo "Certificates created Successfully !!!"

Step-2). Lets run the above mentioned Shell script which will create the needed keystores and truststores. It also imports the servers public key to the client truststore. “keytool” is a utility that can be found inside the “$JAVA_HOME/bin” so make sire the PATH includes the JDK’s bin directory.

$ cd WLST_and_Keys
$ chmod 755 createKeyStore.sh
$ ./createKeyStore.sh 

--------
Output:
--------
$ ./createKeyStore.sh 


Creating WLS Server side Keystore. (wls12c.keystore)
----------------------------------------
Generating 1,024 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 3,650 days
	for: CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, ST=Karnataka, C=IN
[Storing wls12c.keystore]


Exporting public key (wls12c_server.cer) from the  WLS ServerSide keystore.
----------------------------------------
Certificate stored in file <wls12c_server.cer>


Creating Client side Keystore/truststore. (clientTrustStore.keystore)
----------------------------------------
Generating 1,024 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 3,650 days
	for: CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, ST=Karnataka, C=IN
[Storing clientTrustStore.keystore]


Importing the WLS Servers public key to the Client's truststore.
----------------------------------------
Owner: CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, ST=Karnataka, C=IN
Issuer: CN=127.0.0.1, OU=MiddlewareMagic, O=Blog, L=Bangalore, ST=Karnataka, C=IN
Serial number: 66f456cb
Valid from: Sun Dec 27 19:27:29 IST 2015 until: Wed Dec 24 19:27:29 IST 2025
Certificate fingerprints:
	 MD5:  5A:C2:83:32:24:80:58:0D:A6:1F:68:88:5D:42:F8:C5
	 SHA1: 14:1A:32:08:25:C6:58:DA:37:35:50:FF:5C:D0:DD:F0:26:E5:2E:2E
	 SHA256: 6F:A3:4B:AA:37:D5:47:2C:21:F2:77:92:C6:B6:8C:A4:B2:D9:60:C2:5A:26:E2:A7:32:C5:5B:88:22:84:76:85
	 Signature algorithm name: SHA256withRSA
	 Version: 3

Extensions: 

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 34 6C E7 FE E7 15 B1 DC   99 A9 EB 22 B5 A8 C1 1D  4l........."....
0010: 98 E3 1D B8                                        ....
]
]

Trust this certificate? [no]:  yes
Certificate was added to keystore
[Storing clientTrustStore.keystore]
Certificates created Successfully !!! 

Configuring CustomIdentityAndJavaStandardTrust using WLST

Step-3). Now we will create a simple WLST script “configure_SSL_and_KeyStore.py” which will configure the “CustomIdentityAndJavaStandardTrust” on WebLogic 12c. It will configure the WLS12c to open the HTTPS/SSL port “7443”.

adminURL="t3://localhost:7001"
adminUserName="weblogic"
adminPassword="weblogic1"

connect(adminUserName, adminPassword, adminURL)

edit()
startEdit()
cd('/Servers/AdminServer')
cmo.setKeyStores('CustomIdentityAndJavaStandardTrust')
cmo.setCustomIdentityKeyStoreFileName('/Users/jsensharma/NotBackedUp/Installed/wls1221/user_projects/domains/base_domain/Keystores/wls12c.keystore')
cmo.setCustomIdentityKeyStoreType('jks')
cmo.setCustomIdentityKeyStorePassPhrase('middleware+magic')
activate()
startEdit()

startEdit()
cd('/Servers/AdminServer/SSL/AdminServer')
cmo.setServerPrivateKeyAlias('wlsalias')
cmo.setServerPrivateKeyPassPhrase('middleware+magic')
cmo.setEnabled(true)
cmo.setListenPort(7443)
activate()

Step-4). Now we will start the WebLogic 12.2.1 instance and then we will open a terminal to run the above mentioned WLST script. We will run the “setWLSEnv.sh” script in the terminal first so that it will set the CLASSPATH properly with the required JARs. (or simply use the “wls1221/wlserver/common/bin/wlst.sh” script to start the WLST)

$ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin

$ . ./setWLSEnv.sh 
CLASSPATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/tools.jar:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/modules/features/wlst.wls.classpath.jar:
PATH=/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/modules/org.apache.ant_1.9.2/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin
Your environment has been set.


$ cd WLST_and_Keys

$ java weblogic.WLST configure_SSL_and_KeyStore.py


-------
OUTPUT
-------
$ java weblogic.WLST configure_SSL_and_KeyStore.py 

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server "AdminServer" that belongs to domain "two_ssl_domain".

Warning: An insecure protocol was used to connect to the server. 
To ensure on-the-wire security, the SSL port or Admin port should be used instead.

Location changed to edit tree. 	 
This is a writable tree with DomainMBean as the root. 	 
To make changes you will need to start an edit session via startEdit(). 
For more help, use help('edit').

Starting an edit session ...
Started edit session, be sure to save and activate your changes once you are done.
Activating all your changes, this may take a while ... 
The edit lock associated with this edit session is released once the activation is completed.

The following non-dynamic attribute(s) have been changed on MBeans 
that require server re-start:
MBean Changed : com.bea:Name=AdminServer,Type=Server
Attributes changed : CustomIdentityKeyStoreFileName, CustomIdentityKeyStorePassPhraseEncrypted, CustomIdentityKeyStoreType, KeyStores

Activation completed
Starting an edit session ...
Started edit session, be sure to save and activate your changes once you are done.
Starting an edit session ...
Started edit session, be sure to save and activate your changes once you are done.
Activating all your changes, this may take a while ... 
The edit lock associated with this edit session is released once the activation is completed.

The following non-dynamic attribute(s) have been changed on MBeans 
that require server re-start:
MBean Changed : com.bea:Name=AdminServer,Type=SSL,Server=AdminServer
Attributes changed : ServerPrivateKeyAlias, ServerPrivateKeyPassPhraseEncrypted

Activation completed

Step-5). As configuring the SSL on weblogic is a non dynamic change hence we will need to restart the WebLogic 12c instance. We can verify the same by looking at the WebLogic 12c console as following:

<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute CustomIdentityKeyStoreFileName on weblogic.management.configuration.ServerMBeanImpl@77977041([two_ssl_domain]/Servers[AdminServer]) has been changed. This may require redeploying or rebooting configured entities.> 
<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141238> <A non-dynamic change has been made which affects the server AdminServer. This server must be rebooted in order to consume this change.> 
<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute CustomIdentityKeyStoreFileName on weblogic.management.configuration.ServerMBeanImpl@77977041([two_ssl_domain]/Servers[AdminServer]) has been changed. This may require redeploying or rebooting configured entities.> 
<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute ServerPrivateKeyAlias on weblogic.management.configuration.SSLMBeanImpl@5bbd5356([two_ssl_domain]/Servers[AdminServer]/SSL[AdminServer]) has been changed. This may require redeploying or rebooting configured entities.> 
<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141238> <A non-dynamic change has been made which affects the server AdminServer. This server must be rebooted in order to consume this change.> 
<Dec 27, 2015 7:42:24 PM IST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute ServerPrivateKeyAlias on weblogic.management.configuration.SSLMBeanImpl@5bbd5356([two_ssl_domain]/Servers[AdminServer]/SSL[AdminServer]) has been changed. This may require redeploying or rebooting configured entities.> 

So we will need to restart the WebLogic 12c instance (in our case AdminServer). After restarting the WebLogic Server we will notice the following kind of output on the Console which indicates that the KeyStore is configured properly.

<Dec 27, 2015 7:42:57 PM IST> <Notice> <Security> <BEA-090171> <Loading the identity certificate and private key stored under the alias wlsalias from the jks keystore file /Users/jsensharma/NotBackedUp/Installed/wls1221/user_projects/domains/base_domain/Keystores/wls12c.keystore.> 

<Dec 27, 2015 7:42:57 PM IST> <Notice> <Security> <BEA-090169> <Loading trusted certificates from the jks keystore file /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/security/cacerts.> 
<Dec 27, 2015 7:42:57 PM IST> <Warning> <Server> <BEA-002611> <The hostname "localhost", maps to multiple IP addresses: 127.0.0.1, 0:0:0:0:0:0:0:1.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[3]" is now listening on 127.0.0.1:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 10.0.1.101:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[1]" is now listening on 10.0.1.101:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 0:0:0:0:0:0:0:1:7001 for protocols iiop, t3, ldap, snmp, http.> 

<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[2]" is now listening on 0:0:0:0:0:0:0:1:7443 for protocols iiops, t3s, ldaps, https.> 

<Dec 27, 2015 7:42:57 PM IST> <Warning> <Server> <BEA-002611> <The hostname "jaysensharma.local", maps to multiple IP addresses: 168.253.130.227, fe80:0:0:0:9a5a:ebff:fecb:7e2e%12.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 168.253.130.227:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure" is now listening on 168.253.130.227:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <WebLogicServer> <BEA-000331> <Started the WebLogic Server Administration Server "AdminServer" for domain "two_ssl_domain" running in development mode.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[3]" is now listening on 127.0.0.1:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 127.0.0.1:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 10.0.1.101:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[1]" is now listening on 10.0.1.101:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 0:0:0:0:0:0:0:1:7001 for protocols iiop, t3, ldap, snmp, http.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure[2]" is now listening on 0:0:0:0:0:0:0:1:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 168.253.130.227:7001 for protocols iiop, t3, ldap, snmp, http.> 

<Dec 27, 2015 7:42:57 PM IST> <Notice> <Server> <BEA-002613> <Channel "DefaultSecure" is now listening on 168.253.130.227:7443 for protocols iiops, t3s, ldaps, https.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.> 
<Dec 27, 2015 7:42:57 PM IST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.> 

Writing “t3s” based Secure WebLogic 12c JMX Client

Step-6). Now lets create a simple MBean client code which will interact with WebLogic using “t3s” secure protocol. We are going to use the Maven to build and run out project. So lets create the following directory structure somewhere in our filesystem first. Here the “SSL_JMX” is our project directory:

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

Now lets create the following kind of JMX code “SecureJMXClient.java” inside “SSL_JMX/src/main/java/client” directory.

package client;
import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;
import weblogic.management.runtime.ServerRuntimeMBean;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.management.jmx.MBeanServerInvocationHandler;
import java.util.Hashtable;
import java.io.IOException;
import java.net.MalformedURLException;
import weblogic.management.runtime.JDBCDataSourceRuntimeMBean;
import javax.management.*;
import javax.naming.*;
 
public class SecureJMXClient {
 
   private static MBeanServerConnection connection;
   private static JMXConnector connector;
   private static final ObjectName service;
   private static String combea = "com.bea:Name=";
   private static String service1 = "DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
   private static String service2 = "RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean";
 
   static {
        try {
               service =new ObjectName(combea + service1);
        } catch (MalformedObjectNameException e) {
               throw new AssertionError(e.getMessage());
        }
   }
 
   public static void initConnection(String hostname, String portString, String username, String password) throws IOException,MalformedURLException {
    String protocol = "t3s";
    Integer portInteger = Integer.valueOf(portString);
    int port = portInteger.intValue();
    String jndiroot = "/jndi/";
    String mserver = "weblogic.management.mbeanservers.domainruntime";
    JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);
    Hashtable h = new Hashtable();
    h.put(Context.SECURITY_PRINCIPAL, username);
    h.put(Context.SECURITY_CREDENTIALS, password);
    h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
    connector = JMXConnectorFactory.connect(serviceURL, h);
    connection = connector.getMBeanServerConnection();
   }
 
   public static ObjectName[] getServerRuntimes() throws Exception {
        return (ObjectName[]) connection.getAttribute(service,"ServerRuntimes");
    }
 
   public void printNameAndState() throws Exception {
    ObjectName arr[]=getServerRuntimes();       
    for(ObjectName temp : arr)
        System.out.println("Servers: "+temp);
 
    ObjectName domain = (ObjectName) connection.getAttribute(service,"DomainConfiguration");
    System.out.println("Domain: " + domain.toString());
    ObjectName[] servers = (ObjectName[]) connection.getAttribute(domain,"Servers");
    for (ObjectName server : servers) {
        String serverState="UNKNOWN";
        String aName = (String) connection.getAttribute(server,"Name");
        try {
            ObjectName ser= new ObjectName("com.bea:Name="+aName+",Location="+aName+",Type=ServerRuntime");
            serverState=(String) connection.getAttribute(ser,"State");
            System.out.println("Server: "+aName+"t State: "+serverState);
         } catch(Exception e) {
            System.out.println("Server: "+aName+"t State: SHUTDOWN (or) In State : "+ serverState);
         }
      }
    }
 
  public static void main(String[] args) throws Exception {
    String hostname   = "localhost";    // CHANGE ME !!!
    String portString = "7443";         // CHANGE ME !!!
    String username   = "weblogic";     // CHANGE ME !!!
    String password   = "weblogic1";    // CHANGE ME !!!
    
    SecureJMXClient s = new SecureJMXClient();
    initConnection(hostname, portString, username, password);
    s.printNameAndState();
    connector.close();
   }
 }

Step-7). Now the most important part in which we will be writing the maven “pom.xml” which will compile and build the above Java code and will package them as part fo a JAR file. We will be using the “exec-maven-plugin” maven plugin in this pom sothat we can easily run the project via “mvn clean install exec:exec”

<?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>JMX_Over_SSL</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>1.7</java.version>
        <middleware.home>/Users/jsensharma/NotBackedUp/Installed/wls1221</middleware.home> <!-- CHANGE ME !!! -->
    </properties>
    
    <dependencies>
        <dependency>
        	<groupId>weblogic</groupId>
        	<artifactId>wlthint3client.needed.jars</artifactId>
        	<version>1.0</version>
            <scope>system</scope>   
            <systemPath>${middleware.home}/wlserver/server/lib/wlthint3client.jar</systemPath>     	
        </dependency>   
        <dependency>
        	<groupId>weblogic</groupId>
        	<artifactId>com.bea.core.management.jmx.jars</artifactId>
        	<version>1.0</version>
            <scope>system</scope>   
            <systemPath>${middleware.home}/wlserver/modules/com.bea.core.management.jmx.jar</systemPath>     	
        </dependency>   
        <dependency>
        	<groupId>weblogic</groupId>
        	<artifactId>wls-api.jars</artifactId>
        	<version>1.0</version>
            <scope>system</scope>   
            <systemPath>${middleware.home}/wlserver/server/lib/wls-api.jar</systemPath>     	
        </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.3.2</version>
               <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
               </configuration>
            </plugin>

            <!-- Allows the example to be run via 'mvn compile exec:exec' -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <configuration>
                    <executable>java</executable>
                       <arguments>
                           <argument>-Davax.net.ssl.trustStorePassword=middleware+magic+client</argument>         <!-- CHANGE ME !!! -->
                           <argument>-Djavax.net.ssl.trustStore=${basedir}/ClientKey/client.keystore</argument>   <!-- CHANGE ME !!! -->
                           <argument>-classpath</argument>
                           <!-- UNIX Based OS use the following classpath setting -->                             <!-- CHANGE ME !!! -->
                           <argument>${middleware.home}/wlserver/server/lib/wlthint3client.jar:${middleware.home}/wlserver/server/lib/wls-api.jar:${middleware.home}/wlserver/modules/com.bea.core.management.jmx.jar:target/${project.artifactId}.jar:.:</argument>

                           <!-- WINDOWS Based OS use the following classpath setting -->                          <!-- CHANGE ME !!! -->
                           <!-- <argument>${middleware.home}/wlserver/server/lib/wlthint3client.jar;${middleware.home}/wlserver/server/lib/wls-api.jar;${middleware.home}/wlserver/modules/com.bea.core.management.jmx.jar;target/${project.artifactId}.jar;.;</argument> -->
                           <argument>client.SecureJMXClient</argument>
                       </arguments>
                </configuration>
            </plugin>
         </plugins>
     </build>
     
</project>


<!--  ######   For those who wants to run the "client.SecureJMXClient" manually do the following:
export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221
export CLASSPATH=$MW_HOME/wlserver/server/lib/wlthint3client.jar:$MW_HOME/wlserver/server/lib/wls-api.jar:$MW_HOME/wlserver/modules/com.bea.core.management.jmx.jar:.:
java   -Davax.net.ssl.trustStorePassword=middleware+magic+client   -Djavax.net.ssl.trustStore=${basedir}/ClientKey/client.keystore  client.SecureJMXClient
-->

Running the t3s protocol based Secure JMX Client

Step-8). Now we are going to build and run the JMX Client to interact with WebLogic 12.2.1 using “t3s://” protocol. Users need to make sure that in the “pom.xml” file they edit the “CHANGE ME!!!” sections to specify the correct path & for the client truststore and the correct truststore password.

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:\SSL_JMX
$ mvn clean install exec:exec

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 /PAYTH/TO/SSL_JMX

$ mvn clean install exec:exec


---------
  OUTPUT
---------
$ mvn clean install exec:exec
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JMX_Over_SSL 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ JMX_Over_SSL ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JMX_Over_SSL ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ JMX_Over_SSL ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ JMX_Over_SSL ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ JMX_Over_SSL ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ JMX_Over_SSL ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ JMX_Over_SSL ---
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/target/JMX_Over_SSL.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ JMX_Over_SSL ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/target/JMX_Over_SSL.jar to /Users/jsensharma/.m2/repository/middleware/magic/JMX_Over_SSL/1.0/JMX_Over_SSL-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/SSL_JMX/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/JMX_Over_SSL/1.0/JMX_Over_SSL-1.0.pom
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:exec (default-cli) @ JMX_Over_SSL ---
Handshake succeeded: TLSv1.2
Servers: com.bea:Name=AdminServer,Location=AdminServer,Type=ServerRuntime
Domain: com.bea:Name=two_ssl_domain,Location=two_ssl_domain,Type=Domain
Server: AdminServert State: RUNNING
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.943 s
[INFO] Finished at: 2015-12-27T21:12:40+05:30
[INFO] Final Memory: 13M/245M
[INFO] ------------------------------------------------------------------------

For those who wants to run the same code without using Maven. Just compile and run the “” code as following:


 $ export MW_HOME=/Users/jsensharma/NotBackedUp/Installed/wls1221

 $ export CLASSPATH=$MW_HOME/wlserver/server/lib/wlthint3client.jar:$MW_HOME/wlserver/server/lib/wls-api.jar:$MW_HOME/wlserver/modules/com.bea.core.management.jmx.jar:.:

 $ javac -d . SecureJMXClient.java 
 
 $ java   -Davax.net.ssl.trustStorePassword=middleware+magic+client   -Djavax.net.ssl.trustStore=/PATH/TO/SSL_JMX/WLST_and_Keys/Keystores/clientTrustStore.keystore    client.SecureJMXClient

---------
  OUTPUT
---------
Handshake succeeded: TLSv1.2
Servers: com.bea:Name=AdminServer,Location=AdminServer,Type=ServerRuntime
Domain: com.bea:Name=two_ssl_domain,Location=two_ssl_domain,Type=Domain
Server: AdminServert State: RUNNING

Some Common Issues

Issue-1). If the Client keystore/truststore PATH is not valid, so check the path specified in “-Djavax.net.ssl.trustStore” (OR) if the client keystore does not include the WebLogic certificate imported in it then we may see the following kind of error:

Handshake failed: TLSv1.2, error = sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed
Handshake failed: TLSv1.1, error = sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed
Handshake failed: TLSv1, error = Received fatal alert: handshake_failure
Handshake failed: TLSv1.2, error = sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed
Handshake failed: TLSv1.1, error = sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed
Handshake failed: TLSv1, error = Received fatal alert: handshake_failure
Exception in thread "main" java.io.IOException: t3s://localhost:7443: [RJVM:000575]Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
	java.rmi.ConnectException: [RJVM:000576]No available router to destination.
	at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:301)
	at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:135)
	at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:369)
	at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
	at client.SecureJMXClient.initConnection(SecureJMXClient.java:47)
	at client.SecureJMXClient.main(SecureJMXClient.java:83)
Caused by: javax.naming.CommunicationException: t3s://localhost:7443: [RJVM:000575]Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
	java.rmi.ConnectException: [RJVM:000576]No available router to destination. [Root exception is java.net.ConnectException: t3s://localhost:7443: [RJVM:000575]Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
	java.rmi.ConnectException: [RJVM:000576]No available router to destination.]
	at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:44)
	at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:889)
	at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:377)
	at weblogic.jndi.Environment.getContext(Environment.java:348)
	at weblogic.jndi.Environment.getContext(Environment.java:316)
	at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:119)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
	at javax.naming.InitialContext.init(InitialContext.java:242)
	at javax.naming.InitialContext.<init>(InitialContext.java:216)
	at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:278)
	... 5 more
Caused by: java.net.ConnectException: t3s://localhost:7443: [RJVM:000575]Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
	java.rmi.ConnectException: [RJVM:000576]No available router to destination.
	at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:238)
	at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:170)
	at weblogic.rjvm.ClientServerURL.findOrCreateRJVM(ClientServerURL.java:178)
	at weblogic.jndi.WLInitialContextFactoryDelegate$1.run(WLInitialContextFactoryDelegate.java:355)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:143)
	at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:351)
	... 13 more
Caused by: java.rmi.ConnectException: [RJVM:000575]Destination 0:0:0:0:0:0:0:1, 7443 unreachable.; nested exception is: 
	javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure; [RJVM:000576]No available router to destination.; nested exception is: 
	java.rmi.ConnectException: [RJVM:000576]No available router to destination.
	at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:524)
	at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:339)
	at weblogic.rjvm.RJVMManager.findOrCreateRemoteInternal(RJVMManager.java:306)
	at weblogic.rjvm.RJVMManager.findOrCreate(RJVMManager.java:155)
	at weblogic.rjvm.RJVMFinder.findOrCreateRemoteServer(RJVMFinder.java:258)
	at weblogic.rjvm.RJVMFinder.findOrCreateRemoteCluster(RJVMFinder.java:329)
	at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:227)
	... 19 more
Caused by: java.rmi.ConnectException: [RJVM:000576]No available router to destination.
	at weblogic.rjvm.ConnectionManager.findOrCreateRouter(ConnectionManager.java:1643)
	at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:505)
	... 25 more

The Source Code for this demo can be found at:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/Security/SSL_JMX_WLS12c
.
.

Regards
Jay SenSharma


Implementing SOA using Opensource Apache Camel JMS Component on WebLogic 12c

Hi,

In one of our previous example we have talked about how we can use “Apache Camel based EJB Client accessing the EJBs deployed on WebLogic 12c”, Now we will see how we can develop a simple Web Application using Apache Camel Servlet which will accept inputs form the user and then will process those inputs (like adding the input numbers) and then the generated HTMPL output will be send to the WebLogic JMS Queue.

As part of this example we are going to use the “org.apache.camel.component.jms.JmsComponent” and Apache Camel “servlet:” endpoint. The Camel JMS component is a general purpose JMS integration point that can be used to integrate Apache Camel with any JMS client library. Using the Camel JMS component, it is possible to define JMS consumer endpoints (at the start of a Camel route) and JMS producer endpoints (at the end of a Camel route). Similarly The servlet: component provides HTTP based endpoints for consuming HTTP requests that arrive at a HTTP endpoint that is bound to a published Servlet.

For more information on Camel JMS Endpoint can be found at : http://camel.apache.org/jms.html . This component allows messages to be sent to (or consumed from) a JMS Queue or Topic. It uses Spring’s JMS support for declarative transactions, including Spring’s JmsTemplate for sending and a MessageListenerContainer for consuming.

Apache Camel’s API and out-of-the-box components implement many common enterprise integration patterns (EIPs), making it relatively simple and easy to do integration tasks such as connecting web services, performing XSL transformations, logging audits, and more. Camel supports most of the Enterprise Integration Patterns. See: http://camel.apache.org/enterprise-integration-patterns.html

What this demo is about ?

As part of this demo we will see how to use Apache Camel based WAR on latest WebLogic 12.2.1 (12c). While running this demo we will learn about the following things:

1. How to develop a Apache Camel based Camel Servlet to accept http request param inputs and to process them.

2. How to use the Apache Camel JMS Component to send the JMS Message (processed data) to the WebLogic Queue.

3. How to deploy the Camel based WebApplication on WebLogic using WebLogic 12.2.1 using maven plugin “weblogic-maven-plugin”. If you get any kind of error while using this plugin then refer to the article How to use WebLogic 12c provided Maven Synchronization Plug-In ?

4. Configuring JMS Connection Factory and the JMS Queues using WLST.

5. We are going to use Apache Camel 2.16.0, Spring 4.1.6.RELEASE and WebLogic 12.2.1 release for this demo.

Configuring JMS Queue and ConnectionFactory

Step-1). First create a directory some where in our filesystem where we will be keeping our projects. We will create a directory as “CamelServlet_With_JMSEndpoint_Demo”

 $ mkdir -p Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo

 $ mkdir -p Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/src/main/java/beans

 $ mkdir -p Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/src/main/resources

 $ mkdir -p Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/src/main/webapp/WEB-INF

Step-2). Lets write the “Camel-on-WebLogic12c/domains.properties” file where we will define all the properties which will be used by the WLST script to configure the JMS Queue and ConnectionFactory.

############ WebLogic 12c JMS Queue and Connection Factory related Configuration #########

# 1 - Connecting details
server.url = t3://localhost:7001
username = weblogic
password = weblogic1
 
# 2 - JMSServer details
jms.server.name = My_JMSServer
store.name = MyJDBCStore
tragated.jms.server.name = AdminServer
 
# 3 - SystemModule Details
system.module.name = My_SystemModule
tragated.system.module.name = AdminServer
 
# 4 - ConnectionFactory Details
connection.factory.name = My_ConnectionFactory
connection.factory.jndi.name = My_CF
 
# 5 - Unit Of Order Details
unit.of.order.value = 1
 
# 6 - SubDeployment & Queue Details
queue.sub.deployment.name = Sub_My_Queue
queue.name = My_Queue
queue.jndi.name = My_Q

Step-3). Now we will write a simple WLST Script which will use the above properties file and configure the JMS resources on WebLogic. Create a file as “Camel-on-WebLogic12c/configureJMS.py”

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
 
from java.io import FileInputStream
import java.lang
import os
import string
 
propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)
 
# 1 - Connecting details
serverUrl = configProps.get("server.url")
Username = configProps.get("username")
Password = configProps.get("password")
 
# 2 - JMSServer details
jmsServerName = configProps.get("jms.server.name")
storeName = configProps.get("store.name")
tragatedJMSServerName = configProps.get("tragated.jms.server.name")
 
# 3 - SystemModule Details
systemModuleName = configProps.get("system.module.name")
tragatedSystemModuleName = configProps.get("tragated.system.module.name")
 
# 4 - ConnectionFactory Details
connectionFactoryName = configProps.get("connection.factory.name")
ConnectionFactoryJNDIName = configProps.get("connection.factory.jndi.name")
 
# 5 - Unit Of Order Details
unitOfOrderValue = configProps.get("unit.of.order.value")
 
# 6 - SubDeployment & Queue Details
queueSubDeploymentName = configProps.get("queue.sub.deployment.name")
queueName = configProps.get("queue.name")
queueJNDIName = configProps.get("queue.jndi.name")
 
#7 - Weblogic Bridge Details:
weblogicDestinationBridge = configProps.get("weblogic.destination.bridge")
weblogicAdapterJNDINoTX = configProps.get("weblogic.adapter.jndi.name")

#8 - Widlfly bridge details:
wildflyDestinationBridge = configProps.get("wildfly.destination.bridge")
wildflyServerUrl = configProps.get("wildfly.server.url")
wildflyJMSUsername = configProps.get("wildfly.jms.username")
wildflyJMSUserPassword = configProps.get("wildfly.jms.password")
wildflyInitialContextFactory = configProps.get("wildfly.initial.context.factory")
wildflyJMSConnectionFactory = configProps.get("wildfly.remote.connection.factory.jndi.name")
wildflyJMSQueueJndi = configProps.get("wildfly.jms.destination.jndi.name")




redirect('wlst.log','false')
 
# 1 - Connecting to the Destination 
connect(Username,Password,serverUrl)
 
edit()
 
# 2 - JMSServer details
print "================== JMSSever ==================="
startEdit()
cmo.createJMSServer(jmsServerName)
print "Created a JMSServer !!"
cd('/Deployments/'+jmsServerName)
cmo.setPersistentStore(getMBean('/FileStores/'+storeName))
print "PersistentStore has been set for the JMSServer !!"
set('Targets',jarray.array([ObjectName('com.bea:Name='+tragatedJMSServerName+',Type=Server')], ObjectName))
print "Targeted the JMSServer !!"
activate()
print ""
 
# 3 - SystemModule Details
print "================== SystemModule ==================="
startEdit()
cd('/')
cmo.createJMSSystemResource(systemModuleName)
print "Created a SystemModule !!"
cd('/SystemResources/'+systemModuleName)
set('Targets',jarray.array([ObjectName('com.bea:Name='+tragatedSystemModuleName+',Type=Server')], ObjectName))
print "Targeted the SystemModule !!"
activate()
print ""
 
# 4 - ConnectionFactory Details
print "================== ConnectionFactory ==================="
startEdit()
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName)
cmo.createConnectionFactory(connectionFactoryName)
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName)
cmo.setJNDIName(ConnectionFactoryJNDIName)
print "Created a ConnectionFactory !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName+'/SecurityParams/'+connectionFactoryName)
cmo.setAttachJMSXUserId(false)
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName)
cmo.setDefaultTargetingEnabled(true)
print "Targeted the ConnectionFactory !!"
activate()
print ""
 
# 5 - SubDeployment & Queue Details
print "================== SubDeployment & Queue ==================="
startEdit()
cd('/SystemResources/'+systemModuleName)
cmo.createSubDeployment(queueSubDeploymentName)
print "Created a SubDeployment for Queue !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName)
cmo.createQueue(queueName)
print "Created a Queue !!"
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/Queues/'+queueName)
cmo.setJNDIName(queueJNDIName)
cmo.setSubDeploymentName(queueSubDeploymentName)
cd('/SystemResources/'+systemModuleName+'/SubDeployments/'+queueSubDeploymentName)
set('Targets',jarray.array([ObjectName('com.bea:Name='+jmsServerName+',Type=JMSServer')], ObjectName))
print "Targeted the Queue to the created subdeployment !!"
activate()
print ""

cmd = "rm -f wlst.log"
os.system(cmd)

Step-4). Now we will start the WebLogic 12.2.1 instance and then we will open a terminal to run the above mentioned WLST script. We will run the “setWLSEnv.sh” script in the terminal first so that it will set the CLASSPATH properly with the required JARs.

$ cd /Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin

$ . ./setWLSEnv.sh 

CLASSPATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/tools.jar:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/modules/features/wlst.wls.classpath.jar:
PATH=/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/server/bin:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/modules/org.apache.ant_1.9.2/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jsensharma/NotBackedUp/Installed/wls1221/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin
Your environment has been set.

Step-5). Running the WLST script in the same terminal.

######  Running the WLST commands as following: #######

$ cd /PATH/TO/Camel-on-WebLogic12c

$ java weblogic.WLST configureJMS.py 

Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands

================== JMSSever ===================
Created a JMSServer !!
PersistentStore has been set for the JMSServer !!
Targeted the JMSServer !!

================== SystemModule ===================
Created a SystemModule !!
Targeted the SystemModule !!

================== ConnectionFactory ===================
Created a ConnectionFactory !!
Targeted the ConnectionFactory !!

================== SubDeployment & Queue ===================
Created a SubDeployment for Queue !!
Created a Queue !!
Targeted the Queue to the created subdeployment !!

Developing the Camel Based WebApp

Step-6). First of all we will write a Simple Bean which will include out business logic of adding two numbers and produce an HTML output containing the sum. For this we will write “MathBean.java” inside the “CamelServlet_With_JMSEndpoint_Demo/src/main/java/beans” as following:

package beans;

public class MathBean {
     private String firstNo="1000";
     private String secondNo="2000";

	public String getFirstNo() {
		return firstNo;
	}

	public void setFirstNo(String firstNo) {
		this.firstNo = firstNo;
	}

	public String getSecondNo() {
		return secondNo;
	}

	public void setSecondNo(String secondNo) {
		this.secondNo = secondNo;
	}
 
    public String addTwoNumbers(String firstNo, String secondNo) {
        System.out.println("[MathBean] addTwoNumbers("+firstNo+","+secondNo+") invoked.");
        int sum = Integer.parseInt(firstNo) + Integer.parseInt(secondNo);
        String result=    "<HTML>" +
                          "   <HEAD><TITLE> Add Numbers Camel Servlet test </TITLE></HEAD>" +
                          "   <BODY>" +
                          "       [MathBean] Sum of " +firstNo+" And "+secondNo+ " is = " + sum + 
                          "   </BODY>" +
                          "</HTML>";
            return result;
        }
}

Step-7). Now we will write a simple “web.xml” file as following which will define the CamelServlet and also declare the Spring “ContextLoaderListener” listener. In the same file we will define the Camel configuration file via “contextConfigLocation” context param. Place the “web.xml” file inside the “CamelServlet_With_JMSEndpoint_Demo/src/main/webapp/WEB-INF/”

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Camel Servlet WAR</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:camel-config.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>CamelServlet</servlet-name>
    <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/camel/*</url-pattern>
  </servlet-mapping>

</web-app>

Step-8). Now we will write a simple “index.html” page inside the “CamelServlet_With_JMSEndpoint_Demo/src/main/webapp/”. This Html page will simple provide a form to the user so that they can enter two number which will be later processed bu the camel servlet after submitting the HTML form.

<html>
	<body>
		<h2>MiddlewareMagic: Camel Add Servlet Demo</h2>
		<table>
			<form action="camel/addNumbers">
				<TR><TD>Enter First Number </TD> <TD><input type="text" name="firstNumber" value="200"/></TD></TR>
				<TR><TD>Enter Second Number </TD> <TD> <input type="text" name="secondNumber" value="300"/></TD></TR>
				<TR><TD><input type="reset" value="Clear"/> </TD> <TD> <input type="Submit" value="Add the Numbers and Store result in WebLogic JMS Queue My_Q" /></TD></TR>
			</form>
		</table>
	</body>
</html>

Step-9). Now we will write the Apache Camel context file “camel-config.xml” which defines how the various camel endpoints will work. In order to know more about this please refer to: http://camel.apache.org/configuring-camel.html
Lets create the “camel-config.xml” file inside “CamelServlet_With_JMSEndpoint_Demo/src/main/resources”

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:p="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

     <bean id="mathBean" class="beans.MathBean" />

     <camelContext xmlns="http://camel.apache.org/schema/spring">
       <route id="addNumbersRoute">
           <from uri="servlet:///addNumbers"/>
           <transform>
               <method bean="mathBean" method="addTwoNumbers(${header.firstNumber},${header.secondNumber})"/> 
           </transform>
           <inOnly uri="weblogicJMS:My_Q" />
       </route>
     </camelContext>


     <!-- WebLogic JndiTemplate Settings --> 
     <bean id="jmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
           <property name="environment">
              <props>
                 <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
                 <prop key="java.naming.provider.url">t3://localhost:7001</prop>
              </props>
           </property>
     </bean>

     <bean id="jndiDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
          <property name="jndiTemplate" ref="jmsJndiTemplate"/>
     </bean>

     <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
          <property name="jndiTemplate" ref="jmsJndiTemplate"/>
          <property name="jndiName" value="My_CF"/>
     </bean>
     
     <bean id="jmsConfiguration" class="org.apache.camel.component.jms.JmsConfiguration">
          <property name="connectionFactory" ref="jmsConnectionFactory"/>
          <property name="destinationResolver" ref="jndiDestinationResolver"/>
     </bean>
          
     <bean id="weblogicJMS" class="org.apache.camel.component.jms.JmsComponent">
          <property name="configuration" ref="jmsConfiguration" />
     </bean>

</beans>

Step-10). Now the most important part in which we will be writing the maven “pom.xml” which will compile and build the above artifacts and will package them as part fo a WAR file. We will be using the “weblogic-maven-plugin” Weblogic plugin in this pom sothat we can easily deploy the WAR to weblogic 12c as well.

<?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>my.camel.servlet.demo</groupId>
	<artifactId>HelloCamelServletWebApp</artifactId>
	<version>1.0</version>
	<packaging>war</packaging>
	<name>HelloCamelServletWebApp Demo</name>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<version.compiler.plugin>2.3.1</version.compiler.plugin>
		<maven.compiler.target>1.7</maven.compiler.target>
		<maven.compiler.source>1.7</maven.compiler.source>
		
		<!-- Camel and Spring related properties -->
		<version.apache.camel>2.16.0</version.apache.camel>
		<version.spring>4.1.6.RELEASE</version.spring>
		
		<!-- Weblogic Plugin related properties -->
		<middleware.home>/Users/jsensharma/NotBackedUp/Installed/wls1221</middleware.home>
        <admin.server.url>t3://localhost:7001</admin.server.url>
        <admin.username>weblogic</admin.username>
        <admin.password>weblogic1</admin.password>
	</properties>

	<dependencies>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${version.spring}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>${version.apache.camel}</version>

			<!-- As we do not want the following JARs inside the "WEB-INF/lib" Hence excluding them : jaxb-api-2.2.7.jar jaxb-core-2.2.7.jar jaxb-impl-2.2.7.jar -->
			<exclusions>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-impl</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-servlet</artifactId>
			<version>${version.apache.camel}</version>
			<!-- As we do not want the following JARs inside the "WEB-INF/lib" Hence excluding them : jaxb-api-2.2.7.jar jaxb-core-2.2.7.jar jaxb-impl-2.2.7.jar -->
			<exclusions>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-impl</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${version.apache.camel}</version>
			<!-- As we do not want the following JARs inside the "WEB-INF/lib" Hence excluding them : jaxb-api-2.2.7.jar jaxb-core-2.2.7.jar jaxb-impl-2.2.7.jar -->
			<exclusions>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-impl</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.sun.xml.bind</groupId>
					<artifactId>jaxb-core</artifactId>
				</exclusion>
			</exclusions>
        </dependency>
	</dependencies>

	<build>
		<finalName>${project.artifactId}</finalName>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>${version.compiler.plugin}</version>
				<configuration>
					<source>${maven.compiler.source}</source>
					<target>${maven.compiler.target}</target>
				</configuration>
			</plugin>
			
			<plugin>
                <groupId>com.oracle.weblogic</groupId> 
                <artifactId>weblogic-maven-plugin</artifactId> 
                <version>12.2.1-0-0</version> 
                <configuration> 
                    <middlewareHome>${middleware.home}</middlewareHome>
                    <adminurl>${admin.server.url}</adminurl>
                    <user>${admin.username}</user>
                    <password>${admin.password}</password>
                    <name>${project.build.finalName}</name>
                    <upload>true</upload> 
                    <action>deploy</action> 
                    <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>          
                </configuration> 
            </plugin>
		</plugins>
	</build>

</project>

Building and Deploying the Camel WebApp

Now we are going to build and deploy the WebApplication to WebLogic 12.2.1 version. We will use Maven plugins to achieve the same. So before using the maven we need to setup the PATH and M2_HOME as following:

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 /PAYTH/TO/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo
$ mvn clean install weblogic:deploy

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:\Camel-on-WebLogic12c\CamelServlet_With_JMSEndpoint_Demo
$ mvn clean install  weblogic:deploy

Step-11). Now we are going to build and deploy it on WebLogic as following using mvn clean install weblogic:deploy:


$ cd CamelServlet_With_JMSEndpoint_Demo

$  mvn clean install weblogic:deploy

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloCamelServletWebApp Demo 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloCamelServletWebApp ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloCamelServletWebApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ HelloCamelServletWebApp ---
[INFO] Compiling 1 source file to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloCamelServletWebApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.1:testCompile (default-testCompile) @ HelloCamelServletWebApp ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloCamelServletWebApp ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ HelloCamelServletWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [HelloCamelServletWebApp] in [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/HelloCamelServletWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/src/main/webapp]
[INFO] Webapp assembled in [45 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/HelloCamelServletWebApp.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloCamelServletWebApp ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/HelloCamelServletWebApp.war to /Users/jsensharma/.m2/repository/my/camel/servlet/demo/HelloCamelServletWebApp/1.0/HelloCamelServletWebApp-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/pom.xml to /Users/jsensharma/.m2/repository/my/camel/servlet/demo/HelloCamelServletWebApp/1.0/HelloCamelServletWebApp-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloCamelServletWebApp Demo 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:deploy (default-cli) @ HelloCamelServletWebApp ---
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name HelloCamelServletWebApp -source /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/HelloCamelServletWebApp.war -upload -adminurl t3://localhost:7001
<Dec 13, 2015 5:49:59 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, HelloCamelServletWebApp [archive: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/Camel-on-WebLogic12c/CamelServlet_With_JMSEndpoint_Demo/target/HelloCamelServletWebApp.war], to configured targets.> 
Task 6 initiated: [Deployer:149026]deploy application HelloCamelServletWebApp on AdminServer.
Task 6 completed: [Deployer:149026]deploy application HelloCamelServletWebApp on AdminServer.
Target state: deploy completed on Server AdminServer

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.831 s
[INFO] Finished at: 2015-12-13T17:50:01+05:30
[INFO] Final Memory: 37M/699M
[INFO] ------------------------------------------------------------------------

Once the Application is deployed on WebLogic we should be able to see the following kind of output on weblogic logs which indicates that the camel context is initialized.

Output on WebLogic console.


Dec 13, 2015 5:50:00 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Dec 13, 2015 5:50:00 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sun Dec 13 17:50:00 IST 2015]; root of context hierarchy
Dec 13, 2015 5:50:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [camel-config.xml]
Dec 13, 2015 5:50:00 PM org.apache.camel.impl.DefaultCamelContext start
INFO: Apache Camel 2.16.0 (CamelContext: camel-1) is starting
Dec 13, 2015 5:50:00 PM org.apache.camel.management.ManagedManagementStrategy doStart
INFO: JMX is enabled
Dec 13, 2015 5:50:00 PM org.apache.camel.impl.converter.DefaultTypeConverter doStart
INFO: Loaded 189 type converters
Dec 13, 2015 5:50:00 PM org.apache.camel.impl.DefaultRuntimeEndpointRegistry doStart
INFO: Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
Dec 13, 2015 5:50:00 PM org.apache.camel.impl.DefaultCamelContext doStartCamel
INFO: AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
Dec 13, 2015 5:50:00 PM org.apache.camel.impl.DefaultCamelContext doStartCamel
INFO: StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
Dec 13, 2015 5:50:01 PM org.apache.camel.impl.DefaultCamelContext doStartOrResumeRouteConsumers
INFO: Route: addNumbersRoute started and consuming from: Endpoint[servlet:///addNumbers]
Dec 13, 2015 5:50:01 PM org.apache.camel.impl.DefaultCamelContext start
INFO: Total 1 routes, of which 1 is started.
Dec 13, 2015 5:50:01 PM org.apache.camel.impl.DefaultCamelContext start
INFO: Apache Camel 2.16.0 (CamelContext: camel-1) started in 0.156 seconds
Dec 13, 2015 5:50:01 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 898 ms
Dec 13, 2015 5:50:01 PM org.apache.camel.component.servlet.CamelHttpTransportServlet init
INFO: Initialized CamelHttpTransportServlet[name=CamelServlet, contextPath=/HelloCamelServletWebApp]

Testing the Web Application

Now as the application is deployed on WebLogic 12.2.1 hence lets access the URL and submit the form:

http://localhost:7001/HelloCamelServletWebApp/
OR
http://localhost:7001/HelloCamelServletWebApp/camel/addNumbers?firstNumber=200&secondNumber=300

As soon as we submit the data (two numbers) in the form presented by the application we will be able to see that the JMS Queue has got a JMS Message in it.

Listing JMS Queue Messages on WLS Console

Listing JMS Queue Messages on WLS Console

Source Code:
The Source code for this demo can be found at:

https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/JMS/Camel-on-WebLogic12c
.
.

Regards
Jay SenSharma


Why and How to use Apache CXF Service in WebLogic 12c ?

Hi,

Why and how to deploy Apache CXF based web service on WebLogic? This is the question we are going to focus as part of this article. First lets see what is apache cxf. Apache CXF implements the JAX-WS APIs which make building web services easy. It allows us generating WSDL from Java classes and generating Java classes from WSDL, Provider API which allows you to create simple messaging receiving server endpoints, Dispatch API which allows you to send raw XML messages to server endpoints.

Apache CXF provides support for the Spring 2.0 XML syntax support and integration. It also enables the development of RESTful services via annotations using the HTTP Binding. The Apache CXF uses Aegis Databinding (2.0.x) which has it;s own databinding library that makes development of code-first web services incredibly easy. The Apache CXF also provides support for variety of WS specifications like WS-Addressing, WS-Policy, WS-ReliableMessaging and WS-Security.

What this demo is about ?

As part of this demo we will see how to use Apache CXF 3.1.4 based WebService on latest WebLogic 12.2.1 (12c). While running this demo we will learn about the following things:

1. How to develop a CXF based WebService using top down approach. Means generating WebService WSDL first and then Creating WebService artifacts (like wrappers, Service interface) from it.

2. How to use the “cxf-codegen-plugin” Maven plugin to generate CXF service artifacts from WSDL.

3. How to deploy the CXF based WebService on WebLogic using WebLogic 12.2.1 using maven plugin “weblogic-maven-plugin”. If you get following kind of error while using this plugin then refer to the article How to use WebLogic 12c provided Maven Synchronization Plug-In ?

4. Invoking the deployed CXF web service using a simple Curl Based Client.

Developing CXF WebService from WSDL

Step-1). First create a directory some where in our filesystem where we will be keeping our projects.

 $ mkdir WebLogic12c_CXF_Demo_Maven

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/resources

 $ mkdir -p WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic 

Step-2). Lets start developing a simple WSDL “helloworld.wsdl” and place it inside the “WebLogic12c_CXF_Demo_Maven/src/main/resources/” as following:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" 
				  xmlns:impl="http://middlewaremagic.com" 
				  xmlns:intf="http://middlewaremagic.com" 
				  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
			  	  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
				  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
				  targetNamespace="http://middlewaremagic.com">

 <wsdl:types>
  <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://middlewaremagic.com">
   <element name="sayHello">
    <complexType>
     <sequence>
      <element name="name" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="sayHelloResponse">
    <complexType>
     <sequence>
      <element name="sayHelloReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="sayHelloResponse">
      <wsdl:part element="impl:sayHelloResponse" name="parameters">
      </wsdl:part>
   </wsdl:message>

   <wsdl:message name="sayHelloRequest">
      <wsdl:part element="impl:sayHello" name="parameters">
      </wsdl:part>
   </wsdl:message>

   <wsdl:portType name="HelloWorld">
      <wsdl:operation name="sayHello">
         <wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest">
       </wsdl:input>
         <wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse">
       </wsdl:output>
      </wsdl:operation>
   </wsdl:portType>
   
   <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="sayHello">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="sayHelloRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="sayHelloResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   
   <wsdl:service name="HelloWorldService">
      <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
         <wsdlsoap:address location="http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld"/>
      </wsdl:port>
   </wsdl:service>   
   
</wsdl:definitions>

Step-3). Now lets write a simple “pom.xml” file inside the “WebLogic12c_CXF_Demo_Maven” directory as following where we will use the “cxf-codegen-plugin” plugin’s “wsdl2java” goal to generate the WebService artifacts like helper classes, implementation class and the webservice interface..etc


<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>WebLogic12c_CXF_Demo</artifactId>
    <packaging>war</packaging>
    <name>WSDL first demo on WenLogic 12.2.1</name>
    <version>1.0</version>
    <description>A very simple demo showing how to develop and use a CXF based WebService on WebLogic 12.2.1</description>

    <properties>
        <cxf.version>3.1.4</cxf.version>
        <cxf.xjc-utils.version>3.0.5</cxf.xjc-utils.version>
        <spring.version>4.1.4.RELEASE</spring.version>
    </properties>
    
    <build>
        <defaultGoal>install</defaultGoal>
        <finalName>WebLogic_CXF_Demo</finalName>   <!-- WAR name -->
        
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                        <webResources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>*.wsdl</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>src/main/resources/helloworld.wsdl</wsdl>  <!-- Where the original WSDL is present -->
                                    <wsdlLocation>WEB-INF/wsdl/helloworld.wsdl</wsdlLocation>  <!-- Where to place the WSDL -->
                                    <bindingFiles>
                                        <bindingFile>src/main/resources/binding.xml</bindingFile>
                                    </bindingFiles>
                                    <extraargs>
                                        <extraarg>-impl</extraarg>  <!-- will generate a dummy  webservice implementation -->
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>    


            <plugin> 
              <groupId>com.oracle.weblogic</groupId> 
              <artifactId>weblogic-maven-plugin</artifactId> 
              <version>12.2.1-0-0</version> 
              <configuration> 
                  <adminurl>t3://localhost:7001</adminurl>
                  <user>weblogic</user> 
                  <password>weblogic1</password> 
                  <upload>true</upload> 
                  <action>deploy</action> 
                  <remote>false</remote> 
                  <verbose>true</verbose> 
                  <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source> 
                  <name>${project.build.finalName}</name> 
              </configuration> 
           </plugin>                   
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf.xjc-utils</groupId>
            <artifactId>cxf-xjc-runtime</artifactId>
            <version>${cxf.xjc-utils.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
       </dependency>
    </dependencies>
</project>

Step-4). Now if users want to provide their own custom binding then they can add the “binding.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/resources/” directory as following, Here i am putting a dummy file without having much information in it:

<jaxws:bindings wsdlLocation="helloworld.wsdl"
          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
          
		<jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema">
			<jxb:globalBindings>
			</jxb:globalBindings>
		</jaxws:bindings>
		
</jaxws:bindings>

Step-5). Now lets run the maven to build the above project which will internally read the WSDL and generate the WebService Artifacts along with a dummy implementation class which later we will modify according to our need. So open a terminal and run the following commands in order to set the maven properly.
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 /WebLogic12c_CXF_Demo_Maven
$ 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:\WebLogic12c_CXF_Demo_Maven
$ mvn clean install 

As soon as you will run the “mvn clean install” the web service artifacts will be generated as following:

$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12c_CXF_Demo ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target
[INFO] 
[INFO] --- cxf-codegen-plugin:3.1.4:wsdl2java (generate-sources) @ WebLogic12c_CXF_Demo ---
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -d /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf -b file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/binding.xml -impl -verbose -wsdlLocation WEB-INF/helloworld.wsdl file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/helloworld.wsdl
wsdl2java - Apache CXF 3.1.4

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebLogic12c_CXF_Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebLogic12c_CXF_Demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebLogic12c_CXF_Demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1:war (default-war) @ WebLogic12c_CXF_Demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebLogic12c_CXF_Demo] in [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Processing war project
[INFO] Copying webapp webResources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources] to [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/webapp]
[INFO] Webapp assembled in [55 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12c_CXF_Demo ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.320 s
[INFO] Finished at: 2015-11-14T11:52:19+05:30
[INFO] Final Memory: 23M/245M
[INFO] ------------------------------------------------------------------------

Updating WebService Impl and deploying on WLS12c

Step-6). After running the above “cxf-codegen-plugin” task “wsdl2java” it will create some artifacts (WebService interface and helper and impementation classes) from the WSDL. We can see that the following kind of web service implementation class “HelloWorldImpl.java” would have been generated inside the “WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic”


/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.middlewaremagic;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 3.1.4
 * 2015-11-14T11:52:18.278+05:30
 * Generated source version: 3.1.4
 * 
 */

@javax.jws.WebService(
                      serviceName = "HelloWorldService",
                      portName = "HelloWorld",
                      targetNamespace = "http://middlewaremagic.com",
                      wsdlLocation = "WEB-INF/helloworld.wsdl",
                      endpointInterface = "com.middlewaremagic.HelloWorld")
                      
public class HelloWorldImpl implements HelloWorld {

    private static final Logger LOG = Logger.getLogger(HelloWorldImpl.class.getName());

    /* (non-Javadoc)
     * @see com.middlewaremagic.HelloWorld#sayHello(java.lang.String  name )*
     */
    public java.lang.String sayHello(java.lang.String name) { 
        LOG.info("Executing operation sayHello");
        System.out.println(name);
        try {
            java.lang.String _return = "";
            return _return;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

}

Step-7). As we see a dummy WebService implementation class is generated as above by CXF, Hence lets customize it base don our need. Lets Copy the above file “HelloWorldImpl.java” from “WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic” to “WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic”

 $ cp -f WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf/com/middlewaremagic/HelloWorldImpl.java  WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic

Once we copied the above file then edit the “pom.xml” file to make sure that the following tag is commented or removed. So that when we do the “mvn clean build”

        <extraargs>
            <!-- <extraarg>-impl</extraarg> -->  <!-- REMOVE THIS LINE  -->
            <extraarg>-verbose</extraarg>
        </extraargs>

Step-8). Now lets edit the “WebLogic12c_CXF_Demo_Maven/src/main/java/com/middlewaremagic/HelloWorldImpl.java” file and then provide our own implementation.

package com.middlewaremagic;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@javax.jws.WebService(
                      serviceName = "HelloWorldService",
                      portName = "HelloWorld",
                      targetNamespace = "http://middlewaremagic.com",
                      wsdlLocation = "WEB-INF/helloworld.wsdl",
                      endpointInterface = "com.middlewaremagic.HelloWorld")
                      
public class HelloWorldImpl implements HelloWorld {

    private static final Logger LOG = Logger.getLogger(HelloWorldImpl.class.getName());

    public java.lang.String sayHello(java.lang.String name) { 
        System.out.println("\n\t [HelloWorld_Impl] sayHello("+name+") invoked.");
        return "Hello World !!! Mr. "+ name + " at " + new java.util.Date();
    }
}

Step-9). Before deploying the above application lets make sure to add the “web.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF/” as following:

<?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"> 
    <display-name>wls_cxf_demo</display-name>
    <servlet>
        <servlet-name>cxf</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

Step-10). The most important part now, is to add the following kind of CXF specific “cxf-servlet.xml” file inside the “WebLogic12c_CXF_Demo_Maven/src/main/webapp/WEB-INF/” as following:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jaxws="http://cxf.apache.org/jaxws"
      xmlns:soap="http://cxf.apache.org/bindings/soap"
      xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
             http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:endpoint xmlns:hello="http://middlewaremagic.com/"
            id="HelloWorldHTTP" address="/HelloWorld"
            serviceName="hello:HelloWorldService" endpointName="hello:HelloWorldPort"
            implementor="com.middlewaremagic.HelloWorldImpl">
    </jaxws:endpoint>

</beans>

Step-11). Now lets do a clean build again with the “weblogic:deploy” plugin to deploy it on WebLogic.



$ mvn clean install weblogic:deploy


[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12c_CXF_Demo ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target
[INFO] 
[INFO] --- cxf-codegen-plugin:3.1.4:wsdl2java (generate-sources) @ WebLogic12c_CXF_Demo ---
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -d /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/generated-sources/cxf -b file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/binding.xml -verbose -wsdlLocation WEB-INF/wsdl/helloworld.wsdl file:/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources/helloworld.wsdl
wsdl2java - Apache CXF 3.1.4

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ WebLogic12c_CXF_Demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebLogic12c_CXF_Demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ WebLogic12c_CXF_Demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebLogic12c_CXF_Demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1:war (default-war) @ WebLogic12c_CXF_Demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebLogic12c_CXF_Demo] in [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Processing war project
[INFO] Copying webapp webResources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/resources] to [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo]
[INFO] Copying webapp resources [/Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/src/main/webapp]
[INFO] Webapp assembled in [66 msecs]
[INFO] Building war: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12c_CXF_Demo ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.war
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12c_CXF_Demo/1.0/WebLogic12c_CXF_Demo-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WSDL first demo on WenLogic 12.2.1 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- weblogic-maven-plugin:12.2.1-0-0:deploy (default-cli) @ WebLogic12c_CXF_Demo ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name WebLogic_CXF_Demo -source /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war -upload -verbose -adminurl t3://localhost:7001
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name WebLogic_CXF_Demo -source /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war -upload -verbose -adminurl t3://localhost:7001
<Nov 14, 2015 12:51:48 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, WebLogic_CXF_Demo [archive: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/WebLogic12c_CXF_Demo_Maven/target/WebLogic_CXF_Demo.war], to configured targets.> 
Task 6 initiated: [Deployer:149026]deploy application WebLogic_CXF_Demo on AdminServer.
Task 6 completed: [Deployer:149026]deploy application WebLogic_CXF_Demo on AdminServer.
Target state: deploy completed on Server AdminServer

Target Assignments:
+ WebLogic_CXF_Demo  AdminServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.753 s
[INFO] Finished at: 2015-11-14T12:51:50+05:30
[INFO] Final Memory: 38M/502M
[INFO] ------------------------------------------------------------------------

Running Curl Based WebSerivce Client

Step-12). As the web service is deployed hence lets try accessing the WSDL and the service endpoint information from WLS server by accessing the following URL:

http://localhost:7001/WebLogic_CXF_Demo/services
And
http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld?wsdl

Step-13). Now lets create a SOAP request XML which we will send to the web service. Hence write the “soap_request.xml” file inside the any directory of your choice like “WebLogic12c_CXF_Demo_Maven//client”

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mid="http://middlewaremagic.com">
   <soapenv:Header/>
   <soapenv:Body>
      <mid:sayHello>
         <mid:name>MiddlewareMagic!!!</mid:name>
      </mid:sayHello>
   </soapenv:Body>
</soapenv:Envelope>

Step-14). Also lets write a simple CURL based command which will send the above SOAP request to the WebService endpoint. Write the following file “request.sh” inside the “WebLogic12c_CXF_Demo_Maven/client”

## A simple "curl" based SOAP Request 
## Which will invoke the HelloWorld Service:

request=`cat soap_request.xml`
curl -s -H "Content-Type: text/xml" -d "$request" http://localhost:7001/WebLogic_CXF_Demo/services/HelloWorld
echo

Step-15). Run the client to access the WebService and to receive the response.

  $ cd WebLogic12c_CXF_Demo_Maven/client

  $ chmod 755 ./request.sh 

  $ ./request.sh

        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
               <sayHelloResponse xmlns="http://middlewaremagic.com">
                   <sayHelloReturn>Hello World !!! Mr. MiddlewareMagic!!! at Sat Nov 14 12:59:32 IST 2015</sayHelloReturn>
               </sayHelloResponse>
            </soap:Body>
       </soap:Envelope>

.
.
Source code for this demo is present in:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/WebService/WebLogic12c_CXF_Demo_Maven

.
.
Regards
Jay SenSharma


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