Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers

Igor Androsov -- webMethods Ezine Columnist

Exception Handling with Integration Server



By Igor Androsov

 


Using Flow-based Try-Catch Blocks

Another technique for handling Flow exceptions is to create a Try-Catch block.

The technique for creating Try-Catch blocks in Flow is as follows:

SEQUENCE (EXIT on SUCCESS), Label: MAIN
  SEQUENCE (EXIT in FAILURE), Label: TRY
    Try block Flow goes here
  SEQUENCE (EXIT on DONE), Label: CATCH
    Catch block Flow goes here

When dealing with special binary objects such as JDBC Connection objects or JMS session objects, though, you must take special precautions. Even though invoking pub.flow:getLastError restores the pipeline as it was when the exception was thrown, binary objects are unrecoverable.

To prevent the trashing of a connection and session object, create it before the Try block, if possible. This is an example using JDBC database connectivity.

Create JDBC database connection here
SEQUENCE (EXIT on SUCCESS), Label: MAIN
  SEQUENCE (EXIT in FAILURE), Label: TRY
    SQL statements
    commit changes
  SEQUENCE (EXIT on DONE), Label: CATCH
    pub.flow:getLastError
    Error Handling code
    Rollback all changes to the database


Saving Data on the IS Session

Another way of preserving a special binary object is to do it in the user's session with the Integration Server.

When saving an object in the user's IS session, the object will remain valid until the session destroyed. To accomplish this task, use the Java service ErrorHandler.util:put_object_in_session in this article's accompanying package. ErrorHandler.util:ErrorHandler.util:put_object_in_session saves the binary object to an IS session from which it can be later retrieved. The service source code is below:

import com.wm.app.b2b.server.Session;
import com.wm.app.b2b.server.ServerAPI;

Object obj = in.get("object");
String strObjectName = in.getString("objectName");
Session session = Service.getSession();

// Data type
Object tobj = session.get(strObjectName);
if (tobj != null)
    session.remove(strObjectName);

session.put(strObjectName, obj);

To retrieve the object from the user IS session, use the Java service ErrorHandler.util:get_object_from_session, also included in the package. The service source code is below:

  String strObjectName = in.getString("objectName");
  Session session = Service.getSession();
  out.put("object", session.get(strObjectName));

Now, let's put it all together. Here is an example Flow structure to implement putObjectInSession and getObjectFromSession:

Create JDBC connection here
Save JDBC connection object to user's IS session
SEQUENCE (EXIT on SUCCESS), Label: MAIN
  SEQUENCE (EXIT in FAILURE), Label: TRY
    SQL statements
    commit changes
  SEQUENCE (EXIT on DONE), Label: CATCH
    pub.flow:getLastError
    Error Handling code
    Get connection object from user's IS session
    Rollback all changes to the database


Retrofitting for Exception Handling

The most useful piece of data in an error is the name of the service from which the error was thrown.

If you are including building a new integration that uses Error Handling, pub.flow:getLastError is a reliable service for finding the exception-throwing service -- just look at the output field error/service. But, when implementing Error Handling procedures on production code, making edits to working Flow may not be an option. There is a workaround for this situation.

For retrofitting production code, make use of the accompanying package's service ErrorHandler.util:get_service_name. This service examines the complete call stack thrown by the exception event and identifies which service was called immediately before the Error Handling service. It is not a perfect solution, but it is minimally intrusive to production environments (and it works!).

The source code for ErrorHandler.util:get_service_name is below:

IDataHashCursor curs = pipeline.getHashCursor();
String caller = "SVC - ";
try
{
  Thread t = Thread.currentThread();
  com.wm.app.b2b.server.ServerThread st =
        (com.wm.app.b2b.server.ServerThread)t;
  java.util.Stack stack =
        st.getState().getCallStack();
  for (int i = 0; i < stack.size(); i++)
  {
    if (i < stack.size() - 1)
    {
      caller += stack.elementAt(i).toString();
      caller += " ";
    }
  }
}
catch (Exception e)
{
  caller = new String("non-determinable");
}
curs.last();
curs.insertAfter("serviceName", caller);


Conclusion

Strong error handling plays an important part in developing robust, failure-resistant systems. I hope that this article adds clarity to webMethods Integration Server exception handling logic.



<<Prev  1  [2]  

Go Deeper on the Subject: The wMUsers Discussion Forums


Igor Androsov has over 14 years of experience in the IT Industry. For last 5 years he has been a software mercenary specializing in Integration process and technology using wide array of languages and platforms: C/C++, Java UNIX, LINUX, OS/2 and Windows. Igor started working with webMethods in 1998 as a new Integration tool implementing a B2B Exchange. He has implemented large distributed systems for multiple Fortune 500 enterprises.

Igor can be reached via email at


Advertise at wMUsers






  Home | Join wMUsers | Discussion Forums | Knowledge Center | Jobs | Shareware | User Groups | Links |
Contact Us | Terms of Service | Privacy Policy

wMUsers is an independent organization and is not sponsored in any manner by Software AG.


© All Rights Reserved, 2001-2008.