ANT

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


Changing the context-param values of web.xml using plan.xml

Ravish Mody

Here we are going to see how we can change the “<context-param>”  child tag values using plan.xml file. Many times we see that the values are not getting changed or reflected by plan.xml file updates even if every step looks correct.

NOTE: The plan.xml feature works on Xpath and which is applicable on the XSD based xml files. So it would not work for DTD based web.xml file.  So make sure that you use the weblogic.DDConverter utility to convert the web.xml to use the latest XSD based deployment descriptors. To get more information on it do have a look at this post How to use the weblogic.DDConverter tool ?

Steps To change the context-param values of web.xml using plan.xml

Step1).  Create a web application  in some location like: (C:/DemoPlan/SampleWebApp)

Step2).  Now create a “web.xml” file like following inside “C:/DemoPlan/SampleWebApp/WEB-INF” directory:

<!---------------- DO NOT use the DTDs inside your XML file if you want to use plan.xml------------------
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <context-param id="one">
        <param-name>TokenGroup</param-name>
        <param-value>oldvalue</param-value>
    </context-param>
</web-app>
-----------------------Please ignore the above web.xml content -------------------------------------------->

<?xml version='1.0' encoding='WINDOWS-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <context-param id="one">
    <param-name>TokenGroup</param-name>
    <param-value>oldvalue</param-value>
  </context-param>
</web-app>

Step3).  Now we need to create a “index.jsp” inside “C:/DemoPlan/SampleWebApp” like following to read the context-param values defined inside the “web.xml” file.

<html>
<head><title>Hi</title><head>
<body bgcolor=maroon text=white>

<%
     String param = application.getInitParameter("TokenGroup");
     out.println("<h3>TokenGroup : "+param);
     System.out.println("ntTokenGroup : "+param);
%>

</body>
</html>

Step4).  Now write the following kind of “plan.xml” file inside any directory like “C:/DemoPlan/”
NOTE: you need to make sure that the  <config-root>Should contain a valid directory path which contains the plan.xml file.</config-root>

<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
  <application-name>SimpleWebApp</application-name>

  <variable-definition>
      <variable>
          <name>newVariable</name>
          <value>Key123456</value>
      </variable>
  </variable-definition>

  <module-override>
    <module-name>SimpleWebApp</module-name>
    <module-type>war</module-type>

    <module-descriptor external="false">
      <root-element>web-app</root-element>
      <uri>WEB-INF/web.xml</uri>
      <variable-assignment>
         <name>newVariable</name>
         <xpath>/web-app/context-param/[param-name="TokenGroup"]/param-value</xpath>
         <operation>add</operation>
      </variable-assignment>
    </module-descriptor>

  </module-override>
  <config-root>C:/DemoPlan/</config-root>
</deployment-plan>

Step5). Now just to simplify the deployment and un-deployment task we can write the build.xml file  to make the things automated.

<project name="webservices-hello_world" default="deploy">
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="10.10.10.10" />
<property name="wls.port" value="7001" />
<property name="admin.server.name" value="AdminServer" />
<property name="deploy.target" value="AdminServer" />

<property name="deploy.name" value="SimpleWebApp" />
<property name="deploy.source" value="SimpleWebApp" />
<property name="plan.xml.path" value="C:/DemoPlan//plan.xml" />

<!-- Setting TaskDefinition -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="C:/bea103/wlserver_10.3/server/lib/weblogic.jar"/>
</classpath>
</taskdef>

<!-- Deploying Applications  -->
<target name="deploy">
<wldeploy action="deploy"
          name="${deploy.name}"
          source="${deploy.source}"
          user="${wls.username}"
          nostage="true"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<target name="redeployWithPlan">
<wldeploy action="redeploy"
          name="${deploy.name}"
          plan="${plan.xml.path}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Redeploying Applications  -->
<target name="redeploy">
<wldeploy action="redeploy"
          name="${deploy.name}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Uneploying Applications  -->
<target name="undeploy">
<wldeploy action="undeploy"
          name="${deploy.name}"
          failonerror="false"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>
</project>

Step6). Now deploy your application after running the setWLSEnv.cmd in the command prompt like following:

ant deploy

Step7). Now access the application like http://hostName:port/SampleWebApp/index.jsp   you will notice that the  page displays the value of TokenGroup as “oldvalue” which is defined in the web.xml .

Step8). Now again redeploy your application using the plan.xml file  which is specified in the  “build.xml” file as following:

ant redeployWithPlan

Step9).  Now as soon as you will hit your application “http://hostName:port/SampleWebApp/index.jsp” you will see that the page displays the value of TokenGroup as “Key123456

Thanks
Ravish Mody

Comments Off on Changing the context-param values of web.xml using plan.xml more...

Deploy Multiple Applications Remotely Using ANT

Ravish Mody

Today, one of our subscriber Kiran using comment asked us that how can he deploy more then one application remotely that to using ANT script. Thus we create this script which would do the same job very easily.

The logic behind this script is the that, we have used upload and depends. To cut the story sort the value of default which is on the line-1 is given as deploy3 and the target name for deploy2 has dependency on the deployment of application-1 same way the target name for deploy3 has dependency on the deployment of application-2. Thus till the application-1 is not deployed other applications would not deploy, this way all the application are been deployed one by one.

Steps To Create An ANT Script to Deploy Multiple Applications Remotely:

Step1) Create a “build.xml” file with the following details in it (i.e just copy the below snip-code).

<project name="webservices-hello_world" default="deploy3">
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="10.10.10.10" />
<property name="wls.port" value="7001" />
<property name="admin.server.name" value="AdminServer" />

<!-- Deploying Target -->
<property name="deploy.target" value="AdminServer" />

<!-- Details for Application-1 -->
<property name="deploy.name.1" value="TestApp1" />
<property name="deploy.source.1" value="TestApp1.war" />

<!-- Details for Application-2 -->
<property name="deploy.name.2" value="TestApp2" />
<property name="deploy.source.2" value="TestApp2.war" />

<!-- Details for Application-3 -->
<property name="deploy.name.3" value="TestApp3" />
<property name="deploy.source.3" value="TestApp3.war" />

<!-- Setting TaskDefinition -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="C:/bea103/wlserver_10.3/server/lib/weblogic.jar"/>
</classpath>
</taskdef>

<!-- Deploying Applications  -->
<target name="deploy1">
<wldeploy action="deploy"
	  upload="true"
          name="${deploy.name.1}"
          source="${deploy.source.1}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Deploying Applications-2 DEPENDS on Deployment of Applications-1 -->

<target name="deploy2" depends="deploy1">
<wldeploy action="deploy"
	  upload="true"
          name="${deploy.name.2}"
          source="${deploy.source.2}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Deploying Applications-3 DEPENDS on Deployment of Applications-2 -->

<target name="deploy3" depends="deploy2">
<wldeploy action="deploy"
	  upload="true"
          name="${deploy.name.3}"
          source="${deploy.source.3}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>
</project>

Step2) Open a prompt and then run (setWLSenv.cmd/sh  or setDomainEnv.sh/cmd)

Step3) To deploy the applications move to the current directory where ever you have placed both “build.xml” and all the application “TestApp1.war” ,“TestApp2.war” and “TestApp3.war” and then run the following command.

ant

Step4) The output would be like follows

ant
Buildfile: build.xml

deploy1:
 [wldeploy] weblogic.Deployer -verbose -upload -noexit -name TestApp1 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp1.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -password ******** -deploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -upload -noexit -name TestApp1 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp1.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -deploy
 [wldeploy] <Feb 11, 2011 6:12:53 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, TestApp1 [archive: /home/rmody/JBoss_Data/Samples/WLS/TestApp1.war], to AdminServer .>
 [wldeploy] Task 0 initiated: [Deployer:149026]deploy application TestApp1 on AdminServer.
 [wldeploy] Task 0 completed: [Deployer:149026]deploy application TestApp1 on AdminServer.
 [wldeploy] Target state: deploy completed on Server AdminServer

 [wldeploy] Target Assignments:
 [wldeploy] + TestApp1  AdminServer

deploy2:
 [wldeploy] weblogic.Deployer -verbose -upload -noexit -name TestApp2 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp2.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -password ******** -deploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -upload -noexit -name TestApp2 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp2.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -deploy
 [wldeploy] <Feb 11, 2011 6:12:54 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, TestApp2 [archive: /home/rmody/JBoss_Data/Samples/WLS/TestApp2.war], to AdminServer .>
 [wldeploy] Task 1 initiated: [Deployer:149026]deploy application TestApp2 on AdminServer.
 [wldeploy] Task 1 completed: [Deployer:149026]deploy application TestApp2 on AdminServer.
 [wldeploy] Target state: deploy completed on Server AdminServer

 [wldeploy] Target Assignments:
 [wldeploy] + TestApp2  AdminServer

deploy3:
 [wldeploy] weblogic.Deployer -verbose -upload -noexit -name TestApp3 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp3.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -password ******** -deploy
 [wldeploy] weblogic.Deployer invoked with options:  -verbose -upload -noexit -name TestApp3 -source /home/rmody/JBoss_Data/Samples/WLS/TestApp3.war -targets AdminServer -adminurl t3://10.10.10.10:7001 -user weblogic -deploy
 [wldeploy] <Feb 11, 2011 6:12:56 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, TestApp3 [archive: /home/rmody/JBoss_Data/Samples/WLS/TestApp3.war], to AdminServer .>
 [wldeploy] Task 2 initiated: [Deployer:149026]deploy application TestApp3 on AdminServer.
 [wldeploy] Task 2 completed: [Deployer:149026]deploy application TestApp3 on AdminServer.
 [wldeploy] Target state: deploy completed on Server AdminServer

 [wldeploy] Target Assignments:
 [wldeploy] + TestApp3  AdminServer

BUILD SUCCESSFUL
Total time: 5 seconds

That it, now if you check in your remote box under the server on which you have deployed the applications it would have the following directory structure and then check you console under deployments you would notice that all the applications are been deployed.

Path:

Application-1

<BEA_HOME>user_projects/domains/<YOUR_DOMAIN>/servers/AdminServer/upload/TestApp1/app/TestApp1.war

Application-2

<BEA_HOME>user_projects/domains/<YOUR_DOMAIN>/servers/AdminServer/upload/TestApp2/app/TestApp2.war

Application-3

<BEA_HOME>user_projects/domains/<YOUR_DOMAIN>/servers/AdminServer/upload/TestApp3/app/TestApp3.war

========================================

Issues:

Suppose if you get following kind of error while deploying from a remote machine:
Caused by: javax.naming.NamingException: Couldn’t connect to any host [Root exception is org.omg.CORBA.OBJECT_NOT_EXIST: Unknown object in LOCATE_REQUEST vmcid: 0x0 minor code: 0

[wldeploy] Caused by: weblogic.deploy.api.spi.exceptions.ServerConnectionException: [J2EE Deployment SPI:260010]Unable to connect to 't3://he3unxd189v01:9100' as user, 'weblogic'. Error received: Couldn't connect to any host
[wldeploy] at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.getMBeanServer(ServerConnectionImpl.java:251)
[wldeploy] at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.getMBeanServerForType(ServerConnectionImpl.java:191)
[wldeploy] at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.init(ServerConnectionImpl.java:147)
[wldeploy] at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.getNewConnection(WebLogicDeploymentManagerImpl.java:148)
[wldeploy] at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.<init>(WebLogicDeploymentManagerImpl.java:118)
[wldeploy] ... 32 more
[wldeploy] Caused by: java.io.IOException: Couldn't connect to any host
[wldeploy] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:156)
[wldeploy] at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:79)
[wldeploy] at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:338)
[wldeploy] at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
[wldeploy] at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.getMBeanServer(ServerConnectionImpl.java:240)
[wldeploy] ... 36 more
[wldeploy] Caused by: javax.naming.NamingException: Couldn't connect to any host [Root exception is org.omg.CORBA.OBJECT_NOT_EXIST: Unknown object in LOCATE_REQUEST vmcid: 0x0 minor code: 0 completed: No]
[wldeploy] Caused by: javax.naming.NamingException: Couldn't connect to any host [Root exception is org.omg.CORBA.OBJECT_NOT_EXIST: Unknown object in LOCATE_REQUEST vmcid: 0x0 minor code: 0 completed: No]
[wldeploy] at weblogic.corba.j2ee.naming.Utils.wrapNamingException(Utils.java:83)
[wldeploy] at weblogic.corba.j2ee.naming.ORBHelper.getORBReferenceWithRetry(ORBHelper.java:590)
[wldeploy] at weblogic.corba.j2ee.naming.ORBHelper.getORBReference(ORBHelper.java:547)
[wldeploy] at weblogic.corba.j2ee.naming.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:85)
[wldeploy] at weblogic.corba.j2ee.naming.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:31)
[wldeploy] at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:41)
[wldeploy] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
[wldeploy] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
[wldeploy] at javax.naming.InitialContext.init(InitialContext.java:223)
[wldeploy] at javax.naming.InitialContext.<init>(InitialContext.java:197)
[wldeploy] at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:143)
[wldeploy] ... 40 more
[wldeploy] Caused by: org.omg.CORBA.OBJECT_NOT_EXIST: Unknown object in LOCATE_REQUEST vmcid: 0x0 minor code: 0 completed: No
[wldeploy] at weblogic.iiop.LocateReplyMessage.needsForwarding(LocateReplyMessage.java:171)
[wldeploy] at weblogic.iiop.IORManager.locateInitialReference(IORManager.java:254)
[wldeploy] at weblogic.corba.orb.ORB.resolve_initial_references(ORB.java:258)
[wldeploy] at weblogic.corba.client.naming.ClientORBInfo.<init>(ClientORBInfo.java:34)
[wldeploy] at weblogic.corba.client.naming.ClientORBHelper.createORBInfo(ClientORBHelper.java:42)
[wldeploy] at weblogic.corba.j2ee.naming.ORBHelper.cacheORB(ORBHelper.java:314)
[wldeploy] at weblogic.corba.j2ee.naming.ORBHelper.cacheORBAndCreateURL(ORBHelper.java:323)
[wldeploy] at weblogic.corba.j2ee.naming.ORBHelper.getORBReferenceWithRetry(ORBHelper.java:583)

Then please make sure to add “wlfullclient.jar” at the beginning of the CLASSPATH in your ANT Script…Also please refer to http://forums.oracle.com/forums/thread.jspa?threadID=2188580&tstart=0

And to khow to make wlfullclient.jar in weblogic please refer to: http://middlewaremagic.com/weblogic/?p=558


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