« Back to CVP - All Versions

Invoking a webservice using JAVA

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hi All,
 
I need help in developing an action element java class to be able to invoke an external web service.
can anyone pinpoint a guide or a link?
 
thanks in advance,

Hi All,
i have the same problem...any update regardin this issue ?
appriciate any support.

Hi Sherif,
 
I managed to invoke the webservice by using a java class that sends the soap message expected by the webservice.
 
here is an example:
 
import com.audium.server.AudiumException;
import com.audium.server.voiceElement.ActionElementBase;
import com.audium.server.session.ActionElementData;
import java.util.regex.*;
import java.net.*;
import java.io.*;
public class Authentication3 extends ActionElementBase
{
    public void doAction(String name, ActionElementData data) throws AudiumException
    {
            String type = "text/xml";
            String SOAPTOTAL = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://192.168.6.160/webservice1\">"
        + "<soapenv:Header/>"
         +"<soapenv:Body>"
            +"<web:FabienRose>"
               +"<web:Message1>test</web:Message1>"
            +"</web:FabienRose>"
         +"</soapenv:Body>"
      +"</soapenv:Envelope>";
                  System.out.println(SOAPTOTAL);
                  try {
                        URL url = new URL("http://192.168.6.160/webservice1/service1.asmx");
                        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                        conn.setRequestMethod("POST");
                        conn.setRequestProperty("content-Type",type);
                        conn.setUseCaches(false);
                        conn.setDoOutput(true);
                        conn.setDoInput(true);
                        DataOutputStream os = new DataOutputStream(conn.getOutputStream());
                       
                        os.writeBytes (SOAPTOTAL);
                        os.flush();
                        os.close();
                       
                        BufferedReader reader = new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
                        System.out.println("1");
                        String response = reader.readLine();
                        String result=response.substring( response.indexOf("<FabienRoseResult>") +"<FabienRoseResult>".length() , response.indexOf("</FabienRoseResult>"));
                        ElementData("Authentication_Status");
                        data.setElementData("Authentication_Status",result);
                       
                  }
                  catch (IOException e) {
                   data.addToLog("Problem connecting to Web Service Socket", ""+e);
            }
      }
 private void ElementData(String string) {
  // TODO Auto-generated method stub
  
 }
}
 
Fabien

Dear Fabien,
Thanks very much for your support but I have another question and asked this question many times on the forums but no one answer me.
I am using Call studio 7.0.2 and I am trying to use the web service element (my web service is deployed on oracle application server) the loading of the WSDL file is ok but once I tested the application and the element execute it I found a bad request error in the log¿
Any idea regarding this error and is am missing thing ? jars or what ever ?