Blogs

Check out the new content on the Cisco Developer Network reflecting the New & Enhanced features in Cisco Unified Communication Manager 9.1.

See the new ...Read More

 

The Unified Communications 9.0 Partner Bundle packages Cisco’s Collaboration application software for our Collaboration partner community to leverage for their internal lab or demonstration systems. The 9.0 version is now available for order. Learn More >> ...Read More

 

Cisco Extension Mobility Developers:

Check out the new content on the Cisco Developer Network reflecting the New & Enhanced features in Cisco Unified Communication Manager 9.0(1).

...Read More

 

Developer Partners,

Cisco announces the availability of our 2012 Developer Partner presentations shared at CiscoLive San Diego.

Please log into the Cisco Developer Network using your Partner UserID to download this content.

Access these presentations here: http://developer.cisco.com/web/cdc/devforumpreso PARTNER LOGIN REQUIRED
...Read More

 

Developer Partners,

Cisco announces the availability of our 2012 Developer Partner presentations shared at CiscoLive London.

Please log into the Cisco Developer Network using your Partner UserID to download this content.

Access these presentations here: http://developer.cisco.com/web/cdc/devforumpreso PARTNER LOGIN REQUIRED
...Read More

 

Showing 1 - 5 of 21 results.
Items per Page 5
of 5

Forums

« Back to Extension Mobility API Questions

java class to submit XML to EMServiceServlet

Combination View Flat View Tree View
Threads [ Previous | Next ]
I am trying to write a java class that will submit an XML request to the EMServiceServlet.
 
What I have now returns a 500 Internal Server Error, just like if I were to visit the servlet with a web browser.
 
So I think my problem is with my headers, but I can't be sure.
 
Does anyone see anything wrong with my code?
 
 
import java.io.*;
import java.net.*;
public class EMLoginLogout {
 public static String emLogin(String userid, String phoneName, String appID, String appPasswd) {
 // Build XML String
 String XMLString = new String();
 XMLString = "<request>";
 XMLString += "<appInfo>";
 XMLString += "<appID>" + appID + "</appID>";
 XMLString += "<appCertificate>" + appPasswd + "</appCertificate>";
 XMLString += "</appInfo>";
 XMLString += "<login>";
 XMLString += "<deviceName>" + phoneName + "</deviceName>";
 XMLString += "<userID>" + userid + "</userID>";
 XMLString += "<exclusiveDuration>";
 XMLString += "<time>60</time>";
 XMLString += "</exclusiveDuration>";
 XMLString += "</login>";
 XMLString += "</request>";
 try {
  // Make connection
  URL url = new URL("http://X.X.X.X:8080/emservice/EMServiceServlet");
  URLConnection urlConnection = url.openConnection();
  urlConnection.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
  urlConnection.setDoInput(true);
  urlConnection.setDoOutput(true);
  urlConnection.connect();
  OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream(),"UTF8");
  
 
  // Write XML string to request body
  out.write(XMLString);
  out.flush();
 // Read the response
 BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
 String line = null;
 while ((line = in.readLine()) != null)
 {
  //System.out.println(line);
  line += in.readLine();
 }
 out.close();
 in.close();
 return line;
 }
 catch (UnknownHostException e) {
    System.err.println("Error connecting to host: " + e.getMessage());
    return "-2";
   } catch (IOException ioe) {
    System.err.println("Error sending/receiving from server: " + ioe.getMessage()); // close the socket
   } catch (Exception ea) {
    System.err.println("Unknown exception " + ea.getMessage());
    return "-3";
   }
   return XMLString;
 }
}
 
Thanks,
-C

Three thing:
 
1) You're missing authentication.. (basic authentication header)
2) Content type is wrong.. nedds to be application/x-www-form-urlencoded
3) Content(XMLString) needs to be prepended by xml=
 
Check com\cisco\ipphone\sdk\EMProvider in the Cisco Ip Phone Services SDK for a working sample.

Thanks Stephan, I didn't realize this was already something that was part of the IPPhones SDK.
 
I just recreated the wheel!...woohoo!
 
-C

thanks ...
i was digging with that problem ,too.It returned 500 internal server error while using samples in normal way....
founding cisco's soap syntax is harder than founding a treasure....
there are no clear samples in sdk of emapi
 

Collateral


No files available