« Back to IP Phone Services Questions

Simple JSP Push To Phone Example

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hi,
 
I am trying to write a JSP based application that will push messages to the phone.
 
I can push a message to a phone from a HTML form but it prompts me to authenticate and provide a CUCM user and password.
 
How do I set this programatically?
 
I also need to be able to handle the response from the phone, i.e. Success or error, etc.
 
Has anyone got a simple JSP example that does this?
 
Many thanks
 
Tom

The IP Phone Services SDK has a JSP sample for Push2Phone.  Unfortunately some of the helper classes haven't been updated to work with CM5+.  The trick in your case is to add the Authorization header for basic auth:
 
------------------
 
    String pushAuth = Text2Base64.getBase64(pushUserId + ":" + pushPassword);
    String pushXML = "<CiscoIPPhoneExecute>";
    for (int i = 0; i < uris.length; i++) {
      pushXML = pushXML + "<ExecuteItem Priority=\"0\" URL=\"" +
          uris + "\"/>";
    }
    pushXML = pushXML + "</CiscoIPPhoneExecute>";
 
    StringBuffer response = new StringBuffer();
    try {
      String httpData = "XML=" + URLEncoder.encode(pushXML);
      System.out.println("xml="+httpData);
      URL url = new URL("http://" + phoneIP + "/CGI/Execute");
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setDoInput(true);
      conn.setDoOutput(true);
      conn.setRequestMethod("POST");
      conn.setFollowRedirects(getResult);
      conn.setRequestProperty("Content-type",
                              "application/x-www-form-urlencoded");
      conn.setRequestProperty("Authorization", "Basic " + pushAuth);
      PrintWriter pout = new PrintWriter(new OutputStreamWriter(conn.
          getOutputStream()), true);
      pout.print(httpData);
      pout.flush();