Howto:SOAP API Java Sample Code: Difference between revisions

From innovaphone wiki
Jump to navigation Jump to search
(New page: {{FIXME|reason=TODO: work in progress }} ==Applies To== This information applies to * any innovaphone PBX platform * Java Runtime Environment innovaphone PBX web services can be used fr...)
 
mNo edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{FIXME|reason=TODO: work in progress }}
{{3rd_Party_Input}}
 
==Applies To==
==Applies To==
This information applies to
This information applies to
Line 16: Line 15:


===Running Sample Code===
===Running Sample Code===
This code is a simple Java console application. It will run on your OS console terminal. As dependencies, you will need JDK to compile the code and JRE to execute it.
To '''compile''', save the code on file '''innoSOAP.java''' and provide that file as parameter to '''javac''' command.
*The below code was compiled on javac version 1.8.0 and run on java version 1.8.0 (It was not tested on other versions)
*You may get a warning regarding the function sun.misc.BASE64Encoder().encode() because it is deprecated. Nevertheless the code will run. You may remove that section of the code (used just for authentication on the PBX) but you will have to allow "public" access to /PBX0/user.soap on HTTP(security risk!!!).




Line 31: Line 36:


public class innoSOAP {
public class innoSOAP {
/*
    /*
The example below demonstrates the use of SOAP integration to innovaphone PBX.
        The example below demonstrates the use of SOAP integration to innovaphone PBX.
   
Reference to innovaphone SOAP integration can be found on:
        Reference to innovaphone SOAP integration can be found on:
http://wiki.innovaphone.com/index.php?title=Reference:SOAP_API
        http://wiki.innovaphone.com/index.php?title=Reference:SOAP_API


INSTRUCTIONS:
        INSTRUCTIONS:
Modify the global variables below according to your specific system.
        Modify the global variables below according to your specific system.
       
The program will perform the following tasks:
        The program will perform the following tasks:
1 - Send a SOAP message with the instruction "Initialize" and grab the session ID.
        1 - Send a SOAP message with the instruction "Initialize" and grab the session ID.
2 - Referencing the session ID it will send a SOAP message with the instruction "UserInitialize" and grab the user ID.
        2 - Referencing the session ID it will send a SOAP message with the instruction "UserInitialize" and grab the user ID.
3 - Loop on an SOAP instruction "Poll" to keep looking for information on the user CNUSER (refer to global variables below)
        3 - Loop on an SOAP instruction "Poll" to keep looking for information on the user CNUSER (refer to global variables below)
User information and Call information.
            User information and Call information.
(The Poll call remains opened until information is provided or time out. In case of timeout PBX sends an emtpy response
        (The Poll call remains opened until information is provided or time out. In case of timeout PBX sends an emtpy response
and then another Poll call takes place)
        and then another Poll call takes place)
       
Created by:
        Created by:
Francisco Paletta
        Francisco Paletta
       
Version: 0.1
        Version: 0.2
*/
    */
   
   
//innovaphone general information
    //innovaphone general information
private static final String MYNAMESPACE = "pbx";
    private static final String MYNAMESPACE = "pbx";
     private static final String MYNAMESPACEURI = "http://www.innovaphone.com/pbx";
     private static final String MYNAMESPACEURI = "http://www.innovaphone.com/pbx";
   
//specific system information
    //specific system information
private static final String SOAPACTION = "";
    private static final String SOAPACTION = "";
     private static final String SOAPENDPOINTURL = "http://192.168.0.1/PBX0/user.soap";
     private static final String SOAPENDPOINTURL = "http://192.168.0.1/PBX0/user.soap";
private static final String ADMSOAPUSER = "admin"; //PBX admin user
    private static final String ADMSOAPUSER = "admin"; //PBX admin user
     private static final String ADMSOAPUSERPWD = "ip311"; //PBX admin password
     private static final String ADMSOAPUSERPWD = "ip311"; //PBX admin password
private static final String SOAPUSER = "SOAP"; //SOAP user object in PBX with group access to other objects
    private static final String SOAPUSER = "SOAP"; //SOAP user object in PBX with group access to other objects
private static final String CNUSER = "User 1"; //CN of user to perform Poll on
    private static final String CNUSER = "User 1"; //CN of user to perform Poll on


     // Main function
     // Main function
Line 71: Line 76:
         callSoapWebService(SOAPENDPOINTURL, SOAPACTION);
         callSoapWebService(SOAPENDPOINTURL, SOAPACTION);
     }
     }
   
//Prints all nodes on the nodelist
    //Prints all nodes on the nodelist
private static void nodeListPrint(NodeList list, String tab){
    private static void nodeListPrint(NodeList list, String tab){
NodeList childList;
        NodeList childList;      
for (int i = 0; i < list.getLength(); i++) {
        for (int i = 0; i < list.getLength(); i++) {
if(!list.item(i).getNodeName().equals("#text")) {
            System.out.print(tab+String.valueOf(list.item(i).getNodeName()));
System.out.println("");
            childList = list.item(i).getChildNodes();
System.out.print(tab+String.valueOf(list.item(i).getNodeName()));
            if(childList.getLength() != 0) {
}
                if(!childList.item(0).getNodeName().equals("#text")) {
childList = list.item(i).getChildNodes();
                    System.out.println("");
if(childList.getLength() == 0) {
                    nodeListPrint(childList, tab+"  ");
System.out.print(" -> ");
                }
System.out.print(String.valueOf(list.item(i).getTextContent()));
                else {
} else {
                    System.out.print(" -> ");
nodeListPrint(childList, tab+" ");
                    System.out.println(String.valueOf(childList.item(0).getTextContent()));
}  
                }               
}  
            } else {
}
                System.out.println("");
            }
        }  
    }


//Starts web connection and execute the SOAP calls
    //Starts web connection and execute the SOAP calls
     private static void callSoapWebService(String soapEndpointUrl, String soapAction) {
     private static void callSoapWebService(String soapEndpointUrl, String soapAction) {
         try {
         try {
           
String session="";
            String session="";
String user="";
            String user="";
           
             // Create SOAP Connection
             // Create SOAP Connection
             SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
             SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
             SOAPConnection soapConnection = soapConnectionFactory.createConnection();
             SOAPConnection soapConnection = soapConnectionFactory.createConnection();
           


             // Send SOAP Message to SOAP Server
             // Send SOAP Message to SOAP Server
Line 109: Line 117:
             System.out.println("\n");
             System.out.println("\n");


SOAPBody body = soapResponse.getSOAPBody();
            SOAPBody body = soapResponse.getSOAPBody();
NodeList returnList = body.getElementsByTagName("InitializeResponse");
            NodeList returnList = body.getElementsByTagName("InitializeResponse");
           
System.out.print("Response Parsed:");
            System.out.println("Response Parsed:");
nodeListPrint(returnList,"");
            nodeListPrint(returnList,"");
System.out.println("\n");
            System.out.println("");
           
for (int k = 0; k < returnList.getLength(); k++) {
            for (int k = 0; k < returnList.getLength(); k++) {
NodeList innerResultList = returnList.item(k).getChildNodes();
                NodeList innerResultList = returnList.item(k).getChildNodes();
for (int l = 0; l < innerResultList.getLength(); l++) {
                for (int l = 0; l < innerResultList.getLength(); l++) {
if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
                    if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
session = String.valueOf(innerResultList.item(l).getTextContent().trim());
                        session = String.valueOf(innerResultList.item(l).getTextContent().trim());
}
                        }
}
                }
        }
            }


    soapResponse = soapConnection.call(createSOAPRequest_UserInitialize(soapAction, session), soapEndpointUrl);
            soapResponse = soapConnection.call(createSOAPRequest_UserInitialize(soapAction, session), soapEndpointUrl);


             // Print the SOAP Response
             // Print the SOAP Response
             System.out.println("Response SOAP Message:");
             System.out.println("Response SOAP Message:");
             soapResponse.writeTo(System.out);
             soapResponse.writeTo(System.out);
System.out.println("\n");
            System.out.println("\n");
           
body = soapResponse.getSOAPBody();
            body = soapResponse.getSOAPBody();
returnList = body.getElementsByTagName("UserInitializeResponse");
            returnList = body.getElementsByTagName("UserInitializeResponse");
           
System.out.print("Response Parsed:");
            System.out.println("Response Parsed:");
nodeListPrint(returnList,"");
            nodeListPrint(returnList,"");
System.out.println("\n");
            System.out.println("");
           
for (int k = 0; k < returnList.getLength(); k++) {
            for (int k = 0; k < returnList.getLength(); k++) {
NodeList innerResultList = returnList.item(k).getChildNodes();
                NodeList innerResultList = returnList.item(k).getChildNodes();
for (int l = 0; l < innerResultList.getLength(); l++) {
                for (int l = 0; l < innerResultList.getLength(); l++) {
if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
                    if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
user = String.valueOf(innerResultList.item(l).getTextContent().trim());
                        user = String.valueOf(innerResultList.item(l).getTextContent().trim());
}
                        }
}
                }
        }
            }


boolean returnValue = true;
            boolean returnValue = true;
while(returnValue){
            while(returnValue){
soapResponse = soapConnection.call(createSOAPRequest_Poll(soapAction, session), soapEndpointUrl);
                soapResponse = soapConnection.call(createSOAPRequest_Poll(soapAction, session), soapEndpointUrl);
//The call for Poll remains opened until PBX sends a response. In case of timeout PBX sends an empty response.
                //The call for Poll remains opened until PBX sends a response. In case of timeout PBX sends an empty response.
//The loop will guarantee another Poll call is send to keep "channel" running.
                //The loop will guarantee another Poll call is send to keep "channel" running.
               
// Print the SOAP Response
                // Print the SOAP Response
System.out.println("Response SOAP Message:");
                System.out.println("Response SOAP Message:");
            soapResponse.writeTo(System.out);
                soapResponse.writeTo(System.out);
System.out.println("\n");
                System.out.println("\n");


body = soapResponse.getSOAPBody();
                body = soapResponse.getSOAPBody();
returnList = body.getElementsByTagName("PollResponse");
                returnList = body.getElementsByTagName("PollResponse");
System.out.print("Response Parsed:");
                System.out.println("Response Parsed:");
nodeListPrint(returnList,"");
                nodeListPrint(returnList,"");
System.out.println("\n");
                System.out.println("");
}
            }


             soapConnection.close();
             soapConnection.close();
Line 173: Line 181:
     }
     }


//Creates a SOAPmessage with the "Initialize" instruction
    //Creates a SOAPmessage with the "Initialize" instruction
     private static SOAPMessage createSOAPRequest_Initialize(String soapAction) throws Exception {
     private static SOAPMessage createSOAPRequest_Initialize(String soapAction) throws Exception {
         MessageFactory messageFactory = MessageFactory.newInstance();
         MessageFactory messageFactory = MessageFactory.newInstance();
         SOAPMessage soapMessage = messageFactory.createMessage();
         SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPPart soapPart = soapMessage.getSOAPPart();
       
         // SOAP Envelope
         // SOAP Envelope
         SOAPEnvelope envelope = soapPart.getEnvelope();
         SOAPEnvelope envelope = soapPart.getEnvelope();
Line 188: Line 196:
         SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("user");
         SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("user");
         soapBodyElem1.addTextNode(SOAPUSER);
         soapBodyElem1.addTextNode(SOAPUSER);
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("appl");
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("appl");
         soapBodyElem2.addTextNode("JAVA SOAP CALL");
         soapBodyElem2.addTextNode("JAVA SOAP CALL");
SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("bool");
        SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("bool");
         soapBodyElem3.addTextNode("true");
         soapBodyElem3.addTextNode("true");
SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("v501");
        SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("v501");
         soapBodyElem4.addTextNode("true");
         soapBodyElem4.addTextNode("true");
SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("v700");
        SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("v700");
         soapBodyElem5.addTextNode("true");
         soapBodyElem5.addTextNode("true");
SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("v800");
        SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("v800");
         soapBodyElem6.addTextNode("true");
         soapBodyElem6.addTextNode("true");
SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("vx1000");
        SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("vx1000");
         soapBodyElem7.addTextNode("true");
         soapBodyElem7.addTextNode("true");


Line 205: Line 213:
         headers.addHeader("SOAPAction", soapAction);
         headers.addHeader("SOAPAction", soapAction);


String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
        String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
headers.addHeader("Authorization", "Basic " + authorization);
        headers.addHeader("Authorization", "Basic " + authorization);


         soapMessage.saveChanges();
         soapMessage.saveChanges();
Line 213: Line 221:
         System.out.println("Request SOAP Message:");
         System.out.println("Request SOAP Message:");
         soapMessage.writeTo(System.out);
         soapMessage.writeTo(System.out);
System.out.println("\n");
        System.out.println("\n");


         return soapMessage;
         return soapMessage;
     }
     }
   
//Creates a SOAPmessage with the "UserInitialize" instruction
    //Creates a SOAPmessage with the "UserInitialize" instruction
private static SOAPMessage createSOAPRequest_UserInitialize(String soapAction, String session) throws Exception {
    private static SOAPMessage createSOAPRequest_UserInitialize(String soapAction, String session) throws Exception {
         MessageFactory messageFactory = MessageFactory.newInstance();
         MessageFactory messageFactory = MessageFactory.newInstance();
         SOAPMessage soapMessage = messageFactory.createMessage();
         SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPPart soapPart = soapMessage.getSOAPPart();
       
         // SOAP Envelope
         // SOAP Envelope
         SOAPEnvelope envelope = soapPart.getEnvelope();
         SOAPEnvelope envelope = soapPart.getEnvelope();
Line 233: Line 241:
         SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("session");
         SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("session");
         soapBodyElem1.addTextNode(session);
         soapBodyElem1.addTextNode(session);
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("user");
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("user");
         soapBodyElem2.addTextNode(CNUSER);
         soapBodyElem2.addTextNode(CNUSER);
SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("follow");
        SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("follow");
         soapBodyElem3.addTextNode("true");
         soapBodyElem3.addTextNode("true");


Line 242: Line 250:
         headers.addHeader("SOAPAction", soapAction);
         headers.addHeader("SOAPAction", soapAction);


String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
        String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
headers.addHeader("Authorization", "Basic " + authorization);
        headers.addHeader("Authorization", "Basic " + authorization);


         soapMessage.saveChanges();
         soapMessage.saveChanges();
Line 250: Line 258:
         System.out.println("Request SOAP Message:");
         System.out.println("Request SOAP Message:");
         soapMessage.writeTo(System.out);
         soapMessage.writeTo(System.out);
System.out.println("\n");
        System.out.println("\n");


         return soapMessage;
         return soapMessage;
     }
     }
   
//Creates a SOAPmessage with the "Poll" instruction
    //Creates a SOAPmessage with the "Poll" instruction
private static SOAPMessage createSOAPRequest_Poll(String soapAction, String session) throws Exception {
    private static SOAPMessage createSOAPRequest_Poll(String soapAction, String session) throws Exception {
         MessageFactory messageFactory = MessageFactory.newInstance();
         MessageFactory messageFactory = MessageFactory.newInstance();
         SOAPMessage soapMessage = messageFactory.createMessage();
         SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPPart soapPart = soapMessage.getSOAPPart();
       
         // SOAP Envelope
         // SOAP Envelope
         SOAPEnvelope envelope = soapPart.getEnvelope();
         SOAPEnvelope envelope = soapPart.getEnvelope();
Line 275: Line 283:
         headers.addHeader("SOAPAction", soapAction);
         headers.addHeader("SOAPAction", soapAction);


String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
        String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
headers.addHeader("Authorization", "Basic " + authorization);
        headers.addHeader("Authorization", "Basic " + authorization);


         soapMessage.saveChanges();
         soapMessage.saveChanges();
Line 283: Line 291:
         System.out.println("Request SOAP Message:");
         System.out.println("Request SOAP Message:");
         soapMessage.writeTo(System.out);
         soapMessage.writeTo(System.out);
System.out.println("\n");
        System.out.println("\n");


         return soapMessage;
         return soapMessage;
Line 289: Line 297:


}
}






</code>
</code>


== Known Problems ==
== Known Problems ==

Latest revision as of 09:06, 9 May 2018

3rd party input
this is 3rd party content not provided by innovaphone, see history for authors.

Applies To

This information applies to

  • any innovaphone PBX platform
  • Java Runtime Environment

innovaphone PBX web services can be used from Java Runtime Environment. Here is how


More Information

Configuration

Modify the global variables SOAPENDPOINTURL, ADMSOAPUSER, ADMSOAPUSERPWD, SOAPUSER and CNUSER according to your specific system.

Running Sample Code

This code is a simple Java console application. It will run on your OS console terminal. As dependencies, you will need JDK to compile the code and JRE to execute it.

To compile, save the code on file innoSOAP.java and provide that file as parameter to javac command.

  • The below code was compiled on javac version 1.8.0 and run on java version 1.8.0 (It was not tested on other versions)
  • You may get a warning regarding the function sun.misc.BASE64Encoder().encode() because it is deprecated. Nevertheless the code will run. You may remove that section of the code (used just for authentication on the PBX) but you will have to allow "public" access to /PBX0/user.soap on HTTP(security risk!!!).


The sample application

This section will discuss the sample code. It is not a decent description of the PBX SOAP API. For this, see the related articles.



import javax.xml.soap.*; import org.w3c.dom.NodeList;

public class innoSOAP {

   /*
       The example below demonstrates the use of SOAP integration to innovaphone PBX.
   
       Reference to innovaphone SOAP integration can be found on:
       http://wiki.innovaphone.com/index.php?title=Reference:SOAP_API
       INSTRUCTIONS:
       Modify the global variables below according to your specific system.
       
       The program will perform the following tasks:
       1 - Send a SOAP message with the instruction "Initialize" and grab the session ID.
       2 - Referencing the session ID it will send a SOAP message with the instruction "UserInitialize" and grab the user ID.
       3 - Loop on an SOAP instruction "Poll" to keep looking for information on the user CNUSER (refer to global variables below)
           User information and Call information.
       (The Poll call remains opened until information is provided or time out. In case of timeout PBX sends an emtpy response
        and then another Poll call takes place)
       
       Created by:
       Francisco Paletta
       
       Version: 0.2
   */
   
   
   //innovaphone general information
   private static final String MYNAMESPACE = "pbx";
   private static final String MYNAMESPACEURI = "http://www.innovaphone.com/pbx";
   
   //specific system information
   private static final String SOAPACTION = "";
   private static final String SOAPENDPOINTURL = "http://192.168.0.1/PBX0/user.soap";
   private static final String ADMSOAPUSER = "admin"; //PBX admin user
   private static final String ADMSOAPUSERPWD = "ip311"; //PBX admin password
   private static final String SOAPUSER = "SOAP"; //SOAP user object in PBX with group access to other objects
   private static final String CNUSER = "User 1"; //CN of user to perform Poll on
   // Main function
   public static void main(String args[]) {
       callSoapWebService(SOAPENDPOINTURL, SOAPACTION);
   }
   
   //Prints all nodes on the nodelist
   private static void nodeListPrint(NodeList list, String tab){
       NodeList childList;        
       for (int i = 0; i < list.getLength(); i++) {
           System.out.print(tab+String.valueOf(list.item(i).getNodeName()));
           childList = list.item(i).getChildNodes();
           if(childList.getLength() != 0) {
               if(!childList.item(0).getNodeName().equals("#text")) {
                   System.out.println("");
                   nodeListPrint(childList, tab+"  ");
               }
               else {
                   System.out.print(" -> ");
                   System.out.println(String.valueOf(childList.item(0).getTextContent()));
               }                
           } else {
               System.out.println("");
           }
       } 
   }
   //Starts web connection and execute the SOAP calls
   private static void callSoapWebService(String soapEndpointUrl, String soapAction) {
       try {
           
           String session="";
           String user="";
           
           // Create SOAP Connection
           SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
           SOAPConnection soapConnection = soapConnectionFactory.createConnection();
           
           // Send SOAP Message to SOAP Server
           SOAPMessage soapResponse = soapConnection.call(createSOAPRequest_Initialize(soapAction), soapEndpointUrl);
           // Print the SOAP Response
           System.out.println("Response SOAP Message:");
           soapResponse.writeTo(System.out);
           System.out.println("\n");
           SOAPBody body = soapResponse.getSOAPBody();
           NodeList returnList = body.getElementsByTagName("InitializeResponse");
           
           System.out.println("Response Parsed:");
           nodeListPrint(returnList,"");
           System.out.println("");
           
           for (int k = 0; k < returnList.getLength(); k++) {
               NodeList innerResultList = returnList.item(k).getChildNodes();
               for (int l = 0; l < innerResultList.getLength(); l++) {
                   if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
                       session = String.valueOf(innerResultList.item(l).getTextContent().trim());
                       }
               }
           }
           soapResponse = soapConnection.call(createSOAPRequest_UserInitialize(soapAction, session), soapEndpointUrl);
           // Print the SOAP Response
           System.out.println("Response SOAP Message:");
           soapResponse.writeTo(System.out);
           System.out.println("\n");
           
           body = soapResponse.getSOAPBody();
           returnList = body.getElementsByTagName("UserInitializeResponse");
           
           System.out.println("Response Parsed:");
           nodeListPrint(returnList,"");
           System.out.println("");
           
           for (int k = 0; k < returnList.getLength(); k++) {
               NodeList innerResultList = returnList.item(k).getChildNodes();
               for (int l = 0; l < innerResultList.getLength(); l++) {
                   if (innerResultList.item(l).getNodeName().equalsIgnoreCase("return")) {
                       user = String.valueOf(innerResultList.item(l).getTextContent().trim());
                       }
               }
           }
           boolean returnValue = true;
           while(returnValue){
               soapResponse = soapConnection.call(createSOAPRequest_Poll(soapAction, session), soapEndpointUrl);
               //The call for Poll remains opened until PBX sends a response. In case of timeout PBX sends an empty response.
               //The loop will guarantee another Poll call is send to keep "channel" running.
               
               // Print the SOAP Response
               System.out.println("Response SOAP Message:");
               soapResponse.writeTo(System.out);
               System.out.println("\n");
               body = soapResponse.getSOAPBody();
               returnList = body.getElementsByTagName("PollResponse");
               System.out.println("Response Parsed:");
               nodeListPrint(returnList,"");
               System.out.println("");
           }
           soapConnection.close();
       } catch (Exception e) {
           System.err.println("\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n");
           e.printStackTrace();
       }
   }
   //Creates a SOAPmessage with the "Initialize" instruction
   private static SOAPMessage createSOAPRequest_Initialize(String soapAction) throws Exception {
       MessageFactory messageFactory = MessageFactory.newInstance();
       SOAPMessage soapMessage = messageFactory.createMessage();
       SOAPPart soapPart = soapMessage.getSOAPPart();
       
       // SOAP Envelope
       SOAPEnvelope envelope = soapPart.getEnvelope();
       envelope.addNamespaceDeclaration(MYNAMESPACE, MYNAMESPACEURI);
       // SOAP Body
       SOAPBody soapBody = envelope.getBody();
       SOAPElement soapBodyElem = soapBody.addChildElement("Initialize");
       SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("user");
       soapBodyElem1.addTextNode(SOAPUSER);
       SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("appl");
       soapBodyElem2.addTextNode("JAVA SOAP CALL");
       SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("bool");
       soapBodyElem3.addTextNode("true");
       SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("v501");
       soapBodyElem4.addTextNode("true");
       SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("v700");
       soapBodyElem5.addTextNode("true");
       SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("v800");
       soapBodyElem6.addTextNode("true");
       SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("vx1000");
       soapBodyElem7.addTextNode("true");


       MimeHeaders headers = soapMessage.getMimeHeaders();
       headers.addHeader("SOAPAction", soapAction);
       String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
       headers.addHeader("Authorization", "Basic " + authorization);
       soapMessage.saveChanges();
       /* Print the request message, just for debugging purposes */
       System.out.println("Request SOAP Message:");
       soapMessage.writeTo(System.out);
       System.out.println("\n");
       return soapMessage;
   }
   
   //Creates a SOAPmessage with the "UserInitialize" instruction
   private static SOAPMessage createSOAPRequest_UserInitialize(String soapAction, String session) throws Exception {
       MessageFactory messageFactory = MessageFactory.newInstance();
       SOAPMessage soapMessage = messageFactory.createMessage();
       SOAPPart soapPart = soapMessage.getSOAPPart();
       
       // SOAP Envelope
       SOAPEnvelope envelope = soapPart.getEnvelope();
       envelope.addNamespaceDeclaration(MYNAMESPACE, MYNAMESPACEURI);
       // SOAP Body
       SOAPBody soapBody = envelope.getBody();
       SOAPElement soapBodyElem = soapBody.addChildElement("UserInitialize");
       SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("session");
       soapBodyElem1.addTextNode(session);
       SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("user");
       soapBodyElem2.addTextNode(CNUSER);
       SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("follow");
       soapBodyElem3.addTextNode("true");


       MimeHeaders headers = soapMessage.getMimeHeaders();
       headers.addHeader("SOAPAction", soapAction);
       String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
       headers.addHeader("Authorization", "Basic " + authorization);
       soapMessage.saveChanges();
       /* Print the request message, just for debugging purposes */
       System.out.println("Request SOAP Message:");
       soapMessage.writeTo(System.out);
       System.out.println("\n");
       return soapMessage;
   }
   
   //Creates a SOAPmessage with the "Poll" instruction
   private static SOAPMessage createSOAPRequest_Poll(String soapAction, String session) throws Exception {
       MessageFactory messageFactory = MessageFactory.newInstance();
       SOAPMessage soapMessage = messageFactory.createMessage();
       SOAPPart soapPart = soapMessage.getSOAPPart();
       
       // SOAP Envelope
       SOAPEnvelope envelope = soapPart.getEnvelope();
       envelope.addNamespaceDeclaration(MYNAMESPACE, MYNAMESPACEURI);
       // SOAP Body
       SOAPBody soapBody = envelope.getBody();
       SOAPElement soapBodyElem = soapBody.addChildElement("Poll");
       SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("session");
       soapBodyElem1.addTextNode(session);


       MimeHeaders headers = soapMessage.getMimeHeaders();
       headers.addHeader("SOAPAction", soapAction);
       String authorization = new sun.misc.BASE64Encoder().encode((ADMSOAPUSER+":"+ADMSOAPUSERPWD).getBytes());
       headers.addHeader("Authorization", "Basic " + authorization);
       soapMessage.saveChanges();
       /* Print the request message, just for debugging purposes */
       System.out.println("Request SOAP Message:");
       soapMessage.writeTo(System.out);
       System.out.println("\n");
       return soapMessage;
   }

}


Known Problems

Related Articles

Reference:SOAP API

Howto:PBX SOAP Api C-sharp sample code

Howto:SOAP with PHP5