cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
822
Views
0
Helpful
6
Replies

CRS 5.0.1 scripting - HTTP Error management

SebastianV
Level 1
Level 1

Greetings,

I am scripting against a web service (on another server). To create a script as robust as possible, I'd like to implement some error handling. What is the best way to handle errors regarding unavailability of the web service (e.g. error 503)?

I have looked at the On Exception Goto step but am unsure if it would be a good solution to the problem.

The XML document I need to retrieve and the data that needs to be extracted pose no problem, I just want to be able to route calls based upon availability of the web server providing the XML data.

1 Accepted Solution

Accepted Solutions

Hi,

I see. Then you don't really need to watch a specific HTTP response code, only two states:

1. web server down, so I/O exception occurs (no response from web server within the specified timeout),

2. web server malfunctions so no valid XML served (so actually the web server responds, but instead of serving a valid XML document, it sends some error message in plaintext or HTML).

Both can be handled by the built in exception handling mechanisms. Actually they throw a DocumentIOException.

So all you have to do is to insert an On Exception Step, select the "com.cisco.doc.DocumentIOException" from the list, and then specify the label of a step that should be executed if any of the above conditions occur. Don't forget to clear the exception.

The first step is the On Exception step

The second and third simulate a document (actually located on the IVR server) which is not a valid XML.

The third and the fourth step simulate a network timeout (this can be set in the Create URL Document step, but the Cache document step is the one actually trying to connect to the web server).

Good luck.

G.

View solution in original post

6 Replies 6

Gergely Szabo
VIP Alumni
VIP Alumni

Hi,

I am not aware of any built-in exception handling mechanism for that, but if you are not afraid of coding in Java, then you can do this in a closure. No custom JAR necessary.

1. create a java.net.HttpURLConnection to the URL of your choice

2. get its OutputStream, send all the headers and data necessary, then flush and close the stream,

3. get its InputStream, read the response, and return the response as String or Stream, the latter is better because it can be cast simply into a Document (and then you can use the standard Get XML Document Data step.

If you place the whole block of code into a try..catch closure, then you can of course catch all the exceptions and react on them easily.

If you are interested in specific HTTP response codes, you can use

yourUrlCon.getResponseCode() where yourUrlCon is of course the java.net.HttpURLConnection object.

G.

Hello Gergely,

Thank you for your suggestion. Unfortunately, I don't know the first thing about Java. It might be to big an adventure to go there. Would you happen to have an example you could share?

Hi,

that's no problem, but can you just be more specific about that web service you want to talk to? Is it SOAP? Or is it just some XML? Or JSON? Does it expect GET or POST parameters?

G.

Hi,

The webserver provides an XML document stating what status the application is in.

What I have so far:

document_XML_01 = Create URL Document(string_URL_01)

document_XML_01 = Create XML Document(string_URL_01)

string_RESULT_01 = Get XML Document Data(document_XML_01,"//Child/Node")

If(string_RESULT_01 == "blah")

True

False

Etc

If the webserver is up & running, there are no problems and this works a treat. If the server is down or the XML is not being served, I need to process in my script with alternative routing. So I am looking for a solution to catch a timeout and a solution to continue based on the HTTP error code(s).

Hi,

I see. Then you don't really need to watch a specific HTTP response code, only two states:

1. web server down, so I/O exception occurs (no response from web server within the specified timeout),

2. web server malfunctions so no valid XML served (so actually the web server responds, but instead of serving a valid XML document, it sends some error message in plaintext or HTML).

Both can be handled by the built in exception handling mechanisms. Actually they throw a DocumentIOException.

So all you have to do is to insert an On Exception Step, select the "com.cisco.doc.DocumentIOException" from the list, and then specify the label of a step that should be executed if any of the above conditions occur. Don't forget to clear the exception.

The first step is the On Exception step

The second and third simulate a document (actually located on the IVR server) which is not a valid XML.

The third and the fourth step simulate a network timeout (this can be set in the Create URL Document step, but the Cache document step is the one actually trying to connect to the web server).

Good luck.

G.

Thank you for the clarification of this issue, it was extremely helpful.

It now works as I intended and all bases are covered regardless of the webservers's status.

Thanks again for your time!