08-19-2015 12:23 AM
HI i am already try a sample codes from Sample Apps- Cisco EMAPI
these are my code
package asd;
import java.io.*;
import java.net.*;
import java.net.URLEncoder;
import java.io.InputStreamReader;
import java.io.Reader;
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 asdf {
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) {
}
}
};
//E/M API service URL on Unified CM host host.com
//Note this sample assumes the certificate for the host with subject
//name 'cucm-host.com' has been imported into the Java keystore
//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>SEP000000000001</devicename><userid>user01</userid><deviceprofile>EM-USER01</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();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
writer.close();
reader.close();
}
}
actually i get a message " Error processing request: null "
but the login is stil failed.
08-31-2015 11:53 AM
I suspect you want to post this question here, instead, where you're more likely to get an answer:
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide