Download Usage: java -classpath PackageInstaller

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
/*
* 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)
{
/******************************************************************
*****/
password must
/* Parse command line. The hostname, port, username and
*/
/* 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();
}
}
Related documents