cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1774
Views
0
Helpful
2
Replies

CUCM 10 SQL Query

marwa.ads
Level 1
Level 1

i am Trying to make soap request to executes sql query on CUCM 10.0 and seems that there's a problem in the request format,

any one can help? below is my code.

StringBuffer sb = new StringBuffer(2048);

        byte[] bArray = null; // buffer for reading response from

        Socket socket = null; // socket to AXL server

        OutputStream out = null; // output stream to server

        InputStream in = null; // input stream from server

        String sAXLSOAPRequest = "";

        String sAXLRequest = null; // will hold only the SOAP payload

        String authorization = CMUName + ":" + CMPass;

        authorization = new sun.misc.BASE64Encoder().encode(authorization.getBytes());

        sAXLSOAPRequest = "POST /axl/ HTTP/1.0\r\n";

        sAXLSOAPRequest += "Host:localhost:8443\r\n";

        sAXLSOAPRequest += "Authorization: Basic " + authorization + "\r\n";

        sAXLSOAPRequest += "Accept: text/*\r\n";

        sAXLSOAPRequest += "Content-type: text/xml\r\n";

        sAXLSOAPRequest += "SOAPAction: \"CUCM:DB ver=10\"\r\n";

        sAXLSOAPRequest += "Content-length: ";

        sAXLRequest = "<SOAP-ENV:Envelope "

                + " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"

                + "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" >";

        sAXLRequest += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "

                + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> ";

        sAXLRequest += "<SOAP-ENV:Body> <executeSQL" + type + " sequence='1012121' > "; //1397055592533

        sAXLRequest += "<sql>" + sqlquery + "</sql>";

        sAXLRequest += "</executeSQL" + type + ">  </SOAP-ENV:Body> </SOAP-ENV:Envelope>";

        // finish the HTTPS Header

        sAXLSOAPRequest += sAXLRequest.length();

        sAXLSOAPRequest += "\r\n\r\n";

        // now add the SOAP payload to the HTTPS header, which completes the AXL

        // SOAP request

        sAXLSOAPRequest += sAXLRequest;

        try {

            CUCMOperations axl = new CUCMOperations();

            // Implement the certificate-related stuffs required for sending request via https

            X509TrustManager xtm = axl.new MyTrustManager();

            TrustManager[] mytm = {xtm};

            SSLContext ctx = SSLContext.getInstance("SSL");

            ctx.init(null, mytm, null);

            SSLSocketFactory sslFact = (SSLSocketFactory) ctx.getSocketFactory();

            socket = (SSLSocket) sslFact.createSocket(CMIP, Integer.parseInt(CMPort));

            in = socket.getInputStream();

            // send the request to the server

            // read the response from the server

            bArray = new byte[2048];

            int ch = 0;

            int sum = 0;

            out = socket.getOutputStream();

            out.write(sAXLSOAPRequest.getBytes());

            while ((ch = in.read(bArray)) != -1) {

                sum += ch;

                sb.append(new String(bArray, 0, ch));

            }

            socket.close();

            // output the response to the standard output

            //System.out.println(sb.toString());

        } catch (UnknownHostException e) {

            System.err.println("Error connecting to host: " + e.getMessage());

            return "";

        } catch (IOException ioe) {

            System.err.println("Error sending/receiving from server: " + ioe.getMessage());

            return "";

            // close the socket

        } catch (Exception ea) {

            System.err.println("Unknown exception " + ea.getMessage());

            return "";

        } finally {

            try {

                if (socket != null) {

                    socket.close();

                }

            } catch (Exception exc) {

                System.err.println("Error closing connection to server: " + exc.getMessage());

                return "";

            }

        }

        return sb.toString();

    }

2 Replies 2

dstaudt
Cisco Employee
Cisco Employee

The code as listed needs to be updated to send the request to the actual UCM IP address, here:

>> sAXLSOAPRequest += "Host:localhost:8443\r\n";

What is the nature of the error/problem you are seeing?  Can you provide the XML request and response?

i receive the below response

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>error: The document is not a executeSQLQuery@http://www.cisco.com/AXL/API/10.0: document element namespace mismatch expected "http://www.cisco.com/AXL/API/10.0" got ""</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope>