Apache Camel based EJB Client accessing the EJBs deployed on WebLogic 12c

Hi,

In our last demo we have seen how to develop and deploy an EJB3.0 based application on WebLogic 12c and how to access those EJBs from a standalone java code. See the following for more details on this: http://middlewaremagic.com/weblogic/?p=8283

However as part of this example we will see how ti use Apache Camel’s “org.apache.camel.component.ejb.EjbComponent” in order to access an EJB deployed on WebLogic12c. In order to see more about the Apache Camel EJB Component, which binds EJBs to Camel message exchanges, please refer to : http://camel.apache.org/ejb.html

So lets begin with writing the EJB Project.

We are assuming that you have already developed and deployed your EJB on WebLogic 12c as described in the article: http://middlewaremagic.com/weblogic/?p=8283 Now we will continue from there and will try developing a simple apache camel based client.

Developing Camel Based EJB Client

Step-1). First of all lets make a directory “Apache_Camel_As_WebLogic_EJB_Client” We will place our client artifacts there.

   $ mkdir -p Apache_Camel_As_WebLogic_EJB_Client/src/main/java/ejb3
   $ mkdir -p Apache_Camel_As_WebLogic_EJB_Client/src/main/resources/META-INF/spring

Step-2). As we are assuming that you have already deployed your EJB application on WebLogic 12c. The client needs the EJB remote interface to invoke the EJBs. Hence we will use the “HelloRemote.java” EJB remote interface here. Create a file “HelloRemote.java” as following inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/java/ejb3” directory.

package ejb3;
import javax.ejb.*;
@Remote
public interface HelloRemote {
        public String sayHello(String name);
}

Step-3). Now we will create the XML based apache camel context route. In order to do that lets create a file “camel-context.xml” inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/resources/META-INF/spring” directory 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: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">

    <p:properties id="jndiProperties">
        <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
        <prop key="java.naming.provider.url">t3://localhost:7001</prop>
        <!--
        <prop key="remote.connection.default.username">ejbuser</prop>
        <prop key="remote.connection.default.password">ejbuser@123</prop>
        -->
    </p:properties>


    <!-- setup Camel EJB component -->
    <bean id="ejbComponent" class="org.apache.camel.component.ejb.EjbComponent">
        <property name="properties" ref="jndiProperties"/>
    </bean>
    
    <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
      <camel:route id="testCamelEJBClient">
            <camel:from uri="timer:foo?period=5000"/>
            <setBody>
                <simple>MiddlewareMagic!!!</simple>
            </setBody>
            <!-- NOTE: "java:global/TestApp/TestEJB/HelloBean!ejb3.HelloRemote" is the JNDI name of WLS 12c deployed EJB -->
            <camel:to uri="ejbComponent:java:global/TestApp/TestEJB/HelloBean!ejb3.HelloRemote?method=sayHello" />
            
            <camel:log message="[EJB Response] ===> ${body}" />
      </camel:route>
    </camel:camelContext>

</beans>

Step-4). Just in case if we want to provide your own logging configuration to DEBUG the camel code and its execution then we can add the following kind of “log4j.properties” file inside the “Apache_Camel_As_WebLogic_EJB_Client/src/main/resources” directory.

#
# The logging properties used
#
log4j.rootLogger=INFO, out
#log4j.logger.org.apache.camel=DEBUG
log4j.logger.org.springframework=INFO

# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer

Step-5). Now we will write the most important part which will make the whole project and will define how the execution will happen. Hence lets write the “pom.xml” file inside the “Apache_Camel_As_WebLogic_EJB_Client” location as following:

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

  <modelVersion>4.0.0</modelVersion>
  <groupId>middleware.magic</groupId>
  <artifactId>Apache_Camel_As_WebLogic12c_EJB_Client</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>Apache Camel As WebLogic 12c Based EJB Client</name>
  <url>http://middlewaremagic.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <middleware.home>/Users/jsensharma/NotBackedUp/Installed/wls12130</middleware.home> <!-- CHANGE ME !!! -->
  </properties>

  <dependencies>   
       <!-- Needed to have access to WebLogic related class access like "weblogic.jndi.WLInitialContextFactory" -->
       <dependency>
        	<groupId>weblogic</groupId>
        	<artifactId>needed.jars</artifactId>
        	<version>1.0</version>
            <scope>system</scope>   
            <systemPath>${middleware.home}/wlserver/server/lib/wlthint3client.jar</systemPath>     	
       </dependency>  
             
       <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xbean</groupId>
            <artifactId>xbean-spring</artifactId>
            <version>3.16</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
          <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
             <version>1.2.15</version>
             <exclusions>
                <exclusion>
                     <groupId>com.sun.jmx</groupId>
                     <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>com.sun.jdmk</groupId>
                     <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>javax.jms</groupId>
                     <artifactId>jms</artifactId>
                </exclusion>
             </exclusions>
           </dependency>
           <dependency>
               <groupId>org.apache.camel</groupId>
               <artifactId>camel-ejb</artifactId>
               <version>2.15.0</version>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>6.0</version>
                <scope>provided</scope>
            </dependency>
   </dependencies>

   <pluginRepositories>
      <pluginRepository>
         <id>apache.snapshots</id>
         <name>Apache Development Snapshot Repository</name>
         <url>https://repository.apache.org/content/repositories/snapshots/</url>
         <releases>
            <enabled>false</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </pluginRepository>
   </pluginRepositories>

   <repositories>
      <repository>
         <id>apache.snapshots</id>
         <name>Apache Development Snapshot Repository</name>
         <url>https://repository.apache.org/content/repositories/snapshots/</url>
         <releases>
            <enabled>false</enabled>
         </releases>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </repository>
   </repositories>
   
  <build>
    <defaultGoal>install</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <!-- allows the route to be ran via 'mvn camel:run' -->
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>2.15.4</version>
      </plugin>
    </plugins>
  </build>
</project>

Running the Camel Based EJB Client

Step-6). Now lets run the client code 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 /PATH/TO/Apache_Camel_As_WebLogic_EJB_Client

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:\Apache_Camel_As_WebLogic_EJB_Client

Step-7). Once the environment is set then run the Apache Camel Based ejb client as following:

   $ mvn clean camel:run

.
.

Raw output of the client execution

$ mvn clean camel:run
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Camel As WebLogic 12c Based EJB Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] 
[INFO] >>> camel-maven-plugin:2.15.4:run (default-cli) > test-compile @ Apache_Camel_As_WebLogic12c_EJB_Client >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Compiling 1 source file to /Apache_Camel_As_WebLogic_EJB_Client/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Apache_Camel_As_WebLogic_EJB_Client/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5:testCompile (default-testCompile) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] No sources to compile
[INFO] 
[INFO] <<< camel-maven-plugin:2.15.4:run (default-cli) < test-compile @ Apache_Camel_As_WebLogic12c_EJB_Client <<<
[INFO] 
[INFO] --- camel-maven-plugin:2.15.4:run (default-cli) @ Apache_Camel_As_WebLogic12c_EJB_Client ---
[INFO] Using org.apache.camel.spring.Main to initiate a CamelContext
[INFO] Starting Camel ...
[pache.camel.spring.Main.main()] MainSupport                    INFO  Apache Camel 2.15.0 starting
[pache.camel.spring.Main.main()] ClassPathXmlApplicationContext INFO  Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@32ef2304: startup date [Sun Nov 01 21:48:40 IST 2015]; root of context hierarchy
[pache.camel.spring.Main.main()] XmlBeanDefinitionReader        INFO  Loading XML bean definitions from file [/Apache_Camel_As_WebLogic_EJB_Client/target/classes/META-INF/spring/camel-context.xml]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.0 (CamelContext: camel-1) is starting
[pache.camel.spring.Main.main()] ManagedManagementStrategy      INFO  JMX is enabled
[pache.camel.spring.Main.main()] DefaultTypeConverter           INFO  Loaded 183 type converters
[pache.camel.spring.Main.main()] SpringCamelContext             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.
[pache.camel.spring.Main.main()] SpringCamelContext             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
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route: testCamelEJBClient started and consuming from: Endpoint[timer://foo?period=5000]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Total 1 routes, of which 1 is started.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.0 (CamelContext: camel-1) started in 0.751 seconds

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:44 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:49 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:54 IST 2015

[mel-1) thread #0 - timer://foo] testCamelEJBClient             INFO  [EJB Response] ===> [HelloBean] Says Hello, MiddlewareMagic!!!, Date: Sun Nov 01 21:48:59 IST 2015

Source Code:
The complete source code of this demo can be found at the following git repo:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/ApacheCamel/Apache_Camel_As_WebLogic_EJB_Client

.
.
Regards
Jay SenSharma


Writing WebLogic 12c based EJB 3.0 project and Standalone client using Maven Build

Hi,

As part of this demo we will see how to write a fully maven based WebLogic12c deployable application which will contain an EJB Project which we will deploy on WebLogic using the 12c specific maven plugin “wls-maven-plugin”. In the same sample we will use the “exec-maven-plugin” plugin as well to run our Remote Weblogic EJB Client code.

As part of this code was we will learn the following things:

1). Writing a simple EJB EAR project using Maven.
2). Deploying the EAR project on WebLogic 12c using “wls-maven-plugin”
3). Running a Simple EJB Client code with the help of “exec-maven-plugin”

So lets begin with writing the EJB Project.

Developing EJB Project

Step-1). First of all lets make a directory “WebLogic_EJB_Demo_Using_Maven” where we will keep both our “EJB_Project” and “EJB_Client_Project”.

    $ mkdir /WebLogic_EJB_Demo_Using_Maven
    $ mkdir -p /WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/src/main/application/META-INF
    $ mkdir -p /WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/src/main/java/ejb3

Step-2). Now we will write the “HelloRemote.java”, the remote interface of our Stateless EJB, Inside the “EJB_Project/TestEJB/src/main/java/ejb3”.

package ejb3;
import javax.ejb.*;
@Remote
public interface HelloRemote {
        public String sayHello(String name);
}

Step-3). Similarly we will write the Stateless Bean “HelloBean.java” inside the “EJB_Project/TestEJB/src/main/java/ejb3” as following

package ejb3;
import javax.ejb.*;
@Stateless
public class HelloBean implements HelloRemote {
        public String sayHello(String name) {
           System.out.println("\n\t hello("+name+") invoked, Hello HelloBean Date:  "+new java.util.Date());
           return "Hello, "+name+", Date: "+new java.util.Date();
        }
 }

Step-4). Now we will write the most important part. So lets create a maven build the file “pom.xml” inside the “/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB” directory.

<?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">

    <parent>
        <groupId>middleware.magic</groupId>
        <artifactId>WebLogic12_EJB_Demo_With_Maven</artifactId>
        <version>1.0</version>
    </parent>

    <properties>
        <ear.app.name>TestApp</ear.app.name>
        <ejb.jar.name>TestEJB</ejb.jar.name>
    </properties>
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>middleware.magic</groupId>
    <artifactId>TestEJB</artifactId>
    <version>1.0</version>
    <packaging>ejb</packaging>


    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
        	<groupId>javax.ejb</groupId>
        	<artifactId>ejb-api</artifactId>
        	<version>3.0</version>
            <scope>provided</scope>        	
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.0</ejbVersion>
                    <archive>
                        <manifest>
                            <useUniqueVersions>false</useUniqueVersions>
                            <addClasspath>false</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Step-5). Similarly we will write another “pom.xml” inside the “/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp” as following:

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

    <parent>
        <groupId>middleware.magic</groupId>
        <artifactId>WebLogic12_EJB_Demo_With_Maven</artifactId>
        <version>1.0</version>
    </parent>

    <properties>
        <ear.app.name>TestApp</ear.app.name>
        <ejb.jar.name>TestEJB</ejb.jar.name>
    </properties>
    
    <groupId>middleware.magic</groupId>
    <artifactId>TestApp</artifactId>
    <name>${artifactId}</name>
    <version>1.0</version>
    <packaging>ear</packaging>

    <dependencies>
        <dependency>
            <groupId>middleware.magic</groupId>
            <artifactId>TestEJB</artifactId>
            <version>1.0</version>
            <type>ejb</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <applicationName>${artifactId}</applicationName>
                    <finalName>${ear.app.name}</finalName>
                    <version>6</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <fileNameMapping>no-version</fileNameMapping>
                    <skinnyWars>true</skinnyWars>
                    <modules>
                        <ejbModule>
                            <groupId>middleware.magic</groupId>
                            <artifactId>${ejb.jar.name}</artifactId>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Step-6). So far we have written the child project pom.xml, Now lets write the main “pom.xml” file inside the “/WebLogic_EJB_Demo_Using_Maven/EJB_Project” as following:

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

    <groupId>middleware.magic</groupId>
    <artifactId>WebLogic12_EJB_Demo_With_Maven</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.7</java.version>
        <middleware.home>/PATH/TO/Installed/wls12130</middleware.home>  <!— CHANGE ME!!! —>
   	<admin.server.url>t3://localhost:7001</admin.server.url>  <!— CHANGE ME!!! —>
        <admin.username>weblogic</admin.username>                 <!— CHANGE ME!!! —>
        <admin.password>weblogic1</admin.password>                <!— CHANGE ME!!! —>
        <ear.app.name>TestApp</ear.app.name>                      
        <ejb.jar.name>TestEJB</ejb.jar.name>                       
    </properties>
    
    <modules>
        <module>${ejb.jar.name}</module>
        <module>${ear.app.name}</module>
    </modules>
    
    
    <dependencies>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  
  
    <build>
         <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>

            <plugin>
               <groupId>com.oracle.weblogic</groupId> 
               <artifactId>wls-maven-plugin</artifactId> 
               <version>12.1.3.0</version> 
               <configuration> 
                 <middlewareHome>${middleware.home}</middlewareHome>
                 <adminurl>${admin.server.url}</adminurl>
                 <user>${admin.username}</user>
                 <password>${admin.password}</password>
                 <name>${ear.app.name}</name>
                 <source>${ear.app.name}/target/${ear.app.name}.ear</source>          
               </configuration> 
            </plugin>  
         </plugins>
     </build>
     
</project>

Step-7). Now lets start the WebLogic server and then deploy the EJB project. In order to deploy the EJB Project, Open a terminal and then run the following commands. The Maven plugin will build the EAR containing the EJB as well as it will deploy it to WebLogic server.

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 /WebLogic_EJB_Demo_Using_Maven/EJB_Project
$ mvn clean install wls: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:\WebLogic_EJB_Demo_Using_Maven\EJB_Project
$ mvn clean install wls:deploy 

In case if you face any error / exception while running the WebLogic 12c Maven plugin “wls-maven-plugin” then please refer to the article:
http://middlewaremagic.com/weblogic/?p=8217

RAW Output of EJB Project Build and Deployment

$ mvn clean install wls:deploy
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for middleware.magic:TestApp:ear:1.0
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artifactId} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] WebLogic12_EJB_Demo_With_Maven
[INFO] TestEJB
[INFO] TestApp
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WebLogic12_EJB_Demo_With_Maven 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12_EJB_Demo_With_Maven ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12_EJB_Demo_With_Maven ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12_EJB_Demo_With_Maven/1.0/WebLogic12_EJB_Demo_With_Maven-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestEJB 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestEJB ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TestEJB ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ TestEJB ---
[INFO] Compiling 2 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TestEJB ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ TestEJB ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TestEJB ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-ejb-plugin:2.3:ejb (default-ejb) @ TestEJB ---
[INFO] Building EJB TestEJB-1.0 with EJB version 3.0
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/target/TestEJB-1.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TestEJB ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/target/TestEJB-1.0.jar to /Users/jsensharma/.m2/repository/middleware/magic/TestEJB/1.0/TestEJB-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestEJB/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/TestEJB/1.0/TestEJB-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestApp 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestApp ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target
[INFO] 
[INFO] --- maven-ear-plugin:2.9:generate-application-xml (default-generate-application-xml) @ TestApp ---
[INFO] Generating application.xml
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ TestApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/src/main/resources
[INFO] 
[INFO] --- maven-ear-plugin:2.9:ear (default-ear) @ TestApp ---
[INFO] Copying artifact [ejb:middleware.magic:TestEJB:1.0] to [TestEJB.jar]
[INFO] Building zip: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp-1.0/TestEJB.jar
[INFO] Copying artifact [jar:org.slf4j:slf4j-api:1.7.0] to [lib/slf4j-api.jar]
[INFO] Copy ear sources to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp-1.0
[INFO] Could not find manifest file: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp-1.0/META-INF/MANIFEST.MF - Generating one
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp.ear
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TestApp ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp.ear to /Users/jsensharma/.m2/repository/middleware/magic/TestApp/1.0/TestApp-1.0.ear
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/TestApp/1.0/TestApp-1.0.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WebLogic12_EJB_Demo_With_Maven 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- wls-maven-plugin:12.1.3.0:deploy (default-cli) @ WebLogic12_EJB_Demo_With_Maven ---
[INFO] ++====================================================================++
[INFO] ++  wls-maven-plugin: deploy                                          ++
[INFO] ++====================================================================++
weblogic.Deployer invoked with options:  -noexit -adminurl t3://localhost:7001 -user weblogic -deploy -name TestApp -source TestApp/target/TestApp.ear
<Oct 29, 2015 11:02:23 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, TestApp [archive: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Project/TestApp/target/TestApp.ear], to configured targets.> 
Task 0 initiated: [Deployer:149026]deploy application TestApp on myserver.
Task 0 completed: [Deployer:149026]deploy application TestApp on myserver.
Target state: deploy completed on Server myserver

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] WebLogic12_EJB_Demo_With_Maven ..................... SUCCESS [  2.781 s]
[INFO] TestEJB ............................................ SUCCESS [  0.824 s]
[INFO] TestApp ............................................ SUCCESS [  0.327 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.298 s
[INFO] Finished at: 2015-10-29T23:02:24+05:30
[INFO] Final Memory: 19M/310M
[INFO] ------------------------------------------------------------------------

Writing WebLogic EJB Client Code

Step-8). Now lets start writing the client project. So first of all lets make the following directories:

$ mkdir -p /WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/main/java/ejb3
$ mkdir -p /WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/main/java/client
$ mkdir -p /WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/main/resources

Step-9). Now lets first place the above created “HelloRemote.java” inside the “/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/main/java/ejb3” directory so that the client can use it.

package ejb3;
import javax.ejb.*;
@Remote
public interface HelloRemote {
        public String sayHello(String name);
}

Step-10). Now the main step of writing the EJB Client. So lets create a file “WebLogicEJBClient.java” inside the “/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/main/java/client” as following:

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

public class WebLogicEJBClient {
  public static void main(String ar[]) throws Exception {
    Context context = null;
	try {
          Properties props = new Properties();
          props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          props.put(Context.PROVIDER_URL, "t3://localhost:7001"); 
          //props.put(Context.SECURITY_PRINCIPAL, "ejbUserOne");
          //props.put(Context.SECURITY_CREDENTIALS, "ejbPasswordOne@123");
          context = new InitialContext(props);	
          
          System.out.println("\n\n****************************************");
	      System.out.println("\n\t[WebLogicEJBClient] Got initial Context: "+context);	

          String EJB_JNDI_NAME="java:global/TestApp/TestEJB/HelloBean!ejb3.HelloRemote";
          
          HelloRemote remote = (HelloRemote) context.lookup(EJB_JNDI_NAME);
          String result = remote.sayHello("MiddlewareMagic!!!");
          System.out.println("\n\t[WebLogicEJBClient] Got response from EJB : " + result);
          System.out.println("\n****************************************\n\n");
          
     } catch(Exception e) {
			e.printStackTrace();
     }     
   }
}

Step-11). Now lets run the EJB Client code 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 /WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project

$ mvn clean install exec:exec

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:\WebLogic_EJB_Demo_Using_Maven\EJB_Client_Project

$ mvn clean install exec:exec

RAW Output of Client Code Execution:


$ mvn clean install exec:exec



[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building WebLogic12_EJB_Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ WebLogic12_EJB_Client ---
[INFO] Deleting /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ WebLogic12_EJB_Client ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ WebLogic12_EJB_Client ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ WebLogic12_EJB_Client ---
[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/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ WebLogic12_EJB_Client ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ WebLogic12_EJB_Client ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ WebLogic12_EJB_Client ---
[INFO] Building jar: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/target/WebLogic12_EJB_Client-1.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ WebLogic12_EJB_Client ---
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/target/WebLogic12_EJB_Client-1.0.jar to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12_EJB_Client/1.0/WebLogic12_EJB_Client-1.0.jar
[INFO] Installing /Users/jsensharma/NotBackedUp/MM_Tests/WLS/FINAL_EJB_CAMEL/WebLogic_EJB_Demo_Using_Maven/EJB_Client_Project/pom.xml to /Users/jsensharma/.m2/repository/middleware/magic/WebLogic12_EJB_Client/1.0/WebLogic12_EJB_Client-1.0.pom
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:exec (default-cli) @ WebLogic12_EJB_Client ---


****************************************

	[WebLogicEJBClient] Got initial Context: javax.naming.InitialContext@1889f191

	[WebLogicEJBClient] Got response from EJB : Hello, MiddlewareMagic!!!, Date: Thu Oct 29 23:02:44 IST 2015

****************************************


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.231 s
[INFO] Finished at: 2015-10-29T23:02:45+05:30
[INFO] Final Memory: 14M/245M
[INFO] ------------------------------------------------------------------------

Source Code:
The complete source code of this demo can be found at the following git repo:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/EJB/WebLogic_EJB_Demo_Using_Maven
.
.
Regards
Jay SenSharma


WebLogic 12c JMS Bridge to connect to WildFly 8.2 HornetQ Broker.

Hi,

As part of this article we will see how to configure a JMS Message bridge on WebLogic 12c side so that any message sent to the JMS Queue present on WebLogic will be automatically transfered to WildFly 8.2 Instance. The WebLogic Messaging Bridge is a forwarding mechanism that provides interoperability between WebLogic JMS implementations, and between JMS and other messaging products. We are going to use the Messaging Bridge to integrate WildFly 8.2 offered HornetQ messaging broker communication. A messaging bridge instance forwards messages between a pair of bridge source and target destinations. These destinations are mapped to a pair of bridge source and target destinations. The messaging bridge reads messages from the source bridge destination and forwards those messages to the target bridge destination.

In order to know how to create a WebLogic Message bridge between WebLogic and JBoss 5 please refer to : http://middlewaremagic.com/weblogic/?p=6066

As part of this article we will learn:

1). How to create a WebLogic Message Bridge using WLST.
2). How to create a JMS Queue on WildFly 8.2 side.
NOTE: These steps will remain almost same for JBoss AS7 or JBoss EAP6, the only change will be in the Connection URL of WildFly or JBossAS. In WildFly we use “http-remoting://localhost:8080” where as in JBossAS7/EAP6 we use “remote://localhost:4447”).
3). Then we will send some messages to WebLogic JMS Queues and will receive them from WildFly 8.2 JMS Queues.

Creating A Simple JMS Queue on WildFLy 8.2 side

Step-1). Start the WildFly 8.2 (or JBoss EAP6/JBossAS7) full profile (which has messaging) as following:

   $ cd /PATH/TO/wildfly-8.2.1.Final/bin
   $ ./standalone.sh -c standalone-full.xml

I am running Weblogic 12c and WildFLy on the same host hence i am running both on “localhost” users can change it based on their need.

Step-2). Create a simple JMS user on WildFly 8.2 side and this user must belong to “guest” role. Please see the “messaging subsystem” configuration of “standalone-full.xml” to know more about “guest” role.
username: jmsuser
password: jmsuser@123
user role: guest
Realm: ApplicationRealm

   $ cd /PATH/TO/wildfly-8.2.1.Final/bin
   $ ./add-user.sh 

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): b

Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : jmsuser
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
 - The password should be different from the username
Password :  jmsuser@123
Re-enter Password :  jmsuser@123
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: guest
About to add user 'jmsuser' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Added user 'jmsuser' to file '/PATH/TO/wildfly-8.2.1.Final/standalone/configuration/application-users.properties'
Added user 'jmsuser' to file '/PATH/TO/wildfly-8.2.1.Final/domain/configuration/application-users.properties'
Added user 'jmsuser' with groups guest to file '/PATH/TO/wildfly-8.2.1.Final/standalone/configuration/application-roles.properties'
Added user 'jmsuser' with groups guest to file '/PATH/TO/wildfly-8.2.1.Final/domain/configuration/application-roles.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="am1zdXNlckAxMjM=" />

Step-3). Creating a simple JMS Queue using the WildFly CLI command line utility. NOTE the JNDI name should contain “java:/jboss/exported” prefix or else the JMS queue will can not be looked up remotely.

   $ cd /PATH/TO/wildfly-8.2.1.Final/bin
   $ ./jboss-cli.sh -c
   
   [standalone@localhost:9990 /] /subsystem=messaging/hornetq-server=default/jms-queue=TestQ/:add(entries=["java:/jboss/exported/jms/queue/TestQ"],durable=false)
     {"outcome" => "success"}
     
   [standalone@localhost:9990 /] :reload
     {
       "outcome" => "success",
       "result" => undefined
     }

Starting WebLogic 12c and configuring it

First of all Copy the WildFly client jar “/PATH/TO/wildfly-8.2.1.Final/bin/client/jboss-client.jar” and place it inside the “$DOMAIN_HOME/lib” directory of WebLogic 12c.

Step-4). Start WebLogic 12c normally.

   $ cp -f /PATH/TO/wildfly-8.2.1.Final/bin/client/jboss-client.jar     /PATH/TO/wls12130/user_projects/domains/mydomain/lib

   $ cd /PATH/TO/wls12130/user_projects/domains/mydomain/bin
   $ ./startWebLogic.sh

Writing WLST script to configure JMS Bridge

Step-5). Now create a directory like “WebLogic_JMS_Bridge” where we will place our project artifacts.

   $ mkdir  WebLogic_JMS_Bridge
   $ cd WebLogic_JMS_Bridge

Step-6). Inside the “WebLogic_JMS_Bridge” directory write the following kind of file “domain.properties” which will contain all the configuration details.


############ 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 = myserver
 
# 3 - SystemModule Details
system.module.name = My_SystemModule
tragated.system.module.name = myserver
 
# 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


############ JMS Bridge related Configuration #########
weblogic.destination.bridge = WLS_Source_Bridge
weblogic.adapter.jndi.name = eis.jms.WLSConnectionFactoryJNDINoTX


wildfly.destination.bridge = WildFly_Destination_Bridge
wildfly.server.url = http-remoting://localhost:8080

# When using JBoss EAP6 or JBossAS7 then change the URL to following:
# wildfly.server.url =remote://localhost:4447

wildfly.initial.context.factory = org.jboss.naming.remote.client.InitialContextFactory
wildfly.remote.connection.factory.jndi.name = jms/RemoteConnectionFactory
wildfly.jms.destination.jndi.name = jms/queue/TestQ

wildfly.jms.username = jmsuser
wildfly.jms.password = jmsuser@123

Step-7). Now we will write simple WLST Script to configure the JMS Bridge , Create JMS Queue, JMS ConnectionFactory on WebLogic side. So write a file like “weblogicJMS_Setup.py” inside the same directory “WebLogic_JMS_Bridge” as following:

#############################################################################
#
# @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 - Unit Of Order Details
print "================== Unit Of Order ==================="
startEdit()
cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/ConnectionFactories/'+connectionFactoryName+'/DefaultDeliveryParams/'+connectionFactoryName)
cmo.setDefaultUnitOfOrder(unitOfOrderValue)
print "Changed Unit Of Order !!"
activate()
print ""
 
# 6 - 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 ""



print "================== Creating  WebLogic Destination Bridge ==================="
startEdit()
cd('/')
cmo.createJMSBridgeDestination(weblogicDestinationBridge)
cd('/JMSBridgeDestinations/'+weblogicDestinationBridge)
cmo.setConnectionURL(serverUrl)
cmo.setAdapterJNDIName(weblogicAdapterJNDINoTX)
cmo.setConnectionFactoryJNDIName(ConnectionFactoryJNDIName)
cmo.setDestinationJNDIName(queueJNDIName)
activate()


print "================== Creating  WildFly Destination Bridge ==================="
startEdit()
cd('/')
cmo.createJMSBridgeDestination(wildflyDestinationBridge)
cd('/JMSBridgeDestinations/'+wildflyDestinationBridge)
cmo.setConnectionURL(wildflyServerUrl)
cmo.setAdapterJNDIName(weblogicAdapterJNDINoTX)
cmo.setConnectionFactoryJNDIName(wildflyJMSConnectionFactory)
cmo.setDestinationJNDIName(wildflyJMSQueueJndi)
activate()

startEdit()
cd('/JMSBridgeDestinations/'+weblogicDestinationBridge)
cmo.setUserName(Username)
cmo.setUserPassword(Password)
activate()

startEdit()
cd('/JMSBridgeDestinations/'+wildflyDestinationBridge)
cmo.setUserName(wildflyJMSUsername)
cmo.setUserPassword(wildflyJMSUserPassword)
cmo.setInitialContextFactory(wildflyInitialContextFactory);
activate()

print "================== Creating  JMS Bridge on WebLogic12c ==================="
startEdit()
cd('/')
cmo.createMessagingBridge('WLS12c_to_WildFly8_Bridge')
cd('/MessagingBridges/WLS12c_to_WildFly8_Bridge')
set('Targets',jarray.array([ObjectName('com.bea:Name=myserver,Type=Server')], ObjectName))
cmo.setSourceDestination(getMBean('/JMSBridgeDestinations/'+weblogicDestinationBridge))
cmo.setTargetDestination(getMBean('/JMSBridgeDestinations/'+wildflyDestinationBridge))
cmo.setStarted(true)
cmo.setSelector('')
cmo.setQualityOfService('Atmost-once')
activate()

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

Step-8). Now we will run the WLST script. As following:

   $ cd /PATH/TO/wls12130/user_projects/domains/mydomain/bin
   $ . ./setDomainEnv.sh
   $ cd /PATH/TO/WebLogic_JMS_Bridge
   $  java  weblogic.WLST  webLogicJMS_Setup.py
   
   
   
   OUTPUT:
   
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 !!

================== Unit Of Order ===================
Changed Unit Of Order !!

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

================== Creating  WebLogic Destination Bridge ===================
================== Creating  WildFly Destination Bridge ===================
================== Creating  JMS Bridge on WebLogic12c ===================

Writing Java Code to send messages to WebLogic JMS Queue

Step-9). Now In the “WebLogic_JMS_Bridge” create a sub directory with name “src” where we will create file “QueueSend.java”:

import java.io.IOException;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QueueSend {
  public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
  public final static String JMS_FACTORY="My_CF";
  public final static String QUEUE="My_Q";

  private QueueConnectionFactory qconFactory;
  private QueueConnection qcon;
  private QueueSession qsession;
  private QueueSender qsender;
  private Queue queue;
  private TextMessage msg;

  public void init(Context ctx, String queueName) throws NamingException, JMSException {
    qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
    qcon = qconFactory.createQueueConnection();
    qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queue = (Queue) ctx.lookup(queueName);
    qsender = qsession.createSender(queue);
    msg = qsession.createTextMessage();
    qcon.start();
  }

  public void send(String message,int counter) throws JMSException {
    msg.setText(message);
    msg.setIntProperty("counter", counter);
    qsender.send(msg);
  }

  public void close() throws JMSException {
    qsender.close();
    qsession.close();
    qcon.close();
  }

  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.out.println("Usage: java QueueSend WebLogicURL");
      return;
    }
    InitialContext ic = getInitialContext(args[0]);
    QueueSend qs = new QueueSend();
    qs.init(ic, QUEUE);
    readAndSend(qs);
    qs.close();
  }

  private static void readAndSend(QueueSend qs) throws IOException, JMSException {
    String line="Test Message Body with counter = ";
    for(int i=0;i<10;i++) {
          qs.send(line+i,i);
          System.out.println("JMS Message Sent: "+line+i+"\n");
       }
  }

  private static InitialContext getInitialContext(String url) throws NamingException {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
    env.put(Context.PROVIDER_URL, url);
    return new InitialContext(env);
  }
}

Step-10). Now we will write a simple ANT “build.xml” file inside the “WebLogic_JMS_Bridge” as following:

<project name="ApplicationLevelJMSDemo" default="run">
<property name="wls.home" value="/Users/jsensharma/NotBackedUp/Installed/wls12130" /> <!-- CHANGE ME!! -->
<property name="basedir" value="." />
<property name="tmp.dir" value="tmp" />
<property name="output.dir" value="build" />
<property name="src.dir" value="src" />
<property name="client.jar.name" value="jms_WLS_Client.jar" />

        <path id="wls.classpath">
             <fileset dir="${wls.home}">
                 <include name="**/*.jar"/>
             </fileset>
        </path>
        <target name="init">
           <delete dir="${output.dir}" />
           <mkdir dir="${output.dir}" />
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
        </target>

        <target name="run">
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
           <javac srcdir="${src.dir}" destdir="${tmp.dir}"  includes="QueueSend.java" classpathref="wls.classpath"/>
           <jar jarfile="${output.dir}/${client.jar.name}" basedir="${tmp.dir}" compress="true" />
           <java classname="QueueSend" fork="true">
               <classpath>
                  <pathelement location="${tmp.dir}"/>
                  <path refid="wls.classpath"/>
               </classpath>
               <arg value="t3://localhost:7001"/>
           </java>
           <delete dir="${tmp.dir}" />
        </target>  
</project>

Make sure to change the “wls.home” to point to your own WebLogic installation in this file.

Step-11). Now lets run the ANT project to send some messages to WLS “My_Q”

     $ cd /PATH/TO/WebLogic_JMS_Bridge
     $ export ANT_HOME=/PATH/TO/apache_ant_1.9.2
     $ export JAVA_HOME=/PATH/TO/jdk1.8.0_60
     $ export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
     
     $ ant
     
     
     OUTPUT:
     Buildfile: /Users/jsensharma/NotBackedUp/MM_Tests/WLS/JMS_Bridge/build.xml

run:
    [mkdir] Created dir: /PATH/TO/WebLogic_JMS_Bridge/tmp
    [javac] /Users/jsensharma/NotBackedUp/MM_Tests/WLS/JMS_Bridge/build.xml:28: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 1 source file to /PATH/TO/WebLogic_JMS_Bridge/tmp
    [javac] warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.8'
    [javac] warning: Supported source version 'RELEASE_6' from annotation processor 'org.sonatype.guice.bean.scanners.index.SisuIndexAPT6' less than -source '1.8'
    [javac] Note: /PATH/TO/WebLogic_JMS_Bridge/src/QueueSend.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 2 warnings
      [jar] Building jar: /PATH/TO/WebLogic_JMS_Bridge/build/jms_WLS_Client.jar
      JMS Message Sent: Test Message Body with counter = 0
      
      JMS Message Sent: Test Message Body with counter = 1
      
      JMS Message Sent: Test Message Body with counter = 2
      
      JMS Message Sent: Test Message Body with counter = 3
      
      JMS Message Sent: Test Message Body with counter = 4
      
      JMS Message Sent: Test Message Body with counter = 5
      
      JMS Message Sent: Test Message Body with counter = 6
      
      JMS Message Sent: Test Message Body with counter = 7
      
      JMS Message Sent: Test Message Body with counter = 8
      
      JMS Message Sent: Test Message Body with counter = 9
      
   [delete] Deleting directory /PATH/TO/WebLogic_JMS_Bridge/tmp

BUILD SUCCESSFUL
Total time: 4 seconds

Step-12). Now login to WildFly 8.2 console and then check the JMS Queue “TestQ” runtime stats whether those messages reached to it or not.
http://localhost:9990/console/App.html#jms-metrics

Reference

I am just pasting the WebLogic side JMS Bridge configuration XML snippet here from “config.xml”

  <messaging-bridge>
    <name>WLS12c_to_WildFly8_Bridge</name>
    <target>myserver</target>
    <source-destination>WLS_Source_Bridge</source-destination>
    <target-destination>WildFly_Destination_Bridge</target-destination>
    <selector></selector>
    <quality-of-service>Atmost-once</quality-of-service>
    <started>true</started>
  </messaging-bridge>
  .
  .
  .
  <jms-server>
    <name>My_JMSServer</name>
    <target>myserver</target>
    <persistent-store xsi:nil="true"></persistent-store>
  </jms-server>
  
  <jms-bridge-destination>
    <name>WLS_Source_Bridge</name>
    <adapter-jndi-name>eis.jms.WLSConnectionFactoryJNDINoTX</adapter-jndi-name>
    <user-name>weblogic</user-name>
    <user-password-encrypted>{AES}MZthQtsuT4GH55R5es9TQFUOU8dK8tvLy5xJl5DcN1E=</user-password-encrypted>
    <connection-factory-jndi-name>My_CF</connection-factory-jndi-name>
    <connection-url>t3://localhost:7001</connection-url>
    <destination-jndi-name>My_Q</destination-jndi-name>
  </jms-bridge-destination>
  
  <jms-bridge-destination>
    <name>WildFly_Destination_Bridge</name>
    <adapter-jndi-name>eis.jms.WLSConnectionFactoryJNDINoTX</adapter-jndi-name>
    <user-name>jmsuser</user-name>
    <user-password-encrypted>{AES}0hlGNKwgZkSw+YxjxJSAbkPJm0EnV5tn5Czd5CLTJgk=</user-password-encrypted>
    <connection-factory-jndi-name>jms/RemoteConnectionFactory</connection-factory-jndi-name>
    <initial-context-factory>org.jboss.naming.remote.client.InitialContextFactory</initial-context-factory>
    <connection-url>http-remoting://localhost:8080</connection-url>
    <destination-jndi-name>jms/queue/TestQ</destination-jndi-name>
  </jms-bridge-destination>
  
  <jms-system-resource>
    <name>My_SystemModule</name>
    <target>myserver</target>
    <sub-deployment>
      <name>Sub_My_Queue</name>
      <target>My_JMSServer</target>
    </sub-deployment>
    <descriptor-file-name>jms/my_systemmodule-jms.xml</descriptor-file-name>
  </jms-system-resource>

Source Code: All the relative contents can be found in the following link:
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WebLogic/JMS/WebLogic_JMS_Bridge

Regards
Jay SenSharma


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