Category Archives: webSphere

The category is mainly a disscusion forum about using webSphere Message Broker/IBM product

Integrate PowerShell script with webMethods service

PowerShell script is quite handy when you are inside a windows environment. Sometime you might need to utilize existing powershell script in webMethods to suits your needs. This article is to share some ideas how to integrate PowerShell script into webMethods.

Run a Powershell script from the command line

The basic PowerShell tutorial: https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help. This gives basic idea how to run a Powershell script from the command line with parameter, here is the command syntax:
PowerShell[.exe] [-File <FilePath> [<Args>]]

Here is sample PowerShell script which search for a certain string in all files under a directory.

When invoke this script from command line, you need to add two parameters separated by space. Below is the return of script.
image0021

Execute OS command from webMethod Service

webMethods has provided a built-in java service that can execute command. This build-in service is access controlled which you need change OSCommand.cnf in WmPublic package before you execute this service. Alternatively, you can create your own java service which will give a bit more control of using it. Here is the sample code:

A real sample

I wrote a little PowerShell script to count number of hits on WebSphere web service. My WebSphere wrote all SOAP requests input and output into system.log file same as how webMethods generate server.log. PowerShell script was searching for a particular string in all log files within a folder. Then webMethods flow service collects the results and converts them into table.

Finally and most important, use Google Chart java script to build this colorful column chart

.image0041.jpg

Connect webMethods to WebSphere MQ as JMS provider

Copy the following files from MQ installation directory to WM integration server directory (IntegrationServer\lib\jars):

WebSphereMQ\java\lib\com.ibm.mq.commonservices.jar
WebSphereMQ\java\lib\com.ibm.mq.headers.jar
WebSphereMQ\java\lib\com.ibm.mq.jar
WebSphereMQ\java\lib\com.ibm.mq.jmqi.jar
WebSphereMQ\java\lib\com.ibm.mq.pcf.jar
WebSphereMQ\java\lib\com.ibm.mqjms.jar
WebSphereMQ\java\lib\dhbcore.jar
WebSphereMQ\java\lib\mqcontext.jar

mqcontext.jar can be found in github.com while other jars provided by IBM by default installation.
https://github.com/khaliqgaffar/jboss_esb_eval_proj/blob/master/AuditMonitor/esbcontent/lib/mqcontext.jar

Restart webMethods integration server.

Setup new TCPIP listener in MQ and start it.
MQ.Add Listener

Add JNDI service provider in MQ as JMS administered objects MQ
Provider URL: servername:port/SYSTEM.DEF.SVRCONN (port is the one created in step 3)
Initial Context Factory: com.ibm.mq.jsm.context.WMQInitialContextFactory
Required Libraries: mqcontext.jar
Connect this context factory.
mq-add-jndi.jpg

Add MQ Connection Factory.
Make sure you select “Connection Factory” as type to view both Queue and Topic.
MQ.Add Factory

Add JNDI service provider in webMethods.
Under IS Admin – Setting — Messaging – JNDI Settings – Create JNDI Provider Alias.
mq-add-jndi-provider.jpg
Test JNDI Provider:
MQ.Test JNDI Provider

Add JMS Connection Alias in webMethods.
Under IS Admin – Setting — Messaging – JMS Settings – Create JMS Connection Alias.
JNDI Provider Alias: MQProvider (JNDI created in step 6)
Connection Factory Lookup Name: DEFAULT (Connection factory created in step 5)
MQ.Add JMS Connection
Enable the JMS connection.

Send JMS message from webMethods to MQ use service pub.jms:send
MQ.JMS send

Retrieve JMS message from MQ use JMS trigger
MQ.JMS trigger