Tuesday, 23 September 2014

IBM Integration Bus and the WebSphere Application Server (WAS) Plugin

So I am following this rather excellent developerWorks article: -


WebSphere Message Broker V8 lets you generate a configuration file for the WebSphere Plug-in or Apache mod_proxy modules, which are used by IBM HTTP Server and Apache HTTP Server respectively to enable HTTP load balancing. Part 1 of this two-part series shows you how to configure load balancing for WebSphere Message Broker HTTP traffic using WebSphere Plug-in and IBM HTTP Server. The article shows you how to use WebSphere Message Broker Java APIs and the WebSphere Message Broker Explorer to generate a WebSphere Plug-in configuration for IBM HTTP Server.

This includes some sample code that allows one to generate a plugin file for the WebSphere Application Server (WAS) Plugin.

This Java code makes use of the WebSphere MQ and IBM Integration Bus Java APIs, such as com.ibm.broker.config.proxy.BrokerConnectionParameters.

In order to compile the code, I created a new Java project in Eclipse (Kepler) called PluginGeneration, into which I placed the three source files: -

com.ibm.broker.load.plugin.GeneratePlugin
com.ibm.broker.load.plugin.WritePluginFile
com.ibm.broker.load.plugin.BrokerConnectionDetails

( the example source is in the article, including a downloadable ZIP ).

However, in order to compile the code, I needed to add a single IIB JAR file to my Eclipse build path: -

-rwxr-xr-x 1 wmbadmin mqbrkrs 12210797 Jun 19 19:21 /opt/ibm/mqsi/9.0.0.2/classes/ConfigManagerProxy.jar


Once I'd created the project, with the three classes, I used Eclipse to export it as a Runnable JAR file with the main method of the GeneratePlugin class set as the Launch configuration: -


I was then able to execute the JAR: -

java -jar PluginGeneration.jar 

=========================================================================================
*****************************************************************************************
*******************WebSphere Message Broker Plugin Generation Tool***********************
*****************************************************************************************
=========================================================================================

Do you want to add Broker Connection Details ? (y/n) = y

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

Please Enter the Broker Connection Details ( Hostname, QMName , QMPort )

Enter the Broker Hostname                            = bam8012.uk.ibm.com

Enter the Queue Manager Name                         = DAVEHAY

Enter the Queue Manager Listener Port Number         = 1414

Sadly, at that point, I hit this exception: -

Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.mq.MQException
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:171)
at com.ibm.broker.config.proxy.MQBrokerConnectionParameters.getSender(MQBrokerConnectionParameters.java:574)
at com.ibm.broker.config.proxy.BrokerProxy.<init>(BrokerProxy.java:322)
at com.ibm.broker.config.proxy.BrokerProxy.getInstance(BrokerProxy.java:863)
at com.ibm.broker.load.plugin.GeneratePlugin.main(GeneratePlugin.java:100)
Caused by: java.lang.ClassNotFoundException: com.ibm.mq.MQException
at java.net.URLClassLoader.findClass(URLClassLoader.java:599)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:760)
at java.lang.ClassLoader.loadClass(ClassLoader.java:728)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:707)
... 7 more

This led me to this IBM Technote: -


...
Why was the Java™ MQException Class moved to the com.ibm.mq.jmqi.jar file in WebSphere MQ V7.0?
...
The move of the MQException class to the new com.ibm.mq.jmqi.jar was as a result of significant re-engineering that was implemented across the MQ classes for Java and the MQ classes for JMS. The JMS classes (com.ibm.mq.jms.jar) and Java classes (com.ibm.mq.jar) are now independent and stand as peers, therefore the MQException Class was moved to a common JAR file that can be used by either the Java and JMS libraries.
...

Sadly, I've not yet come up with a perfect solution to this :-(

The issue, and the IBM Technote, implied that I needed to add one or more JARs to the Java class path, which I tried as follows: -

java -cp /opt/ibm/mqm/java/lib/com.ibm.mq.headers.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jmqi.jar -jar /mnt/hgfs/Downloads/PluginGeneration.jar 

but to no avail.

I even tried adding in the additional IIB JAR: -

java -cp /opt/ibm/mqm/java/lib/com.ibm.mq.headers.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jmqi.jar:/opt/ibm/mqsi/9.0.0.2/classes/ConfigManagerProxy.jar -jar /mnt/hgfs/Downloads/PluginGeneration.jar 

but again to no avail.

In the end, I found that the "optimum" solution was to include the four JARs: -

com.ibm.mq.headers.jar
com.ibm.mq.jar
com.ibm.mq.jmqi.jar
ConfigManagerProxy.jar

in the Build Path: -


AND also inside the exported JAR: -


which now allows me to successfully generate the WAS Plugin configuration: -

java -jar PluginGeneration.jar

=========================================================================================
*****************************************************************************************
*******************WebSphere Message Broker Plugin Generation Tool***********************
*****************************************************************************************
=========================================================================================

Do you want to add Broker Connection Details ? (y/n) = y

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

Please Enter the Broker Connection Details ( Hostname, QMName , QMPort )

Enter the Broker Hostname                            = bam8012.uk.ibm.com

Enter the Queue Manager Name                         = DAVEHAY

Enter the Queue Manager Listener Port Number         = 1414

Broker HTTP Service Details for this Broker Connection
Broker,HTTP/HTTPS,Port,URL,Execution Groups....

Do you want to add Broker Connection Details ? (y/n) = n

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

Enter the file name for Plugin                       = plugin-cfg.xml

Enter the location of file                           = /tmp

=========================================================================================
*****************************************************************************************
*********************Congratulation Plugin Generated Successfully************************
**************************Exiting Plugin Generation Tool*********************************
*****************************************************************************************
=========================================================================================


cat /tmp/plugin-cfg.xml 

<?xml version="1.0" encoding="UTF-8"?><Config>
    <!--PLUGININSTALLROOT MUST BE UNCOMMENTED FOR SSL-->
    <!--Property Name="PluginInstallRoot" Value="SET ME TO YOUR WEBSPHERE PLUGINS DIRECTORY"/-->
    <VirtualHostGroup Name="default_host">
        <VirtualHost Name="*:80"/>
    </VirtualHostGroup>



Still not sure why I need to have the WMQ/IIB JARs on build path AND exported within the JAR, but it works :-)

PS For the record, I did try executing the JAR like this: -

java -cp /opt/ibm/mqm/java/lib/com.ibm.mq.headers.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jmqi.jar:/opt/ibm/mqsi/9.0.0.2/classes/ConfigManagerProxy.jar -jar PluginGeneration.jar

but that didn't end well either: -

Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.broker.config.proxy.ConfigManagerProxyLoggedException
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.prepare(J9VMInternals.java:516)
at java.lang.Class.getMethod(Class.java:964)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:506)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:498)
Caused by: java.lang.ClassNotFoundException: com.ibm.broker.config.proxy.ConfigManagerProxyLoggedException
at java.net.URLClassLoader.findClass(URLClassLoader.java:599)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:760)
at java.lang.ClassLoader.loadClass(ClassLoader.java:728)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:707)
... 6 more



Finally, it's worth noting that I'm running the JAR as a user that's configured for BOTH WMQ and IIB: -

...
. /opt/ibm/mqm/bin/setmqenv -s -k

source /opt/ibm/mqsi/9.0.0.2/bin/mqsiprofile

...

with the following class path: -

/opt/ibm/mqsi/9.0.0.2/messages:/opt/ibm/mqsi/9.0.0.2/classes:/opt/ibm/mqsi/9.0.0.2/classes/ConfigManagerProxy.jar:/opt/ibm/mqsi/9.0.0.2/classes/brokerutil.jar:/opt/ibm/mqm/java/lib/com.ibm.mq.jar:/opt/ibm/mqm/java/lib/com.ibm.mqjms.jar:/opt/ibm/mqm/samp/wmqjava/samples:/opt/ibm/mqm/samp/jms/samples:/var/mqsi/common/wsrr



4 comments:

Prakash Mahali said...
This comment has been removed by the author.
Dave Hay said...

Hi Prakash, thanks for the comment - I used the sample code supplied with the original developerWorks article Cheers, Dave

P Kumar said...

the sample code is foe IIB 8 and which is uses MQ but i need for IIB 10 without MQ , can you please help me .also if possible share the httpd.conf and plugin.xml file


Thanks

Dave Hay said...

Hi, alas I've not tried this for IIB 10 :-)