cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2766
Views
5
Helpful
8
Replies

Configure CUCM with AXL

Daniel Flieth
Level 1
Level 1

Hello guys,

i have a question to the AXL programming. Today i looked for tutorials to make a small programm, maybe just to configure one translation pattern.

But when i search at google, i´ve found only tutorials which dont show the whole process. (a step by step - from the beginning to the end - tutorial would be nice). Does anybody have such a tutorial?

If not, can you tell me whats the best guide to learn AXL Programming?

Best Regards

Daniel

1 Accepted Solution

Accepted Solutions

Hi Daniel

Basically those errors you screengrabbed are because you have referenced classes such as SOAPElement in the code, but haven't 'imported' them at the top of your file. Anything that isn't an absolute core part of java needs to be imported, or referred to with it's full path.

So for example,  you have an 'import javax.xml.soap.SOAPBody', and in your code you can then refer to SOAPBody, instead of javax.xml.soap.SOAPBody.

You don't have a line for SOAPElement, so need to add one. To do this you need to know what the full name of the class is, or if you are using an IDE (I use Netbeans) you can simply right click in the code window and select 'Fix Imports' and it will let you pick them from it's list of guesses.

If you aren't using an IDE (which you should do, as it provides lots of syntax checking etc), then just add these lines to the top. Order isn't important, just put them with the other imports:

import javax.xml.soap.SOAPElement;

import java.io.FileReader;
import java.io.BufferedReader;

import java.util.StringTokenizer;

import javax.xml.soap.Name;

Aaron Harrison

Principal Engineer at Logicalis UK

Please rate helpful posts...

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!

View solution in original post

8 Replies 8

Aaron Harrison
VIP Alumni
VIP Alumni

Hi

I wrote a tutorial based around the AxlSqlToolkit demo code that comes with CUCM. It's done in java...

http://www.ipcommute.co.uk/technical-articles/6--using-axlsqltoolkit-for-everything.html

Regards

Aaron Harrison

Principal Engineer at Logicalis UK

Please rate helpful posts...

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!

Hi,

I did this tutorial today :)

But i always ended with Java errors.

I will try it again tomorrow :)

Best Regards

Daniel

Hi

Probably my authoring skills letting you down :-)

Maybe post up your code and errors (or PM me if you are shy) and I'll see whether it's you or me that went wrong! I'm sure there is room for improvement in the doc...

Aaron

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!

Hey Aaron,

today the same issue

Here the error messages and the code (it should be the code you descripted in your tutorial)

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import org.apache.xerces.parsers.DOMParser;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
//import javax.xml.messaging.URLEndpoint;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.DocumentTraversal;
import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.traversal.TreeWalker;
import org.xml.sax.InputSource;

/**
*/
public class AxlCreateTrans {
    /** Defines the connection to AXL for the test driver */
    private SOAPConnection con;

    /** DOCUMENT ME! */
    private String port = "8443";

    /** DOCUMENT ME! */
    private String host = "localhost";

    private String username = null;

    private String password = null;
   
    /**  */
    private String outputFile = "sample.response";
    private String inputFile = "sample.xml";
   
    private String currentStatement = null;

    /**
     * This method provides the ability to initialize the SOAP connection
     */
    private void init() {
        try {
            X509TrustManager xtm = new MyTrustManager();
            TrustManager[] mytm = { xtm };
            SSLContext ctx = SSLContext.getInstance("SSL");
            ctx.init(null, mytm, null);
            SSLSocketFactory sf = ctx.getSocketFactory();

            SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
            con = scf.createConnection();

            HttpsURLConnection.setDefaultSSLSocketFactory(sf);
            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * This method provides the ability to convert a SOAPMessage to a String
     *
     * @param inMessage SOAPMessage
     * @return String The string containing the XML of the SOAPMessage
     * @throws Exception Indicates a problem occured during processing of the SOAPMessage
     */
    public static String convertSOAPtoString(SOAPMessage inMessage) throws Exception {
        Source source = inMessage.getSOAPPart().getContent();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        ByteArrayOutputStream myOutStr = new ByteArrayOutputStream();
        StreamResult res = new StreamResult();
        res.setOutputStream(myOutStr);
        transformer.transform(source, res);
        return myOutStr.toString().trim();
    }

    /**
     */
    public SOAPMessage createSqlMessage(String cmdName, String sql) throws Exception {
        // Add a soap body element to the soap body
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage soapMessage = mf.createMessage();
        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        SOAPBody bdy = envelope.getBody();
        SOAPBodyElement bodyElement = bdy.addBodyElement(envelope.createName(cmdName));
        bodyElement.addAttribute(envelope.createName("sequence"), String.valueOf(System.currentTimeMillis()));
        bodyElement.addChildElement("sql").addTextNode(sql);
        return soapMessage;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getUrlEndpoint() {
        return new String("https://" + username + ":" + password + "@" + host + ":" + port + "/axl/");
    }

    /**
     * This method provides the ability to send a specific SOAPMessage
     *
     * @param requestMessage The message to send
     */
    public SOAPMessage sendMessage(SOAPMessage requestMessage) throws Exception {
        SOAPMessage reply = null;
        try {
            System.out.println("*****************************************************************************");
            System.out.println("Sending message...");
            System.out.println("---------------------");
            requestMessage.writeTo(System.out);
            System.out.println("\n---------------------");

            reply = con.call(requestMessage, getUrlEndpoint());

            if (reply != null) {
                //Check if reply includes soap fault
                SOAPPart replySP = reply.getSOAPPart();
                SOAPEnvelope replySE = replySP.getEnvelope();
                SOAPBody replySB = replySE.getBody();

                if (replySB.hasFault()) {
                    System.out.println("ERROR: " + replySB.getFault().getFaultString());
                }
                else {
                    System.out.println("Positive response received.");
                }
                System.out.println("---------------------");
                reply.writeTo(System.out);
                FileWriter fw = new FileWriter(outputFile, true);
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write("---------------------------- " + currentStatement + " ----------------------------");
                bw.newLine();
                bw.write(convertSOAPtoString(reply));
                bw.newLine();
                bw.flush();
                bw.close();
                System.out.println("\n---------------------");
            }
            else {
                System.out.println("No reply was received!");
                System.out.println("---------------------");
            }

            System.out.println("");
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

        return reply;
    }

    /**
     * This method provides the ability to execute the unit testing
     */
    private void execute() {
         try {
            // first, initialize the output file
            new FileWriter(outputFile).close();
            FileReader fRead = new FileReader(inputFile);
            BufferedReader buffRead = new BufferedReader(fRead);
            String currentLine = buffRead.readLine();
            while (currentLine != null) {
                System.out.println("Processing : " + currentLine);
                StringTokenizer st = new StringTokenizer(currentLine, ",");
                String sPattern = st.nextToken();
                String sPartition = st.nextToken();
                if (sPartition.equals("#")) {
                    sPartition = "";
                }
                String sCSS = st.nextToken();
                if (sCSS.equals("#")) {
                    sCSS = "";
                }
                String sMask = st.nextToken();
                if (sMask.equals("#")) {
                    sMask = "";
                } else {
                    sMask = sMask.trim();
                }
                System.out.println("Inserting : Pattern(" + sPattern + ")    Partition(" + sPartition + ")     CSS(" + sCSS + ")    Called Party Mask(" + sMask + ")");
                sendMessage(createSOAPMessage(sPattern, sPartition, sCSS, sMask));
                currentLine = buffRead.readLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

public SOAPMessage createSOAPMessage(String sPattern, String sPartition, String sCSS, String sMask) throws Exception {
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage soapMessage = mf.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody bdy = envelope.getBody();
        SOAPBodyElement bodyElement = bdy.addBodyElement(envelope.createName("addTransPattern", "axl", "http://www.cisco.com/AXL/API/1.0"));
        Name attrUuid = envelope.createName("uuid");
        SOAPElement newPattern = bodyElement.addChildElement("newPattern");
        newPattern.addAttribute(envelope.createName("sequence"), String.valueOf(System.currentTimeMillis()));
        newPattern.addChildElement("pattern").addTextNode(sPattern);
        newPattern.addChildElement("callingSearchSpaceName").addTextNode(sCSS);
        newPattern.addChildElement("usage");
        newPattern.addChildElement("routePartitionName").addTextNode(sPartition);
        newPattern.addChildElement("blockEnable");
        newPattern.addChildElement("calledPartyTransformationMask").addTextNode(sMask);
        newPattern.addChildElement("callingPartyTransformationMask");
        newPattern.addChildElement("useCallingPartyPhoneMask").addTextNode("Off");
        SOAPElement dialPlan = newPattern.addChildElement("dialPlan");
        dialPlan.addChildElement("name");
        newPattern.addChildElement("dialPlanWizardGenId").addTextNode("0");
        newPattern.addChildElement("networkLocation");
        newPattern.addChildElement("patternUrgency").addTextNode("True");
        newPattern.addChildElement("prefixDigitsOut");
        newPattern.addChildElement("routeFilterName");
        return soapMessage;
    }

    /**
     * This method provides the main method for the class
     *
     * @param args Standard Java PSVM arguments
     */
    public static void main(String[] args) {
        try {
            AxlCreateTrans ast = new AxlCreateTrans();
            ast.parseArgs(args);
            ast.init();
            ast.execute();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param args DOCUMENT ME!
     */
    private void parseArgs(String[] args) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].startsWith("-username")) {
                username = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
            }
            else if (args[i].startsWith("-password")) {
                password = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
                            int j = 0;
                             String encodedPwd = null;
                             if (password.length() > 0) {
                                 while (j < password.length()) {
                                     if (password.charAt(j) == '`'
                                         || password.charAt(j) == '!'
                                         || password.charAt(j) == '@'
                                         || password.charAt(j) == '#'
                                         || password.charAt(j) == '$'
                                         || password.charAt(j) == '%'
                                         || password.charAt(j) == '^'
                                         || password.charAt(j) == '&'
                                         || password.charAt(j) == '('
                                         || password.charAt(j) == ')'
                                         || password.charAt(j) == '{'
                                         || password.charAt(j) == '}'
                                         || password.charAt(j) == '['
                                         || password.charAt(j) == ']'
                                         || password.charAt(j) == '|'
                                         || password.charAt(j) == '\\'
                                         || password.charAt(j) == ';'
                                         || password.charAt(j) == '\"'
                                         || password.charAt(j) == '\''
                                         || password.charAt(j) == '<'
                                         || password.charAt(j) == '>'
                                         || password.charAt(j) == '~'
                                         || password.charAt(j) == '?'
                                         || password.charAt(j) == '/'
                                         || password.charAt(j) == ' ') {
                                         if (encodedPwd == null) {
                                             encodedPwd = "%" + DeciTohex(password.charAt(j));
                                         }
                                         else {
                                             encodedPwd += "%" + DeciTohex(password.charAt(j));
                                         }
                                     }
                                     else {
                                         if (encodedPwd == null) {
                                             encodedPwd = Character.toString(password.charAt(j));

                                         }
                                         else {
                                             encodedPwd += password.charAt(j);
                                         }
                                     }
                                     j++;
                                 }
                             }
                             password = encodedPwd;
            }
            else if (args[i].startsWith("-host")) {
                host = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
            }
            else if (args[i].startsWith("-port")) {
                port = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
            }
            else if (args[i].startsWith("-input")) {
                inputFile = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
            }
            else if (args[i].startsWith("-output")) {
                outputFile = args[i].substring(args[i].indexOf("=") + 1, args[i].length());
            }
            else {
                usage();
                System.exit(-1);
            }
        }
    }

    /**
     * DOCUMENT ME!
     */
    private void usage() {
        System.out.println("AxlTestDriver (Java) parameters and options:");
        System.out.println("  -username=: use the specified username instead of default");
        System.out.println("  -password=: use the specified password instead of default");
        System.out.println("  -host=: use the specified hostname");
        System.out.println("  -port=: use the specified portnumber");
        System.out.println("  -input=: use the specified file as the source of the sql statements");
        System.out.println("  -output=: use the specified file as the destination of the AXL responses");
    }

    /* testing the SSL interface */
    public class MyTrustManager implements X509TrustManager {
        MyTrustManager() {}
        public void checkClientTrusted(X509Certificate chain[], String authType) throws CertificateException {}
        public void checkServerTrusted(X509Certificate chain[], String authType) throws CertificateException {}
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    }
    public static String DeciTohex(int d) {
         int rem;
         String output = "";
         String digit;
         String backwards = "";

         do {
             rem = d % 16;
             digit = DtoHex(rem);
             d = d / 16;
             output += digit;
         }
         while (d / 16 != 0);

         rem = d % 16;

         digit = DtoHex(rem);

         output = output + digit;

         for (int i = output.length() - 1; i >= 0; i--) {
             backwards += output.charAt(i);
         }

         return backwards;
     }

     public static String DtoHex(int rem) {

         String str1 = String.valueOf(rem);

         if (str1.equals("10"))
             str1 = "A";

         else if (str1.equals("11"))
             str1 = "B";

         else if (str1.equals("12"))
             str1 = "C";

         else if (str1.equals("13"))
             str1 = "D";

         else if (str1.equals("14"))
             str1 = "E";

         else if (str1.equals("15"))
             str1 = "F";

         else
             str1 = str1;

         return str1;
     }
}

slashdots
Level 1
Level 1

Just in case you've not found that site yet:

http://developer.cisco.com/web/axl/start

I think a lot of your questions can be solved there (it's the cisco developer network)

Hi Daniel

Basically those errors you screengrabbed are because you have referenced classes such as SOAPElement in the code, but haven't 'imported' them at the top of your file. Anything that isn't an absolute core part of java needs to be imported, or referred to with it's full path.

So for example,  you have an 'import javax.xml.soap.SOAPBody', and in your code you can then refer to SOAPBody, instead of javax.xml.soap.SOAPBody.

You don't have a line for SOAPElement, so need to add one. To do this you need to know what the full name of the class is, or if you are using an IDE (I use Netbeans) you can simply right click in the code window and select 'Fix Imports' and it will let you pick them from it's list of guesses.

If you aren't using an IDE (which you should do, as it provides lots of syntax checking etc), then just add these lines to the top. Order isn't important, just put them with the other imports:

import javax.xml.soap.SOAPElement;

import java.io.FileReader;
import java.io.BufferedReader;

import java.util.StringTokenizer;

import javax.xml.soap.Name;

Aaron Harrison

Principal Engineer at Logicalis UK

Please rate helpful posts...

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!

YOU ARE BRILLIANT Thanks so much. I have to learn Java now

No problem :-)

Book recommendation: Head First Java - If you want to learn java it's a really good place to start, much less dry than your average techie manual. Kind of reminded me of school books :-)

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: