Out of the
box a package can be installed on webMethods Integration Server via the Administrator’s
Package Management GUI or using WmDeployer.
Following code snippet with allow you to install packages on a webMethods Integration Server through the usage of a custom developed java program, leveraging the internal wM codebase for introducing a package.
Java code snippet :
/*
* Usage: java -classpath <path_to_client_classes> PackageInstaller \
* host:<hostname> port:<port> user:<username> \
* pswd:<password> pckg:<package1>,<package2>,...
*
* The .zip extension for package names should be omitted
*
* If using a secure connection (https) to connect to your Integration Server
* uncomment the following line in the connect() method below:
* context.setSecure(true);
*/
import com.wm.app.b2b.client.*;
import com.wm.util.*;
import java.util.StringTokenizer;
public class PackageInstaller
{
public static String hostName = null;
public static String port = null;
public static String userName = null;
public static String password = null;
public static String errorMsg = null;
public static String packages = null;
public static String tmpStr = null;
Context context = null;
public boolean connected = false;
public static boolean secure = false;
public static void main(String[] args)
{
/***********************************************************************/
/* Parse command line. The hostname, port, username and password must */
/* ALL be specified. */
/***********************************************************************/
errorMsg = "";
for (int iCtr = 0; iCtr < args.length; iCtr++)
{
if (args[iCtr].indexOf("host:") != -1) {
hostName = args[iCtr].substring(5);
if (hostName.length() < 1)
errorMsg = errorMsg + "\n No host name specified";
}
else if (args[iCtr].indexOf("port:") != -1) {
port = args[iCtr].substring(5);
if (port.length() < 1)
errorMsg = errorMsg + "\n No port specified";
}
else if (args[iCtr].indexOf("user:") != -1) {
userName = args[iCtr].substring(5);
if (userName.length() < 1)
errorMsg = errorMsg + "\n No user name specified";
}
else if (args[iCtr].indexOf("pswd:") != -1) {
password = args[iCtr].substring(5);
if (password.length() < 1)
errorMsg = errorMsg + "\n No password specified";
}
else if (args[iCtr].indexOf("pckg:") != -1) {
packages = args[iCtr].substring(5);
if (packages.length() < 1)
errorMsg = errorMsg + "\n No packages specified";
}
else {
errorMsg = errorMsg + "\n Invalid parameter '" +
args[iCtr] + "' specified.";
}
}
/***********************************************************************/
/* Display program usage instruction if there were any errors with the */
/* command line arguments. */
/***********************************************************************/
if ((errorMsg.length() > 0) || (hostName == null) || (port == null) ||
(userName == null) || (password == null) || (packages == null)) {
System.out.println(" Usage: java -classpath " +
"<path_to_client_classes> PackageInstaller " +
"host:<hostname> port:<port> user:<username> " +
"pswd:<password> pckg:<package1>,<package2>,...\n");
System.out.println(" Omit the .zip extension for package names");
if (errorMsg.length() > 0)
System.out.println(" Errors encountered:" + errorMsg);
System.exit(1);
}
//Create an instance of this class
PackageInstaller packageInstaller = new PackageInstaller();
System.out.println("Instantiated installer");
packageInstaller.connect(true);
if(!packageInstaller.connected) {
System.exit(1);
}
StringTokenizer st = new StringTokenizer(packages, ",");
while (st.hasMoreTokens()) {
String packageName = st.nextToken();
packageInstaller.install(packageName + ".zip");
packageInstaller.activate(packageName);
}
System.exit(0);
}
public void connect(boolean dispMsg)
{
context = new Context();
try {
/***********************************************/
/* Uncomment the following line if using https */
/***********************************************/
// context.setSecure(true);
context.connect(hostName + ":" + port, userName, password);
connected = true;
}
catch(ServiceException e) {
if (dispMsg) {
System.out.println("Could not connect to " + hostName + ":" + port);
System.out.println(e.toString());
}
connected = false;
}
}
public void install(String packageName)
{
try {
System.out.println("Installing package " + packageName + " ... ");
Values input = new Values();
input.put("file", packageName);
Values data = context.invoke("wm.server.packages", "packageInstall", input);
// System.out.println("IData:\n");
// System.out.println(data.toString());
}
catch(ServiceException e) {
System.out.println(e.toString());
System.exit(1);
}
}
public void activate(String packageName)
{
try {
System.out.println("Activating package " + packageName + " ... ");
Values input = new Values();
input.put("package", packageName);
Values data = context.invoke("wm.server.packages", "packageActivate", input);
// System.out.println("IData:\n");
// System.out.println(data.toString());
}
catch(ServiceException e) {
System.out.println(e.toString());
System.exit(1);
}
}
public PackageInstaller()
{
System.out.println();
System.out.println("******PackageInstaller utility*******");
System.out.println();
}
}
* Usage: java -classpath <path_to_client_classes> PackageInstaller \
* host:<hostname> port:<port> user:<username> \
* pswd:<password> pckg:<package1>,<package2>,...
*
* The .zip extension for package names should be omitted
*
* If using a secure connection (https) to connect to your Integration Server
* uncomment the following line in the connect() method below:
* context.setSecure(true);
*/
import com.wm.app.b2b.client.*;
import com.wm.util.*;
import java.util.StringTokenizer;
public class PackageInstaller
{
public static String hostName = null;
public static String port = null;
public static String userName = null;
public static String password = null;
public static String errorMsg = null;
public static String packages = null;
public static String tmpStr = null;
Context context = null;
public boolean connected = false;
public static boolean secure = false;
public static void main(String[] args)
{
/***********************************************************************/
/* Parse command line. The hostname, port, username and password must */
/* ALL be specified. */
/***********************************************************************/
errorMsg = "";
for (int iCtr = 0; iCtr < args.length; iCtr++)
{
if (args[iCtr].indexOf("host:") != -1) {
hostName = args[iCtr].substring(5);
if (hostName.length() < 1)
errorMsg = errorMsg + "\n No host name specified";
}
else if (args[iCtr].indexOf("port:") != -1) {
port = args[iCtr].substring(5);
if (port.length() < 1)
errorMsg = errorMsg + "\n No port specified";
}
else if (args[iCtr].indexOf("user:") != -1) {
userName = args[iCtr].substring(5);
if (userName.length() < 1)
errorMsg = errorMsg + "\n No user name specified";
}
else if (args[iCtr].indexOf("pswd:") != -1) {
password = args[iCtr].substring(5);
if (password.length() < 1)
errorMsg = errorMsg + "\n No password specified";
}
else if (args[iCtr].indexOf("pckg:") != -1) {
packages = args[iCtr].substring(5);
if (packages.length() < 1)
errorMsg = errorMsg + "\n No packages specified";
}
else {
errorMsg = errorMsg + "\n Invalid parameter '" +
args[iCtr] + "' specified.";
}
}
/***********************************************************************/
/* Display program usage instruction if there were any errors with the */
/* command line arguments. */
/***********************************************************************/
if ((errorMsg.length() > 0) || (hostName == null) || (port == null) ||
(userName == null) || (password == null) || (packages == null)) {
System.out.println(" Usage: java -classpath " +
"<path_to_client_classes> PackageInstaller " +
"host:<hostname> port:<port> user:<username> " +
"pswd:<password> pckg:<package1>,<package2>,...\n");
System.out.println(" Omit the .zip extension for package names");
if (errorMsg.length() > 0)
System.out.println(" Errors encountered:" + errorMsg);
System.exit(1);
}
//Create an instance of this class
PackageInstaller packageInstaller = new PackageInstaller();
System.out.println("Instantiated installer");
packageInstaller.connect(true);
if(!packageInstaller.connected) {
System.exit(1);
}
StringTokenizer st = new StringTokenizer(packages, ",");
while (st.hasMoreTokens()) {
String packageName = st.nextToken();
packageInstaller.install(packageName + ".zip");
packageInstaller.activate(packageName);
}
System.exit(0);
}
public void connect(boolean dispMsg)
{
context = new Context();
try {
/***********************************************/
/* Uncomment the following line if using https */
/***********************************************/
// context.setSecure(true);
context.connect(hostName + ":" + port, userName, password);
connected = true;
}
catch(ServiceException e) {
if (dispMsg) {
System.out.println("Could not connect to " + hostName + ":" + port);
System.out.println(e.toString());
}
connected = false;
}
}
public void install(String packageName)
{
try {
System.out.println("Installing package " + packageName + " ... ");
Values input = new Values();
input.put("file", packageName);
Values data = context.invoke("wm.server.packages", "packageInstall", input);
// System.out.println("IData:\n");
// System.out.println(data.toString());
}
catch(ServiceException e) {
System.out.println(e.toString());
System.exit(1);
}
}
public void activate(String packageName)
{
try {
System.out.println("Activating package " + packageName + " ... ");
Values input = new Values();
input.put("package", packageName);
Values data = context.invoke("wm.server.packages", "packageActivate", input);
// System.out.println("IData:\n");
// System.out.println(data.toString());
}
catch(ServiceException e) {
System.out.println(e.toString());
System.exit(1);
}
}
public PackageInstaller()
{
System.out.println();
System.out.println("******PackageInstaller utility*******");
System.out.println();
}
}
Remarks :
- When compiling and running the java program make sure to include files wm-isclient.jar and mail.jar in your class path. File wm-isclient.jar can found in the "common/lib" folder of an Integration Server whereas file mail.jar is localized in the "ext" sub folder of the "common/lib" folder.
- Usage of the PackageInstaller program is PackageInstaller host:<hostname> port:<port>
user:<username> pswd:<password>
pckg:<package1>,<package2>,...
The .zip extension for package names should be omitted - At this moment the java program is working with at least webMethods Integration Server v7.1.2. Specifications contained herein are potentially subject to change so use them at your own risk.
Author: Johan De Wulf
No comments:
Post a Comment