cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
243
Views
0
Helpful
0
Comments
cdnadmin
Level 11
Level 11
This document was generated from CDN thread

Created by: Chase Casanova on 26-02-2010 07:20:43 PM
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

Subject: RE: java class to submit XML to EMServiceServlet
Replied by: Stephan Steiner on 01-03-2010 03:26:37 PM
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.

Subject: RE: java class to submit XML to EMServiceServlet
Replied by: Chase Casanova on 01-03-2010 05:06:41 PM
Thanks Stephan, I didn't realize this was already something that was part of the IPPhones SDK.
 
I just recreated the wheel!...woohoo!
 
-C

Subject: RE: java class to submit XML to EMServiceServlet
Replied by: dan dan on 16-03-2010 08:31:39 AM
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
 
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:

Quick Links