cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1110
Views
0
Helpful
3
Replies

How to login IP Phone cisco from cucm with 3rd party program #extentionmobility

vanjavajazz
Beginner
Beginner

Hello everyone
I have some trouble with developt extention mobility 3rd party program
The concept is, I wanna login my account that contain my ext from an app (in general login from Ip phone devices)

Then I found this link Sample Apps- Cisco EMAPI

problem that I found by using this code is ssl problem.. then I've succeed passed it using some code
then till now I'm got stuck whis this

heres the codes

package com.cisco.extensionmobility;

import java.io.*;

import java.net.URLEncoder;

import java.io.InputStreamReader;

import java.net.URL;

import java.net.URLConnection;

import javax.net.ssl.HostnameVerifier;

import javax.net.ssl.HttpsURLConnection;

import javax.net.ssl.SSLContext;

import javax.net.ssl.SSLSession;

import javax.net.ssl.TrustManager;

import javax.net.ssl.X509TrustManager;

import java.security.cert.X509Certificate;

public class EMAPISample {

public static void main(String[] args) throws Exception {

  // Create a trust manager that does not validate certificate chains

    TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {

            public java.security.cert.X509Certificate[] getAcceptedIssuers() {

                return null;

            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {

            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {

            }

        }

    };

//To test with insecure connection use the URL as http://cucm-host.com:8080/emservice/EMServiceServlet

    // Install the all-trusting trust manager

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

    sc.init(null, trustAllCerts, new java.security.SecureRandom());

    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    // Create all-trusting host name verifier

    HostnameVerifier allHostsValid = new HostnameVerifier() {

        public boolean verify(String hostname, SSLSession session) {

        

        return true;

        }

    };

    // Install the all-trusting host verifier

    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

   

    URL url = new URL("https://192.168.10.11:8443/emservice/EMServiceServlet");

//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);

//The request body will be in HTTP form encoded format

conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

//Build a string containing the contents of the E/M API XML request - here 'login'

String EMRequest = "<request><appinfo><appid>operator</appid><appcertificate>operator</appcertificate></appinfo>";

EMRequest += "<login><devicename>SEP000000000003</devicename><userid>ivan</userid><deviceprofile>ivan</deviceprofile>";

EMRequest += "<exclusiveduration><time>60</time></exclusiveduration></login></request>";

//URL encode/escape the request

EMRequest = URLEncoder.encode(EMRequest,"UTF-8");

//Build the complete HTTP form request body

EMRequest = "xml="+EMRequest;

//Create an OutputStreamWriter for the URLConnection object and make the request

OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

writer.write(EMRequest);

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);

}

writer.close();

reader.close();

}

}

The result is

Error processing request: null


Is there any solution? Please helpp
I've got stuck for many days with this code

Thank you very much

3 REPLIES 3

Geevarghese Cheria
Cisco Employee
Cisco Employee

Hi Ivan,

Did you had chance to try out the steps mentioned in this url - EM Proxy service

Request to post if there is any further question related to the topic under Extension Mobility API community.

Thanks and Regards,

Geevarghese

pesnexium
Beginner
Beginner

Sorry to be late for answering, but I have just faced the same situtation. After having solved the isssue of certificate, I solved that one by modifying the case of the inside elements <appID>, etc.

Hello,

I work on this Momont on cisco extension mobility, and try to login user id in the IP phone. when i try to do it on the phone directely it's working.

But when I try to execute my code that I have developed , I receive an error code 0 and I ignore this error.


<respone>

<failure>

<error code ="0"> null </error>

</failure>

</response>


can you please help me I inform you that my code is as follows:  thank you in advance




using System;

using System.Collections.Generic;

using System.Text;

using System.Collections;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Net;

using System.IO;

using System.Configuration;

using System.Net.Configuration;

using System.Xml;

namespace EM_Firmwares

{

    class EM

    {

      static void Main(string[] args)  {

Login("SEP1CAA07E3743D", "wma", "");

}

        public static void Login(string device, string userID, string udp ="")

        {

            string TempUrl = string.Empty;

            string Host = ConfigurationManager.AppSettings["192.168.0.110"];

            TempUrl = "http://" + Host + ":8080/emservice/EMServiceServlet";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            StringBuilder emRequest = new StringBuilder("");

            HttpWebResponse Response;

            Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SettingsSection Section = (SettingsSection)Config.GetSection("system.net/settings");

            Section.HttpWebRequest.UseUnsafeHeaderParsing = true;

            Config.Save();

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(TempUrl);

            Request.ProtocolVersion = System.Net.HttpVersion.Version11;

            Request.Timeout = 100000;

            Request.Method = "POST";

            Request.ContentType = "application/x-www-form-urlencoded";

            Request.Accept = "Accept: text/*";

            string emUser = ConfigurationManager.AppSettings["MC"];

            string emPassword = ConfigurationManager.AppSettings["Azopqslm123!"];

            emRequest.Append("xml=<request><appInfo><appID>" + emUser + "</appID><appCertificate>" + emPassword + "</appCertificate></appInfo>");

            emRequest.Append("<login><deviceName>" + device + "</deviceName><userID>" + userID + "</userID>");

            if(udp != ""){emRequest.Append("<deviceProfile>" + udp + "</deviceProfile>");}

            emRequest.Append("<exclusiveDuration><indefinite></indefinite></exclusiveDuration></login></request>");

            Request.ContentLength = (long)emRequest.Length;

            try

            {

                Stream RequestStream = Request.GetRequestStream();

                RequestStream.Write(System.Text.Encoding.ASCII.GetBytes(emRequest.ToString()), 0, emRequest.Length);

                RequestStream.Close();

            }

            catch (WebException x)

            {

                Console.WriteLine("Login Error, " + udp + ", " + device + ", " + userID + ", " + x.Message);

                return;

            }

            string Xml = string.Empty;

            try

            {

                Response = (HttpWebResponse)Request.GetResponse();

                Stream ResponseStream = Response.GetResponseStream();

                StreamReader ReadStream = new StreamReader(ResponseStream, Encoding.UTF8);

                Xml = ReadStream.ReadToEnd();

            }

            catch (WebException x1)

            {

                Console.WriteLine("Login Error, " + udp + ", " + device + ", " + userID + ", " + x1.Message);

                return;

            }

            XmlDocument xdoc = new XmlDocument();    

            xdoc.LoadXml(Xml);

            XmlNode node = xdoc.DocumentElement;

            XmlNodeList nodeList  = node.SelectNodes("success");

            if (nodeList.Count == 0)

            {

                nodeList = node.SelectNodes("failure");

                Console.WriteLine("Login Error, " + udp + ", " + device + ", " + userID + ", " + nodeList[0].InnerText);

            }

            else

            {

                Console.WriteLine("Login Success, " + udp + ", " + device + ", " + userID + ",");

            } 

        }

        public static string Logout(string device)

        {

            string TempUrl = string.Empty;

            string Host = ConfigurationManager.AppSettings["192.168.0.110"];

            TempUrl = "http://" + Host + ":8080/emservice/EMServiceServlet";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            StringBuilder emRequest = new StringBuilder("");

            HttpWebResponse Response;

            Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SettingsSection Section = (SettingsSection)Config.GetSection("system.net/settings");

            Section.HttpWebRequest.UseUnsafeHeaderParsing = true;

            Config.Save();

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(TempUrl);

            Request.ProtocolVersion = System.Net.HttpVersion.Version11;

            Request.Timeout = 100000;

            Request.Method = "POST";

            Request.ContentType = "application/x-www-form-urlencoded";

            Request.Accept = "Accept: text/*";

            string emUser = ConfigurationManager.AppSettings["MC"];

            string emPassword = ConfigurationManager.AppSettings["Azopqslm123!"];

            emRequest.Append("xml=<request><appInfo><appID>" + emUser + "</appID><appCertificate>" + emPassword + "</appCertificate></appInfo>");

            emRequest.Append("<logout><deviceName>" + device + "</deviceName>");

            emRequest.Append("</logout></request>");

            Request.ContentLength = (long)emRequest.Length;

            try

            {

                Stream RequestStream = Request.GetRequestStream();

                RequestStream.Write(System.Text.Encoding.ASCII.GetBytes(emRequest.ToString()), 0, emRequest.Length);

                RequestStream.Close();

            }

            catch (WebException x)

            {

                Console.WriteLine("Logout Error, "  + device +  ", " + x.Message);

                return "Error";

            }

            string Xml = "";

            try

            {

                Response = (HttpWebResponse)Request.GetResponse();

                Stream ResponseStream = Response.GetResponseStream();

                StreamReader ReadStream = new StreamReader(ResponseStream, Encoding.UTF8);

                Xml = ReadStream.ReadToEnd();

            }

            catch (WebException x1)

            {

                Console.WriteLine("Logout Error, "  + device + ", "  + x1.Message);

                return "Error";

            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(Xml);

            XmlNode node = xdoc.DocumentElement;

            XmlNodeList nodeList = node.SelectNodes("success");

            if (nodeList.Count == 0)

            {

                nodeList = node.SelectNodes("failure");

                Console.WriteLine("Logout Error, "  + device + ", "  + nodeList[0].InnerText);

                return "Error";

            }

            else

            {

                Console.WriteLine("Logout Success, " + device  + ",");

                return "success";

            } 

        }

        public static string UserQuery(string device)

        {

            string TempUrl = string.Empty;

            string Host = ConfigurationManager.AppSettings["192.168.0.110"];

            TempUrl = "http://" + Host + ":8080/emservice/EMServiceServlet";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            StringBuilder emRequest = new StringBuilder("");

            HttpWebResponse Response;

            Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SettingsSection Section = (SettingsSection)Config.GetSection("system.net/settings");

            Section.HttpWebRequest.UseUnsafeHeaderParsing = true;

            Config.Save();

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(TempUrl);

            Request.ProtocolVersion = System.Net.HttpVersion.Version11;

            Request.Timeout = 100000;

            Request.Method = "POST";

            Request.ContentType = "application/x-www-form-urlencoded";

            Request.Accept = "Accept: text/*";

            string emUser = ConfigurationManager.AppSettings["MC"];

            string emPassword = ConfigurationManager.AppSettings["Azopqslm123!"];

            emRequest.Append("xml=<query><appInfo><appID>" + emUser + "</appID><appCertificate>" + emPassword + "</appCertificate></appInfo>");

            emRequest.Append("<deviceUserQuery><deviceName>" + device + "</deviceName>");

            emRequest.Append("</deviceUserQuery></query>");

            Request.ContentLength = (long)emRequest.Length;

            try

            {

                Stream RequestStream = Request.GetRequestStream();

                RequestStream.Write(System.Text.Encoding.ASCII.GetBytes(emRequest.ToString()), 0, emRequest.Length);

                RequestStream.Close();

            }

            catch (WebException x)

            {

                Console.WriteLine("UserQuery Error, " + device + ", " + x.Message);

                return "Error";

            }

            string Xml = "";

            try

            {

                Response = (HttpWebResponse)Request.GetResponse();

                Stream ResponseStream = Response.GetResponseStream();

                StreamReader ReadStream = new StreamReader(ResponseStream, Encoding.UTF8);

                Xml = ReadStream.ReadToEnd();

            }

            catch (WebException x1)

            {

                Console.WriteLine("UserQuery Error, " + device + ", " + x1.Message);

                return "Error";

            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(Xml);

            XmlNode node = xdoc.DocumentElement;

            XmlNodeList nodeList = xdoc.GetElementsByTagName("userID");

            if (nodeList.Count == 0)

            {

                nodeList = xdoc.GetElementsByTagName("none");

                if (nodeList.Count != 0)

                {

                    string result = "UserQuery Success, " + device + ", " + "No user logged in (No Error)";

                    Console.WriteLine(result);

                    return result;

                }

                else

                {

                    nodeList = node.SelectNodes("failure");

                    string error = "UserQuery Error, " + device + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n');

                    Console.WriteLine(error);

                    return error;

                }

               

            }

            else

            {

                Console.WriteLine("UserQuery Success, " + device + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n'));

                return nodeList[0].InnerText;

            }

           

        }

        public static string DeviceQuery(string userID)

        {

            string TempUrl = string.Empty;

            string Host = ConfigurationManager.AppSettings["192.168.0.110"];

            TempUrl = "http://" + Host + ":8080/emservice/EMServiceServlet";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            StringBuilder emRequest = new StringBuilder("");

            HttpWebResponse Response;

            Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SettingsSection Section = (SettingsSection)Config.GetSection("system.net/settings");

            Section.HttpWebRequest.UseUnsafeHeaderParsing = true;

            Config.Save();

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(TempUrl);

            Request.ProtocolVersion = System.Net.HttpVersion.Version11;

            Request.Timeout = 100000;

            Request.Method = "POST";

            Request.ContentType = "application/x-www-form-urlencoded";

            Request.Accept = "Accept: text/*";

            string emUser = ConfigurationManager.AppSettings["MC"];

            string emPassword = ConfigurationManager.AppSettings["Azopqslm123!"];

            emRequest.Append("xml=<query><appInfo><appID>" + emUser + "</appID><appCertificate>" + emPassword + "</appCertificate></appInfo>");

            emRequest.Append("<userDevicesQuery><userID>" + userID + "</userID>");

            emRequest.Append("</userDevicesQuery></query>");

            Request.ContentLength = (long)emRequest.Length;

            try

            {

                Stream RequestStream = Request.GetRequestStream();

                RequestStream.Write(System.Text.Encoding.ASCII.GetBytes(emRequest.ToString()), 0, emRequest.Length);

                RequestStream.Close();

            }

            catch (WebException x)

            {

                Console.WriteLine("DeviceQuery Error, " + userID + ", " + x.Message);

                return "Error";

            }

            string Xml = "";

            try

            {

                Response = (HttpWebResponse)Request.GetResponse();

                Stream ResponseStream = Response.GetResponseStream();

                StreamReader ReadStream = new StreamReader(ResponseStream, Encoding.UTF8);

                Xml = ReadStream.ReadToEnd();

            }

            catch (WebException x1)

            {

                Console.WriteLine("DeviceQuery Error, " + userID + ", " + x1.Message);

                return "Error";

            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(Xml);

            XmlNode node = xdoc.DocumentElement;

            XmlNodeList nodeList = xdoc.GetElementsByTagName("deviceName");

            if (nodeList.Count == 0)

            {

                nodeList = node.SelectNodes("failure");

                string error = "UserQuery Error, " + userID + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n');

                Console.WriteLine(error);

                return error;

            }

            else

            {

                Console.WriteLine("DeviceQuery Success, " + userID + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n'));

                return nodeList[0].InnerText;

            }

        }

        public static string DeviceProfileQuery(string userID)

        {

            string TempUrl = string.Empty;

            string Host = ConfigurationManager.AppSettings["192.168.0.110"];

            TempUrl = "http://" + Host + ":8080/emservice/EMServiceServlet";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            StringBuilder emRequest = new StringBuilder("");

            HttpWebResponse Response;

            Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            SettingsSection Section = (SettingsSection)Config.GetSection("system.net/settings");

            Section.HttpWebRequest.UseUnsafeHeaderParsing = true;

            Config.Save();

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(TempUrl);

            Request.ProtocolVersion = System.Net.HttpVersion.Version11;

            Request.Timeout = 100000;

            Request.Method = "POST";

            Request.ContentType = "application/x-www-form-urlencoded";

            Request.Accept = "Accept: text/*";

            string emUser = ConfigurationManager.AppSettings["MC"];

            string emPassword = ConfigurationManager.AppSettings["Azopqslm123!"];

            emRequest.Append("xml=<query><appInfo><appID>" + emUser + "</appID><appCertificate>" + emPassword + "</appCertificate></appInfo>");

            emRequest.Append("<deviceProfileQuery><userID>" + userID + "</userID>");

            emRequest.Append("</deviceProfileQuery></query>");

            Request.ContentLength = (long)emRequest.Length;

            try

            {

                Stream RequestStream = Request.GetRequestStream();

                RequestStream.Write(System.Text.Encoding.ASCII.GetBytes(emRequest.ToString()), 0, emRequest.Length);

                RequestStream.Close();

            }

            catch (WebException x)

            {

                Console.WriteLine("UDPQuery Error, " + userID + ", " + x.Message);

                return "Error";

            }

            string Xml = "";

            try

            {

                Response = (HttpWebResponse)Request.GetResponse();

                Stream ResponseStream = Response.GetResponseStream();

                StreamReader ReadStream = new StreamReader(ResponseStream, Encoding.UTF8);

                Xml = ReadStream.ReadToEnd();

            }

            catch (WebException x1)

            {

                Console.WriteLine("UDPQuery Error, " + userID + ", " + x1.Message);

                return "Error";

            }

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(Xml);

            XmlNode node = xdoc.DocumentElement;

            XmlNodeList nodeList = xdoc.GetElementsByTagName("deviceProfileName");

            if (nodeList.Count == 0)

            {

                nodeList = node.SelectNodes("failure");

                string error = "UserQuery Error, " + userID + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n');

                Console.WriteLine(error);

                return error;

            }

            else

            {

                Console.WriteLine("UDPQuery Success, " + userID + ", " + nodeList[0].InnerText.TrimEnd('\r', '\n'));

                return nodeList[0].InnerText;

            }

        }

    }

}

cordially


Massinissa.

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: