// (c) Copyright 2014 by PTC Inc. All rights reserved.

/**
 * Example code to invoke an Integration Command Extension
 */

package ptc.integrationcommandextensions.example;

import java.io.IOException;

import com.mks.api.*;
import com.mks.api.response.APIException;
import com.mks.api.response.Response;
import com.mks.api.util.APIVersion;

public class RunIntegrationCommand
{
    public static void main(String[] args) throws APIException, IOException
    {
	IntegrationPoint ip = IntegrationPointFactory.getInstance()
		.createLocalIntegrationPoint(APIVersion.API_4_13);
	Session sess = ip.createSession("username", "password");
	Command cmd = new Command("vendor", "application", "customcommand");
	cmd.addOption(new Option("commandOption", "value"));

	CmdRunner cmdrun = sess.createCmdRunner();
	try {
	    Response r = cmdrun.execute(cmd);
	    System.out.print("Exit code: " + r.getExitCode());
	} catch (Exception e) {
	    System.err.println(e.getMessage());
	} finally {
	    cmdrun.release();
	    sess.release();
	    ip.release();
	}
    }
}
