Top
Systemwalker Runbook Automation Operation Guide
Systemwalker

7.4.3 Starting Automated Operation Processes from the REST Interface

The REST interface can be used to start Automated Operation Processes.

Refer to the Systemwalker Runbook Automation Reference Guide for information on the REST interface.

Operation

  1. Use a Web console or the REST interface to check in advance the information required in order to start an Automated Operation Process from the REST interface, such as the name of the Automated Operation Process Group to be started and the process definition name.

  2. Use the REST interface to start the Automated Operation Process.

    An example of a Java program for starting an Automated Operation Process is shown below:

    import java.io.BufferedReader;
    import java.io.ByteArrayOutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    import javax.mail.internet.MimeUtility;
    
    /**
     * REST Client Sample
     *
     * <pre>
     * Using JavaMail utility for Base64 encoding
     * Enter JavaMail module (mail.jar) as required.
     * </pre>
     *
     */
    public class ClientApl {
    
    	// URL of connection destination
    	private final static String baseURL="http://example.com"
    
    	/**
    	 * Start process.
    	 * @param args
    	 */
    	public static void main(String[] args) {
    
    		String username="swrbaadmin";	// User ID
    		String password="systemwalker#1";	// Password
    		String appId = "TEST";	// Automated Operation Process Group name
    		String pdname = "TEST";	// Process definition name
    		String id_pass= null;
    		HttpURLConnection conn = null;
    
    		try {
    			URL url = new URL(baseURL + "/rbaserver/ProcessInstances" + "?"
    					+ "appid=" + appId
    					+ "&pdname=" + pdname);
    
    			// Encoding for Basic authentication
    			ByteArrayOutputStream bos = null;
    			OutputStream os = null;
    			try {
    				bos = new ByteArrayOutputStream();
    				os = MimeUtility.encode(bos , "base64");
    				os.write((username + ":" + password).getBytes());
    				os.flush();
    				id_pass = bos.toString();
    			} catch (Exception e) {
    				e.printStackTrace();
    				throw e;
    			} finally {
    				os.close();
    				bos.close();
    			}
    
    			// HTTP connection
    			conn = (HttpURLConnection) url.openConnection();
    			conn.setRequestProperty("Authorization", "Basic " + id_pass);
    
    			conn.setRequestMethod("POST");
    			conn.setRequestProperty("Content-Type","text/plain");
    			conn.setRequestProperty("Accept","application/xml");
    
    			conn.connect();
    
    			// Obtain results.
    			if (conn.getResponseCode() != HttpURLConnection.HTTP_OK){
    				// Request Error.
    
    				System.out.println("StatusCode : " + conn.getResponseCode());
    				System.exit(1);
    			}
    
    			BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    			String line = bf.readLine();
    			while(line != null){
    				System.out.println(line);
    				line = bf.readLine();
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			if ( conn != null){
    				conn.disconnect();
    			}
    		}
    
    		System.exit(0);
    
    	}
    
    }