<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>java class to submit XML to EMServiceServlet</title>
  <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=2000795" />
  <subtitle>java class to submit XML to EMServiceServlet</subtitle>
  <id>http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=2000795</id>
  <updated>2013-05-23T14:19:40Z</updated>
  <dc:date>2013-05-23T14:19:40Z</dc:date>
  <entry>
    <title>RE: java class to submit XML to EMServiceServlet</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2043058" />
    <author>
      <name>dan dan</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2043058</id>
    <updated>2010-03-16T13:31:39Z</updated>
    <published>2010-03-16T13:31:39Z</published>
    <summary type="html">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
 </summary>
    <dc:creator>dan dan</dc:creator>
    <dc:date>2010-03-16T13:31:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: java class to submit XML to EMServiceServlet</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2006152" />
    <author>
      <name>Chase Casanova</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2006152</id>
    <updated>2010-03-01T23:06:41Z</updated>
    <published>2010-03-01T23:06:41Z</published>
    <summary type="html">Thanks Stephan, I didn't realize this was already something that was part of the IPPhones SDK.
 
I just recreated the wheel!...woohoo!
 
-C</summary>
    <dc:creator>Chase Casanova</dc:creator>
    <dc:date>2010-03-01T23:06:41Z</dc:date>
  </entry>
  <entry>
    <title>RE: java class to submit XML to EMServiceServlet</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2005795" />
    <author>
      <name>Stephan Steiner</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2005795</id>
    <updated>2010-03-01T21:26:37Z</updated>
    <published>2010-03-01T21:26:37Z</published>
    <summary type="html">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.</summary>
    <dc:creator>Stephan Steiner</dc:creator>
    <dc:date>2010-03-01T21:26:37Z</dc:date>
  </entry>
  <entry>
    <title>java class to submit XML to EMServiceServlet</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2000794" />
    <author>
      <name>Chase Casanova</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=2000794</id>
    <updated>2010-02-27T01:20:43Z</updated>
    <published>2010-02-27T01:20:43Z</published>
    <summary type="html">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 = "&lt;request&gt;";
 XMLString += "&lt;appInfo&gt;";
 XMLString += "&lt;appID&gt;" + appID + "&lt;/appID&gt;";
 XMLString += "&lt;appCertificate&gt;" + appPasswd + "&lt;/appCertificate&gt;";
 XMLString += "&lt;/appInfo&gt;";
 XMLString += "&lt;login&gt;";
 XMLString += "&lt;deviceName&gt;" + phoneName + "&lt;/deviceName&gt;";
 XMLString += "&lt;userID&gt;" + userid + "&lt;/userID&gt;";
 XMLString += "&lt;exclusiveDuration&gt;";
 XMLString += "&lt;time&gt;60&lt;/time&gt;";
 XMLString += "&lt;/exclusiveDuration&gt;";
 XMLString += "&lt;/login&gt;";
 XMLString += "&lt;/request&gt;";
 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</summary>
    <dc:creator>Chase Casanova</dc:creator>
    <dc:date>2010-02-27T01:20:43Z</dc:date>
  </entry>
</feed>

