Dashboard > Pulse v2.1 > ... > Remote API Examples > Java Example - GetAllProjectNames
  Pulse v2.1 Log In | Sign Up   View a printable version of the current page.  
  Java Example - GetAllProjectNames
Added by Jason Sankey, last edited by Jason Sankey on Mar 19, 2009
Labels: 
(None)

Pulse Manual Index

Overview

This example shows a simple login - query - logout cycle which is common to many uses of the API.

Code

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

/**
 * An example which illustrates token-based authentication, wrapping a simple
 * reporting method that returns the names of all projects on a Pulse server.
 *
 * The main method outputs the project names, one per line.
 */
public class GetAllProjectNames
{
    private static final String PULSE_URL = "http://pulse/xmlrpc";
    private static final String USERNAME = "user";
    private static final String PASSWORD = "secret";

    public static void main(String[] argv) throws MalformedURLException, XmlRpcException
    {
        // Create a client to talk to the Pulse XML-RPC service.
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(PULSE_URL));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);

        // Login to obtain an authentication token.
        String token = (String) client.execute("RemoteApi.login", Arrays.asList(USERNAME, PASSWORD));

        // Use the token as credentials when retrieving the project names.
        // Note that XML-RPC arrays are returned as Java arrays.
        Object[] projectNames = (Object[]) client.execute("RemoteApi.getAllProjectNames", Arrays.asList(token));

        // Logout now that we are done with the credentials.
        client.execute("RemoteApi.logout", Arrays.asList(token));
        
        for (Object projectName: projectNames)
        {
            System.out.println(projectName);
        }
    }
}

Zutubi wiki is Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators