Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

UCCX - Consuming Web Services

Hi All,

I am looking for some advice in regards to consuming web services via UCCX scripting. In the past i have been doing so successfully in our environment by using document steps and Xpath expressions for both SOAP and REST web services that were configured to allow an HTTP GET request (tomcat running on apache server to expose public methods written in Java).

Our company is in the midst of a Microsoft Dynamics 2012 (r2)  implementation and I have the task of establishing communication with AX in order to pass information back and forth. Our consultants with dynamics have setup a test web service using AIF, but it seems that these services require authentication. Currently the test web service is using NTLM authentication and exposed via SOAP. Apparently it is not possible to use HTTP GET for these web services.

This means i had to write java code in Set steps to communicate with the SOAP services. I was able to successfully do this for some of our own web services using SOAP. however i am having problems with the AX test web service due to the authentication. (Thanks to Gergely Szabo, as i used some of his code found here: https://supportforums.cisco.com/document/97736/uccx-8x-really-simple-soap-client-no-custom-jar )

I am hoping someone has some experience with having consumed AIF web services via Java or at least Java written within a UCCX script. Or if someone has been able to implement authentication and can provide some details for how that works? I don't even know if i can authenticate via NTLM from UCCX scripts due to it being a windows authentication protocol and not linux based.

 

Any thoughts or ideas would be appreciated!

Thanks,

Kevin.

  • Contact Center
1 ACCEPTED SOLUTION

Accepted Solutions

Hi,can you please try the

Hi,

can you please try the above code block in the set step without these additional lines:

  urlCon.setRequestProperty("SOAPAction","http://tempuri.org/myService/getSiteId");
  urlCon.setRequestProperty("Host", "myServer.myDomain.com:8080");
  urlCon.setRequestProperty("Connection","Keep-Alive");
  urlCon.setRequestProperty("User-Agent","Java/1.6.0_29");
  urlCon.setRequestProperty("Accept-Encoding","gzip,deflate");

I am afraid these might sort of confuse the web server.

Also, remove the exception catching mechanism (by commenting out the lines that start with try { ; catch {  and the } where the comment says  try..catch block ends here. You should be able to get the stack trace and hopefully the line in the Java code that generates the exception.

G.

7 REPLIES

Hi,can you tell me the type

Hi,

can you tell me the type of the authentication? Is it simple HTTP Basic Auth or something more sophisticated?

If by "NTLM" you mean Integrated Windows Authentication then it's a problem. UCCX is not Windows so a different method must be used.

Thanks.

G.

New Member

Hi Gergely, Yes, it is using

Hi Gergely,

 

Yes, it is using NTLM by authenticating through windows AD. I believe there are several authentication methods available though, and believe HTTP Basic Auth is one of them.

I will check with the consultants to see what other choices we may be able to test out. I'd prefer no authentication at all, but i do not think that is even an option.

Do you happen to have any example code for working with the basic auth? By the way I am using your java code for the soapResponseString found in your document here (https://supportforums.cisco.com/document/97736/uccx-8x-really-simple-soap-client-no-custom-jar) Great information and instructions!

I wrote something a bit different to generate the soapRequest xml, but they seem to work well together so far.

New Member

This code snippet here may be

This code snippet here may be all i need and seems simple enough. I will do some more testing tomorrow and find out what the different authentication methods are.

http://www.avajava.com/tutorials/lessons/how-do-i-connect-to-a-url-using-basic-authentication.html

 

String webPage = "http://192.168.1.1";

String name = "admin";

String password = "admin";

String authString = name + ":" + password;

byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());

String authStringEnc = new String(authEncBytes);

URL url = new URL(webPage);

URLConnection urlConnection = url.openConnection();

urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);

New Member

Hi, Thus far I have been

Hi,

 

Thus far I have been unsuccessful in my attempts to communicate with this particular web service. The consults did create another service using Basic HTTP Auth and I was able to consume and use the service using SOAPUI just fine.

However, my soapResponseString code (small tweak of Gergely's code) is not working. After 2-3 minutes of sitting on that step in the CRS Editor my stacktrace exception is thrown and shows "Connection timed out". This is way past the time for the 5000ms read timeout, so I imagine the initial communication is successful but then eventually times out due to not returning a response?

I tried to mimic the headers SOAPUI uses from it's HTTP Log, hence the number of urlCon.setRequestProperty lines..

 

CODE for Set soapResponseString below:

 

{

// create a ByteArrayOutputStream - this is actually a buffer
// we are going to use to store the response coming from the SOAP server
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

// this is quite unnecessary: assigning the value of the soapRequest (still holding our XML document)
// to another variable, named content, type String; but anyway, it's just cleaner
String content = soapRequest;

// specify a timeout - 5000 milliseconds - if the web server does not start sending back
// anything within this timeframe, an exception will be raised
int readTimeout = 5000;


try {

  
// a new URL, which is the soapServiceEndpoint variable value (http://ip:port/ etc):
     java.net.URL url = new java.net.URL(soapServiceEndpoint);

// creating a HTTP connection to the above URL:
     java.net.HttpURLConnection urlCon = (java.net.HttpURLConnection) url.openConnection();

// setting some important header parameters, first of all, content length, this is most likely expected
// by the SOAP server
     urlCon.setFixedLengthStreamingMode(content.length());

// setting the timeout:
     urlCon.setReadTimeout(readTimeout);

// we tell Java we will do input (in other words, we will read):
     urlCon.setDoInput (true);

// we tell Java we will do output (in other words, we will send):
     urlCon.setDoOutput (true);

// we tell Java not to cache:
     urlCon.setUseCaches (false);

// we are using HTTP POST
     urlCon.setRequestMethod("POST");

// finally, we set the Content-Type header,
// this way we are telling the SOAP server we are sending an XML, using the UTF-8 charset
     urlCon.setRequestProperty("Content-Type","text/xml;charset=UTF-8");
 
// here we are sending our Basic Auth - authStringEnc is a base64 encoded user:pass credential that's initialized in a previous step
  urlCon.setRequestProperty("Authorization","Basic " + authStringEnc);
 
//set some other header information for the request required by the AIF Web Service 
  urlCon.setRequestProperty("SOAPAction","http://tempuri.org/myService/getSiteId");
  urlCon.setRequestProperty("Host", "myServer.myDomain.com:8080");
  urlCon.setRequestProperty("Connection","Keep-Alive");
  urlCon.setRequestProperty("User-Agent","Java/1.6.0_29");
  urlCon.setRequestProperty("Accept-Encoding","gzip,deflate");
 
 
// opening an OutputStream (this is a one-way channel towards the SOAP server:
     java.io.DataOutputStream output = new java.io.DataOutputStream(urlCon.getOutputStream());

// we write the contents of the content variable (= soapRequest = XML document):
     output.writeBytes(content);

// telling Java to flush "speed up!" and then close the stream:
     output.flush();
     output.close();

// now getting the InputStream (getting a one way channel coming from the SOAP server):
     java.io.DataInputStream input = new java.io.DataInputStream(urlCon.getInputStream());

// buffered read from the InputStream, buffer size 4Kilobytes (= 4096 bytes):
// and the buffer is always written to the other buffer, named baos, that we specified
// on the first line of this block of code

     int bufSize = 4096; // buffer size, bytes
     byte[] bytesRead = new byte[bufSize];
     int bytesReadLength = 0;

     while(( bytesReadLength = input.read( bytesRead )) > 0 ) {

         baos.write(bytesRead,0,bytesReadLength);

     } //while block ends here

// closing the InputStream:
     input.close();

// closing the baos buffer
     baos.close();

} catch (Exception e) {

// again, if an error occurs, let's just send the stack trace to stdout (stdout.log)
// and then return null or can we can return e.getMessage() to see the exception caught inside the script

    e.printStackTrace();
 return e.getMessage();
    //return null;

} // try..catch block ends here

// construct a new String, and return that to the CRS script:
return new String(baos.toByteArray());

} // closure ends here

 

Hi,can you please try the

Hi,

can you please try the above code block in the set step without these additional lines:

  urlCon.setRequestProperty("SOAPAction","http://tempuri.org/myService/getSiteId");
  urlCon.setRequestProperty("Host", "myServer.myDomain.com:8080");
  urlCon.setRequestProperty("Connection","Keep-Alive");
  urlCon.setRequestProperty("User-Agent","Java/1.6.0_29");
  urlCon.setRequestProperty("Accept-Encoding","gzip,deflate");

I am afraid these might sort of confuse the web server.

Also, remove the exception catching mechanism (by commenting out the lines that start with try { ; catch {  and the } where the comment says  try..catch block ends here. You should be able to get the stack trace and hopefully the line in the Java code that generates the exception.

G.

New Member

Thanks for the assistance

Thanks for the assistance Gergely.

I was able to remove the last 3 requestProperties for Connection, User-Agent, and Accept-Encoding in order to get it working. Removing the SOAPAction and Host properties caused an HTTP 500 response.

so this worked great for setting the correct requestProperty content:

urlCon.setRequestProperty("Authorization","Basic " + authStringEnc);

urlCon.setRequestProperty("SOAPAction","http://tempuri.org/myService/getSiteId");
  urlCon.setRequestProperty("Host", "myServer.myDomain.com:8080");

Hi,glad to hear it worked and

Hi,

glad to hear it worked and thanks for the rating.

Just curious: can you tell me why you needed to specify the Host: in your HTTP request? Is it a server referenced by multiple domains?

G.
 

469
Views
0
Helpful
7
Replies
This widget could not be displayed.