Hello World with Java

To get started using AXL, let's look at an API request for a simple example.

Example Scenario: We want to get information about a particular phone.

For this task, we need to make the getPhone API request to the CUCM publisher.

Java Example


// Here is a java example of how to use the getPhone API call

import java.io.*;
import java.net.*;

public class AXLSample {
    public static void main(String[] args) throws Exception {
        //AXL service URL on Unified CM host ds-ucm851.cisco.com
        //Note this sample assumes the certificate for the host with subject
        //name 'host.com' has been imported into the Java keystore
        URL url = new URL("https://host.com:8443/axl/");
        //Create a java.net URLConnection object to make the HTTP request
        URLConnection conn = url.openConnection();
        //setDoOutput=true causes the URLConnection to perform a POST operation
        conn.setDoOutput(true);
        //HTTP Basic authorization string - a base64 encoded string with username:password, in this case 'Administrator:cisco!123'
        //This should be a UCM application user with Standard CCM Admin User and Standard AXL API Access roles
        String authorization = QWRtaW5pc3RyYXRvcjpjaXNjbyExMjM=";
        conn.setRequestProperty("Authorization","Basic " + authorization);
        //Set the SOAPAction header to 'CUCM:DB ver=8.5' for use with a UCM 8.5(1) host, request is 'getPhone'
        conn.setRequestProperty("SOAPAction","\"CUCM:DB ver=8.5 getPhone\"");
        //The request body will be in XML format
        conn.setRequestProperty("Content-Type","text/xml");

        //Build a string containing the contents of the AXL XML request - here 'getPhone'
        String AXLRequest = "<soapenv:Envelope xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="https://www.cisco.com/AXL/API/8.5">";
        AXLRequest += "<soapenv:Body><ns:getPhone><name>SEP001B0CDBBE33</name></ns:getPhone></SOAP-ENV:Envelope>";

        //Create an OutputStreamWriter for the URLConnection object and make the request
        OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
        writer.write(AXLRequest);
        writer.flush();

        //Read the response
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

        //Output the response to the console
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        //Cleanup the stream objects
        writer.close();
        reader.close();
    }
}

Go to Java/JAX-WS Quickstart to learn how to setup a Java application.

cURL Example

Go to Hello World with cURL to get started with another AXL Web Services "Hello World" example.