Have Logs Will Travel

by Alex Durzy on October 15, 2009 · 0 comments

This post only applies to Legacy Version 3 of the API

Using a web service is a little bit like a leap of faith.  You no longer have total control of the code and are depending on the service to perform a chunk of your work flow.  The benefits are obvious, in that you don’t have to develop or maintainLogging that code.  The downside is that when something does go wrong, it’s tempting to blame the web service provider. However, this is not always the case and in the event that something does go wrong, you need a way to determine where the failure was. One way is to use a SOAP testing tool as we’ve seen in Washing with SOAP part 1, 2, 3.  This is a quick way to verify that the web service is doing what it’s supposed to.  But if you need to debug your code, then you will need a way to output the SOAP requests and responses that you are sending and receiving.  This will also be valuable information to show to the provider of the web service you are consuming. So, let’s look at how to do this in a few different languages.

PHP Logging Example

PHP(version 5+) gives you easy access to the last request and response through the SOAP Client object.  The functions __getLastRequest() and __getLastResponse() will return a string representation of the last request and response.  You can either echo this string to standard output, as with the very simple file logger class in this example, or more than likely in your production code you will be logging it to a file.  Get the code

Python Logging Example

If you’re using the Suds SOAP library for Python, you can enable logging through Python’s own logging library.  You won’t need to directly access the request and response strings. You can also control how much information you receive by setting the logging level. Additionally, the library allows adding a file handler to pipe the output to a log file.  Pretty convenient, right?  Get the code

Java Logging Example

With Java, using the JAX-WS SOAP stack, things get slightly more complicated.  If you worked through accessing the SOAP header through the use of a SOAP message handler, then you’ll be familiar with the process here.  What we’ll be doing is writing a handler whose purpose is to intercept requests and responses, log them, and then pass them along to the next handler. Here you will find the handler code, as well as the code to associate it to the binding.  Again, this is for use with Java’s JAX-WS library.  If you’re using Apache Axis or some other SOAP library, you will likely have alternate methods to log SOAP messages.  Get the code

While some languages are easier than others in terms of logging SOAP messages, you should always write your code with the idea that at some point, something may go wrong. When something does go wrong, you’ll need a way to investigate what happened.  Without being able to see the SOAP messages that your application and the Bronto API are passing back and forth, you will have a much harder time debugging your code.  So with these examples in hand, go forth and log those SOAP messages.

Alex Durzy
Support Engineer at Bronto

Related posts:

  1. Washing With SOAP: Part 1 This post only applies to Legacy Version 3 of the...
  2. Washing With SOAP: Part 2 This post only applies to Legacy Version 3 of the...
  3. Washing With SOAP: Part 3 This post only applies to Legacy Version 3 of...

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: