JMS - Java Message Service



Interfacing: 1) J2EE stand-alone client - 2) Weblogic 8.1sp4 - 3) Websphere MQ version 6.0

This example will create a client, using external file-based JNDI, sending messages to a MQ - which subsequely is caught by a Message Driven Bean (MDB) running from a Weblogic 8.1 installation.

Initially, we will run without a security manager and require that the MQ installation and the J2EE applications are running from the same machine. Later will introduce the security manager and perform authentication from another machine.

First, edit the JMSAdmin.config file under IBM\WebSphereMQ\Java\bin installation to set the external JNDI provider Context Factory:


setting up JMSAdmin configuration in the MQ installation
JMSAdmin.config

...
	INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
	#INITIAL_CONTEXT_FACTORY=com.sun.jndi.ldap.LdapCtxFactory
	#INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
	#INITIAL_CONTEXT_FACTORY=com.ibm.ejs.ns.jndi.CNInitialContextFactory
	#INITIAL_CONTEXT_FACTORY=com.ibm.websphere.naming.WsnInitialContextFactory
	#
	#  The following line specifies the URL of the service provider's initial
	#  context. It currently refers to an LDAP root context. Examples of a
	#  file system URL and WebSphere's JNDI namespace are also shown, commented
	#  out.
	#
	PROVIDER_URL=file:/C:/jms-jndi-directory
	#PROVIDER_URL=ldap://localhost:389/ou=Groups,o=Airius.com
	#PROVIDER_URL=ldap://polaris/o=ibm,c=us
	#PROVIDER_URL=file:/C:/JNDI-Directory
	#PROVIDER_URL=iiop://localhost/
...
	#
	#  The following line specifies the security authentication model in use,
	#  and may be 'none' (for anonymous authentication), 'simple', or 'CRAM_MD5'.
	#
	SECURITY_AUTHENTICATION=none
...

	#Leave out the following entries as they probably already are
	#PROVIDER_USERDN
	#PROVIDER_PASSWORD
...



Secondly, it's necessary to configure the Websphere MQ version 6.0 installation by defining the QUEUE manager... Calling it BEAMQ (after all, we're using it with BEA Weblogic server).

Start the MQ navigator and define the queue manager using standard settings...

Websphere MQ navigator definition of new queue manager

MQ navigator wizard for queue manager

Make sure you define a port not already used. Choosing port 1421 here - but that could practically be any other port not already used...

Websphere MQ setup of queue manager

Once the queue manager is in place, define the actual queue. Basicly, it means accepting all recommended standard settings.

Websphere MQ queue setup wizard

Websphere MQ local queue setup

Websphere MQ local queue setup

Websphere MQ local queue setup

Set up the external JNDI provider through JMSAdmin - with definitions matching the queue manager and queue, defined above.


setting up external JNDI through JMSAdmin
MQSC commands


define qcf(TOPSECURITY_QCF) qmgr(BEAQM) channel(SYSTEM.DEF.SVRCONN) hostname(semp20) port(1421) transport(CLIENT)
define q(TOPSECURITY.QUEUE) queue(TOPSECURITY.QUEUE) qmgr(BEAQM)


Basicly this means the name of the machine with the MQ installation is "semp20" (2GHz sempron) and the queue manager operates from port 1421.

JMSAdmin management console start command

JMSAdmin management console

Once having configured the external JNDI provider, you should be able to locate a file c:\jms-jndi\directory\.bindings with plain-text contents as outlined in the following. As a routine check, you'll find the port/machine name from above.


After configuration using JMSAdmin..
c:\jms-jndi-directory\.bindings

#This file is used by the JNDI FSContext.
#Sun Aug 14 16:56:00 CEST 2005
TOPSECURITY.QUEUE/RefAddr/7/Encoding=String
TOPSECURITY_QCF/RefAddr/6/Encoding=String
TOPSECURITY.QUEUE/RefAddr/8/Type=QU
TOPSECURITY_QCF/RefAddr/16/Type=LA
TOPSECURITY_QCF/RefAddr/5/Type=CHAN
TOPSECURITY_QCF/RefAddr/8/Encoding=String
TOPSECURITY_QCF/RefAddr/12/Encoding=String
TOPSECURITY_QCF/RefAddr/3/Content=semp20
TOPSECURITY.QUEUE/RefAddr/9/Type=QMGR
TOPSECURITY_QCF/RefAddr/17/Content=5000
TOPSECURITY_QCF/RefAddr/1/Content=1
TOPSECURITY_QCF/RefAddr/14/Encoding=String
TOPSECURITY.QUEUE/RefAddr/2/Type=PRI
TOPSECURITY_QCF/RefAddr/10/Type=SFIPS
TOPSECURITY_QCF/RefAddr/15/Content=1
TOPSECURITY_QCF/RefAddr/21/Type=MRET
TOPSECURITY_QCF/RefAddr/16/Encoding=String
TOPSECURITY_QCF/RefAddr/13/Content=5000
TOPSECURITY.QUEUE/RefAddr/9/Encoding=String
TOPSECURITY.QUEUE/RefAddr/8/Content=TOPSECURITY.QUEUE
TOPSECURITY.QUEUE/ClassName=com.ibm.mq.jms.MQQueue
TOPSECURITY_QCF/RefAddr/18/Encoding=String
TOPSECURITY.QUEUE/RefAddr/6/Content=273
TOPSECURITY.QUEUE/RefAddr/4/Content=1208
TOPSECURITY_QCF/RefAddr/17/Type=RINT
TOPSECURITY_QCF/RefAddr/6/Type=CCS
TOPSECURITY.QUEUE/RefAddr/3/Type=PER
TOPSECURITY_QCF/RefAddr/11/Type=SPAG
TOPSECURITY_QCF/RefAddr/0/Type=VER
TOPSECURITY_QCF/RefAddr/11/Content=false
TOPSECURITY_QCF/RefAddr/1/Encoding=String
TOPSECURITY_QCF/FactoryName=com.ibm.mq.jms.MQQueueConnectionFactoryFactory
TOPSECURITY_QCF/RefAddr/20/Content=
TOPSECURITY_QCF/RefAddr/20/Encoding=String
TOPSECURITY.QUEUE/RefAddr/2/Content=-2
TOPSECURITY_QCF/RefAddr/18/Type=TCM
TOPSECURITY_QCF/RefAddr/7/Type=CT
TOPSECURITY.QUEUE/RefAddr/0/Content=6
TOPSECURITY.QUEUE/RefAddr/0/Encoding=String
TOPSECURITY_QCF/RefAddr/8/Content=0
TOPSECURITY.QUEUE/RefAddr/2/Encoding=String
TOPSECURITY_QCF/RefAddr/6/Content=819
TOPSECURITY.QUEUE/RefAddr/4/Type=CCS
TOPSECURITY_QCF/RefAddr/12/Type=UCP
TOPSECURITY_QCF/RefAddr/1/Type=TRAN
TOPSECURITY_QCF/RefAddr/11/Encoding=String
TOPSECURITY.QUEUE/RefAddr/4/Encoding=String
TOPSECURITY_QCF/RefAddr/3/Encoding=String
TOPSECURITY_QCF/RefAddr/18/Content=true
TOPSECURITY.QUEUE/RefAddr/6/Encoding=String
TOPSECURITY_QCF/RefAddr/5/Encoding=String
TOPSECURITY.QUEUE/FactoryName=com.ibm.mq.jms.MQQueueFactory
TOPSECURITY.QUEUE/RefAddr/8/Encoding=String
TOPSECURITY_QCF/RefAddr/19/Type=TM
TOPSECURITY_QCF/RefAddr/8/Type=CTO
TOPSECURITY_QCF/ClassName=com.ibm.mq.jms.MQQueueConnectionFactory
TOPSECURITY_QCF/RefAddr/7/Encoding=String
TOPSECURITY_QCF/RefAddr/4/Content=1421
TOPSECURITY_QCF/RefAddr/9/Encoding=String
TOPSECURITY.QUEUE/RefAddr/5/Type=TC
TOPSECURITY_QCF/RefAddr/13/Encoding=String
TOPSECURITY_QCF/RefAddr/13/Type=PINT
TOPSECURITY_QCF/RefAddr/2/Content=BEAQM
TOPSECURITY_QCF/RefAddr/2/Type=QMGR
TOPSECURITY_QCF/RefAddr/16/Content=
TOPSECURITY_QCF/RefAddr/0/Content=6
TOPSECURITY_QCF/RefAddr/15/Encoding=String
TOPSECURITY_QCF/RefAddr/14/Content=10
TOPSECURITY.QUEUE/RefAddr/9/Content=BEAQM
TOPSECURITY_QCF/RefAddr/17/Encoding=String
TOPSECURITY_QCF/RefAddr/12/Content=true
TOPSECURITY.QUEUE/RefAddr/7/Content=1
TOPSECURITY_QCF/RefAddr/9/Type=SRC
TOPSECURITY_QCF/RefAddr/19/Encoding=String
TOPSECURITY.QUEUE/RefAddr/5/Content=0
TOPSECURITY.QUEUE/RefAddr/6/Type=ENC
TOPSECURITY_QCF/RefAddr/14/Type=MBS
TOPSECURITY_QCF/RefAddr/3/Type=HOST
TOPSECURITY_QCF/RefAddr/0/Encoding=String
TOPSECURITY.QUEUE/RefAddr/0/Type=VER
TOPSECURITY_QCF/RefAddr/10/Content=false
TOPSECURITY_QCF/RefAddr/21/Content=1
TOPSECURITY_QCF/RefAddr/2/Encoding=String
TOPSECURITY.QUEUE/RefAddr/3/Content=-2
TOPSECURITY_QCF/RefAddr/21/Encoding=String
TOPSECURITY.QUEUE/RefAddr/1/Content=-2
TOPSECURITY_QCF/RefAddr/9/Content=0
TOPSECURITY.QUEUE/RefAddr/7/Type=FIQ
TOPSECURITY.QUEUE/RefAddr/1/Encoding=String
TOPSECURITY_QCF/RefAddr/15/Type=FIQ
TOPSECURITY_QCF/RefAddr/4/Type=PORT
TOPSECURITY_QCF/RefAddr/7/Content=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000
TOPSECURITY_QCF/RefAddr/10/Encoding=String
TOPSECURITY.QUEUE/RefAddr/3/Encoding=String
TOPSECURITY_QCF/RefAddr/5/Content=SYSTEM.DEF.SVRCONN
TOPSECURITY.QUEUE/RefAddr/1/Type=EXP
TOPSECURITY_QCF/RefAddr/19/Content=SYSTEM.DEFAULT.MODEL.QUEUE
TOPSECURITY.QUEUE/RefAddr/5/Encoding=String
TOPSECURITY_QCF/RefAddr/20/Type=TQPFX
TOPSECURITY_QCF/RefAddr/4/Encoding=String



Now, the MQ should be set up to facilitate communications. We need a MDB and client to perform our operations...


From MQ to Weblogic: the MDB code - pritty much as simple as it gets
TopsecurityMDB.java

package dk.topsecurity;

import weblogic.rmi.RemoteException;

import javax.ejb.*;
import javax.jms.*;
import javax.naming.*;

/**
 * The message bean, which - through external JNDI provider - is using a 
 * context factory, that uses IBM mq classes - and treats the MQ as an 
 * external JMS provider.
 *
 */
public class TopsecurityMDB implements MessageDrivenBean, MessageListener {

  public void ejbActivate() { System.out.println("ejbActivate called"); }

  public void ejbRemove() { System.out.println("ejbRemove called"); }

  public void ejbPassivate() { System.out.println("ejbPassivate called"); }

  public void ejbCreate () throws CreateException { System.out.println("ejbCreate called"); }

  public void setMessageDrivenContext(MessageDrivenContext ctx) {
    System.out.println("setMessageDrivenContext called");
    m_context = ctx;
  }

  /**
   * onMessage required by the MessageListener interface - receives messages
   * from the external JMS provider
   */
  public void onMessage(Message msg) {
    TextMessage tm = (TextMessage) msg;
    try {
      String text = tm.getText();
      System.out.println("Received message from JMS provider : " + text);
    }
    catch(JMSException ex) {
      ex.printStackTrace();
    }
  }

  private MessageDrivenContext m_context;
}



The generic bean descriptor..

ejb-jar.xml

<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
 <enterprise-beans>
    <message-driven>
      <ejb-name>TopsecurityMDB example1</ejb-name>
      <ejb-class>dk.topsecurity.TopsecurityMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
        <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
    </message-driven>
    <message-driven>
      <ejb-name>TopsecurityMDB example2</ejb-name>
      <ejb-class>dk.topsecurity.TopsecurityMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
        <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
    </message-driven>
 </enterprise-beans>
</ejb-jar>



... the weblogic specific descriptor...

weblogic-ejb-jar.xml

<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">
<!-- Sample MessageDriven bean Weblogic deployment descriptor -->
<weblogic-ejb-jar>
  <weblogic-enterprise-bean>
    <ejb-name>TopsecurityMDB example1</ejb-name>
    <message-driven-descriptor>
      <pool>
        <max-beans-in-free-pool>5</max-beans-in-free-pool>
        <initial-beans-in-free-pool>2</initial-beans-in-free-pool>
      </pool>
      <destination-jndi-name>TOPSECURITY.QUEUE</destination-jndi-name>
      <initial-context-factory>com.sun.jndi.fscontext.RefFSContextFactory</initial-context-factory>
      <provider-url>file:/C:/jms-jndi-directory</provider-url>
      <connection-factory-jndi-name>TOPSECURITY_QCF</connection-factory-jndi-name>
    </message-driven-descriptor>
    <jndi-name>TopsecurityMDB1</jndi-name>
  </weblogic-enterprise-bean>
  <weblogic-enterprise-bean>
    <ejb-name>TopsecurityMDB example2</ejb-name>
    <message-driven-descriptor>
      <destination-jndi-name>TOPSECURITY.QUEUE</destination-jndi-name>
      <initial-context-factory>com.sun.jndi.fscontext.RefFSContextFactory</initial-context-factory>
      <provider-url>file:/C:/jms-jndi-directory</provider-url>
      <connection-factory-jndi-name>TOPSECURITY_QCF</connection-factory-jndi-name>
    </message-driven-descriptor>
    <jndi-name>TopsecurityMDB2</jndi-name>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>

... and the minor change necessary for config.xml in order to run the sample (unless you're running in development mode with hot-deployment - and just need to drop the .jar file in the applications direcotry)... In my case, it's obvious I'm using a Weblogic installtion with application directory: C:\bea\user_projects\domains\mqtest\applications.

config.xml

...
    <Application Name="_appsdir_TopsecurityMQ_jar"
        Path="C:\bea\user_projects\domains\mqtest\applications"
        StagedTargets="myserver" StagingMode="stage" TwoPhase="true">
        <EJBComponent Name="TopsecurityMQ" Targets="myserver" URI="TopsecurityMQ.jar"/>
    </Application>
...

We need a client to initiate a stream of messages processed by MQ and the Weblogic server... Check out the shaded area for required authentication. Will be explained in another document.


From J2EE stand-alone client to MQ
TopsecurityMQClient.java

package dk.topsecurity;

import javax.jms.*;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;

public class TopsecurityMQClient implements ExceptionListener {

/** 
 * Setting up authorisation username. Used by classes in com.ibm.mqjms.jar
 * Setting up queue connection factory (QCF)
 * Setting up name of queue, as defined in the MQ setup
 * Setting up url for file-based, external JNDI provider 
 * Setting up context factory to use with external JNDI
 */

  public String mq_username = "Administrator";
  public String mq_qcf = "TOPSECURITY_QCF";
  public String mq_qname = "TOPSECURITY.QUEUE";
  public String mq_url = "file:/C:/jms-jndi-directory";
  public String mq_jndi =  "com.sun.jndi.fscontext.RefFSContextFactory";

/**
 * main method - binding to the Websphere MQ installation - and delivering a
 * number of messages.
 *
 * Make sure you've run the MQSC commands on MQ before deploying examples
 *
 * define qcf(TOPSECURITY_QCF) qmgr(BEAQM) channel(SYSTEM.DEF.SVRCONN) hostname(semp20) port(1421) transport(CLIENT)
 * define q(TOPSECURITY.QUEUE) queue(TOPSECURITY.QUEUE) qmgr(BEAQM)
 */
 
  public static void main(String[] args) {

    TopsecurityMQClient sender = null;
    try {
      sender = new TopsecurityMQClient();
      sender.setupQueueConnection();
      for(int i=0;;i++) {
        sender.send(sender.setMessage("Hello no "+i+" from client at "+new Date()));
      }
    }
    catch(JMSException je) {
      System.out.println("Caught JMSException: "+je);
      Exception le = je.getLinkedException();
      if (le != null) 
        System.out.println("Linked exception: "+le);
      je.printStackTrace();
    } catch(Exception e) {
       e.printStackTrace();
     } finally {
      try {
      if (sender != null)
        sender.cleanup();
      } catch (Exception e) { }
    }
  }

  private void setupQueueConnection() throws Exception {

    /* authentication related part - completely remove when running MQ and
     * J2EE client on same machine under same user - or different machines
     * and identical user names. Otherwise enter the username used for the
     * MQ installation. Failure to do so, will cause the program to exit with
     * authentication exception.
     */
    System.out.println("Initial user.name="+System.getProperty("user.name"));
    System.setProperty("user.name",mq_username);
    System.out.println("Authrorisation required user.name="+System.getProperty("user.name"));
    /*end of authentication related part*/

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, mq_jndi);
    env.put(Context.PROVIDER_URL, mq_url);

    InitialDirContext ctx = new InitialDirContext(env);
    com.ibm.mq.jms.MQQueueConnectionFactory factory =
            (com.ibm.mq.jms.MQQueueConnectionFactory)ctx.lookup(mq_qcf);

    System.out.println("Factory = " +factory);

    /* Create a QueueConnection, QueueSession
     * When a connection is made, use the createQueueSession method on the
     * QueueConnection to obtain a session. Parameters: 
     * boolean= determines whether the session is transacted or non-transacted.
     * int =  that determines the acknowledge mode.
     * Simplest case is that of the non-transacted session with AUTO_ACKNOWLEDGE
     * - p319 in the IBM redbook.
     */
    connection = factory.createQueueConnection();
    session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    ioQueue = (Queue)ctx.lookup(mq_qname);

    connection.start();
    connection.setExceptionListener(this);

    queueSender = session.createSender(ioQueue);
  }


  /**
   * For test purpose, create one of many possible types of messages: 
   * BytesMessage, MapMessage, ObjectMessage, StreamMessage
   */
  TextMessage setMessage(String text) throws Exception {

    TextMessage msg = session.createTextMessage();
    msg.setText(text);
    return(msg);
  }

  /**
   * Send message off to MQ
   */
  void send(TextMessage msg) throws Exception {

    System.out.println("Sending the message on queue " + ioQueue.getQueueName());
    queueSender.send(msg);
  }

  /**
   * required in the ExceptionListener interface
   */
  public void onException(JMSException jms) {
    System.out.println("onException: jms" + jms);
    jms.printStackTrace();
  }

  /**
   * do away with connections to MQ
   */
  void cleanup() throws Exception {
    if (session != null) {
      session.close();
      session = null;
    }
    if (connection != null)
      connection.close();
      connection = null;
  }

  private Queue ioQueue;
  private QueueSession session;
  private QueueConnection connection;
  private QueueConnectionFactory factory;
  private QueueSender queueSender;
  private InitialContext ctx;
  private TextMessage msg;

}



In order to get the whole setup running you need to configure the weblogic startup in two ways: (1) you need to include "-classpath %CLASSPATH%" (without quotation signs :) into the "startWeblogic.cmd" weblogic startup line (at the bottom) and (2) you need to include following script "startWebLogicWithMQSupport.cmd" in the same directory as "startWeblogic.cmd".

Make sure in "startWebLogicWithMQSupport.cmd" to substitute correct settings for WL_HOME and MQ_JAVA_INSTALL_PATH. And if paths contains spaces, be carefull to use quotation signs, so the paths don't break up the startup argument line...

startWebLogicWithMQSupport.cmd

@rem *************************************************************************
@rem This script is used to set up your environment for development with  
@rem WebLogic Server. It sets the following variables: 
@rem
@rem WL_HOME    - The root directory of your WebLogic installation
@rem JAVA_HOME  - Location of the version of Java used to start WebLogic 
@rem              Server. This variable must point to the root directory of a 
@rem              JDK installation and will be set for you by the installer. 
@rem              See the WebLogic platform support page 
@rem              (http://e-docs.bea.com/wls/platforms/index.html) for an up-to-date list of 
@rem              supported JVMs on Windows NT.
@rem PATH       - Adds the JDK and WebLogic directories to the system path.  
@rem CLASSPATH  - Adds the JDK and WebLogic jars to the classpath.  
@rem 
@rem Other variables that setWLSEnv takes are:
@rem
@rem PRE_CLASSPATH  - Path style variable to be added to the beginning of the 
@rem                  CLASSPATH 
@rem POST_CLASSPATH - Path style variable to be added to the end of the 
@rem                  CLASSPATH 
@rem PRE_PATH       - Path style variable to be added to the beginning of the 
@rem                  PATH 
@rem POST_PATH      - Path style variable to be added to the end of the PATH 
@rem
@rem When setting these variables below, please use short file names(8.3). 
@rem To display short (MS-DOS) filenames, use "dir /x". File names with 
@rem spaces will break this script.
@rem 
@rem jDriver for Oracle users: This script assumes that native libraries 
@rem required for jDriver for Oracle have been installed in the proper 
@rem location and that your system PATH variable has been set appropriately. 
@rem
@rem For additional information, refer to the WebLogic Server Administration 
@rem Guide (http://e-docs.bea.com/wls/docs70/adminguide/startstop.html).
@rem *************************************************************************
@echo off

@rem Set user-defined variables.
set WL_HOME=C:\bea\weblogic81

set MQ_JAVA_INSTALL_PATH=c:\Program Files\IBM\WebSphere MQ
set MQ_CLASSPATH=;"%MQ_JAVA_INSTALL_PATH%\java\lib";"%MQ_JAVA_INSTALL_PATH%\Java\samples\base";"%MQ_JAVA_INSTALL_PATH%\java\lib\com.ibm.mq.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\com.ibm.mqjms.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\jms.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\jndi.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\fscontext.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\providerutil.jar";"%MQ_JAVA_INSTALL_PATH%\java\lib\connector.jar"

SET PATH=%PATH%;%MQ_JAVA_INSTALL_PATH%/Java/lib;%MQ_JAVA_INSTALL_PATH%/WebSph~1/bin

@rem Check that the WebLogic classes are where we expect them to be
@if exist "%WL_HOME%\server\lib\weblogic.jar" goto checkJava
@echo.
@echo The WebLogic Server wasn't found in directory %WL_HOME%\server.
@echo Please edit the setWLSEnv.cmd script so that the WL_HOME
@echo variable points to the WebLogic installation directory.
@echo Your environment has not been set.
@goto finish

@rem Check that java is where we expect it to be
:checkJava
@if exist "%JAVA_HOME%\bin\java.exe" goto setWLSEnv
@echo.
@echo The JDK wasn't found in directory %JAVA_HOME%.
@echo Please edit the setWLSEnv.cmd script so that the JAVA_HOME
@echo variable points to the location of your JDK.
@echo Your environment has not been set.
@goto finish

:setWLSEnv
set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%MQ_CLASSPATH%

set PATH=%WL_HOME%\server\bin;%JAVA_HOME%\bin;%PATH%

@rem Import extended environment

if exist extEnv.cmd call extEnv.cmd
if not "%EXT_PRE_CLASSPATH%" == "" set CLASSPATH=%EXT_PRE_CLASSPATH%;%CLASSPATH%
if not "%EXT_POST_CLASSPATH%" == "" set CLASSPATH=%CLASSPATH%;%EXT_POST_CLASSPATH%
if not "%EXT_PRE_PATH%" == "" set PATH=%EXT_PRE_PATH%;%PATH%
if not "%EXT_POST_PATH%" == "" set PATH=%PATH%;%EXT_POST_PATH%

@rem Get PRE and POST environment
if not "%PRE_CLASSPATH%" == "" set CLASSPATH=%PRE_CLASSPATH%;%CLASSPATH%
if not "%POST_CLASSPATH%" == "" set CLASSPATH=%CLASSPATH%;%POST_CLASSPATH%
if not "%PRE_PATH%" == "" set PATH=%PRE_PATH%;%PATH%
if not "%POST_PATH%" == "" set PATH=%PATH%;%POST_PATH%

@echo.
@echo CLASSPATH=%CLASSPATH%
@echo.
@echo PATH=%PATH%
@echo.
@echo Your environment has been set.

:finish



rem Remember to include -classpath %CLASSPATH% in the Weblogic startup line, fx.
rem %JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS% -Dweblogic.Name=%SERVER_NAME% -Dweblogic.ProductionModeEnabled=%PRODUCTION_MODE% -Djava.security.policy="%WL_HOME%\server\lib\weblogic.policy" -classpath %CLASSPATH% weblogic.Server


startWeblogic.cmd

But - don't worry - if settings are wrong, the server is sure to tell you about it.. :)

To turn the sources into executables, ant script "build.xml" is used. It requires setting of environment variable MQ_JAVA_INSTALL_PATH.

build.xml

<project name="TopsecurityMQ" default="all" basedir=".">

  <target name="init">
    <property name="wl_home" value="C:/bea/weblogic81"/>

    <property environment="env"/>
    <property name="JAVAC" value="modern"/>
    <property name="build.compiler" value="${JAVAC}"/>
    <property name="source" value="./src"/>
    <property name="compiledir" value="./build"/>
    <property name="earstage" value="./earstage"/>
    <property name="project_name"   value="TopsecurityMQ"/>
    <property name="mqjava" value="${env.MQ_JAVA_INSTALL_PATH}/java/lib/com.ibm.mq.jar"/>
    <property name="mqjms"  value="${env.MQ_JAVA_INSTALL_PATH}/java/lib/com.ibm.mqjms.jar"/>
  </target>

  <target name="all" depends="init, clean, compile, buildjar, ejbc"/>

  <target name="clean" depends="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <delete dir="${compiledir}" />
    <mkdir dir="${compiledir}"/>
    <mkdir dir="${compiledir}/META-INF"/>
    <delete dir="${earstage}" />
    <mkdir dir="${earstage}" />
    <mkdir dir="${earstage}/META-INF" />
  </target>

  <target name="compile" depends="clean">
    <javac srcdir="${source}" destdir="${compiledir}" 
      classpath="${wl_home}\server\lib\weblogic.jar;${mqjava};${mqjms}" includes="**/*.java"/>
  </target>

  <target name="buildjar" depends="compile">
    <copy file="${source}/ejb-jar.xml" todir="${compiledir}/META-INF" overwrite="yes"/>
    <copy file="${source}/weblogic-ejb-jar.xml" todir="${compiledir}/META-INF" overwrite="yes"/>
    <jar jarfile="${compiledir}/${project_name}.jar"
      basedir="${compiledir}" includes="**/TopsecurityMDB*.class,**/*.xml"
      update="yes">
    </jar>
    <jar jarfile="${earstage}/${project_name}_client.jar"
      basedir="${compiledir}"  includes="**/TopsecurityMQ*Client.class"
      update="yes">
    </jar>
  </target>
  <target name="ejbc" depends="buildjar">
    <java classname="weblogic.ejbc" fork="yes" failonerror="yes" classpath="${wl_home}\server\lib\weblogic.jar">
      <sysproperty key="weblogic.home" value="${compiledir}"/>
      <arg line="-compiler javac ${compiledir}/${project_name}.jar ${earstage}/${project_name}.jar"/>
    </java>
  </target>
  
</project>

In case you're wondering, this is how environment may look like after an MQ installation.

environment snapshot

In order to compile the stuff, you just need the first two of the following .jar files. But in order to run the stand-alone client, you better get hold of them all. They're claimed to be included in a standard Webshpere MQ client installation - but is claimed to require a custom installation to be reveiled.


Enough talk, do the compilation.. (yeah, I compile an extra class)

compile console snaphot

The deployment..

Weblogic startup console snapshot

First - test the MDB put using the Websphere MQ navigatior to put message on queue:

Websphere MQ navigator message control

Websphere MQ navigator message administrator

Weblogic console snapshot of response to MQ manipulation

And running the client (stop with Ctrl-break)...

send.cmd

set BEA_HOME=C:\bea
set WL_HOME=C:\bea\weblogic81
java -classpath .;%WL_HOME%\server\lib\weblogic.jar;.\com.ibm.mq.jar;.\com.ibm.mqjms.jar;.\fscontext.jar;.\providerutil.jar;.\dbhcore.jar;./earstage/TopsecurityMQ_client.jar dk/topsecurity/TopsecurityMQClient



MQ client console snapshot

and the response from the MDB... (circle is completed)

Weblogic console snapshot of response to console client