org.osesb.messagepipeline.test.builtinstagesunittest
Class InsertMessageIDPipelineStage

java.lang.Object
  extended by org.osesb.messagepipeline.PipelineStage
      extended by org.osesb.messagepipeline.test.builtinstagesunittest.InsertMessageIDPipelineStage

public class InsertMessageIDPipelineStage
extends PipelineStage

InsertMessageIDPipelineStage extends PipelineStage in order to add a messageID attribute to the root element of a CD message.

The messageID is a UUID that is generated using classes in the org.osesb.utilities.uuid package.

Since:
Version .9

Field Summary
 
Fields inherited from class org.osesb.messagepipeline.PipelineStage
log, messagePipelineContext, nextStage, parentMessagePipeline, pipelineStageConfiguration, previousStage, thisClassName
 
Constructor Summary
InsertMessageIDPipelineStage(MessagePipeline parentMessagePipeline, PipelineStageConfiguration pipelineStageConfiguration)
          Creates a new instance of InsertMessageIDPipelineStage.
 
Method Summary
static void main(java.lang.String[] args)
          main() For testing and sandboxing.
 boolean runStage(EAIMessage eaiMessage)
          Run PipelineStage logic.
 
Methods inherited from class org.osesb.messagepipeline.PipelineStage
beingDroppedFromPool, commit, getMessagePipelineContext, getNextStage, getParentMessagePipeline, getPipelineStageConfiguration, getPreviousStage, handlePipelineException, handlePipelineException, logMessage, propagate, rollback, setNextStage, setOutputMessage, setPreviousStage, setResultMessage, stageProcessingComplete, stageProcessingStarting
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InsertMessageIDPipelineStage

public InsertMessageIDPipelineStage(MessagePipeline parentMessagePipeline,
                                    PipelineStageConfiguration pipelineStageConfiguration)
                             throws java.lang.Exception
Creates a new instance of InsertMessageIDPipelineStage.

Parameters:
parentMessagePipeline - The MessagePipeline that constructed this PipelineStage.
pipelineStageConfiguration - A PipelineStageConfiguration for this PipelineStage.
Throws:
java.lang.Exception - if constructed with a null parentMessagePipeline or a null pipelineStageConfiguration.
Method Detail

runStage

public boolean runStage(EAIMessage eaiMessage)
                 throws PipelineStageException
Run PipelineStage logic.

The runStage() method expects an IXMLMessage with XML text as the payload.

In this example a messageID is added as an attribute of the root element and the current MessagePipeline message is set to the transformed EAIXMLMessage using the setOutputMessage() method.

The messageID is a UUID that is generated using classes in the org.osesb.utilities.uuid package.

MessagePipeline invokes the runStage() method on each PipelineStage in the order they appear in the MessagePipelineConfiguration. More specifically, the MessagePipeline invokes the following PipelineStage methods:

  1. stageProcessingStarting(): The PipelineStage should allocate resources needed by runStage() in this method.
  2. runStage()(): Main PipelineStage logic. To propagate the results of runStage() to the next stage, a PipelineStage invokes setOutputMessage() and/or propagate() with the EAIMessage to be passed to the next stage. setOutputMessage() is usually one of the last statements in runStage(), but propagate() can be invoked at any point in the runStage() method. See setOutputMessage() and propagate().
  3. commit(): If a PipeleineStageException is not thrown, then commit() is invoked to commit outstanding transactions. The 'transactionScope' PipelineStageConfiguration property controls how the commit() and rollback() methods are invoked. See the getTransactionScope() method in PipelineStageConfiguration for details.
  4. rollback(): If a PipeleineStageException is thrown, then rollback() is invoked to rollback outstanding transactions. The 'transactionScope' PipelineStageConfiguration property controls how the commit() and rollback() methods are invoked. See the getTransactionScope() method in PipelineStageConfiguration for details.
  5. stageProcessingComplete(): PipelineStage should release resources in this method. The MessagePipeline invokes stageProcessingComplete() after all PipelineStage transactions are committed or rolled back.

If a PipelineStage's runStage() method returns false, then pipeline processing terminates with that stage and subsequent stages are not run. However, returning false does not indicate an error to the MessagePipeline. Returning false from runStage() indicates that pipeline processing completed normally before the end of the pipeline was reached.

If a PipelineStage's runStage() method returns true, then the MessagePipeline runs the next stage.

When pipeline processing ends normally, without throwing a PipelineStageException, the MessagePipeline will commit outstanding transactions beginning with the first PipelineStage. The 'transactionScope' PipelineStageConfiguration property controls how the commit() and rollback() PipelineStage methods are invoked. See the getTransactionScope() method in PipelineStageConfiguration for details around configuring 'transactionScope' for PipelineStages.

If a PipelineStage's runStage() method throws a PipelineStageException, then pipeline processing terminates with that stage and subsequent stages are not run.

When pipeline processing ends with a PipelineStageException, the MessagePipeline will roll back outstanding transactions beginning with the PipelineStage that threw the Exception. The 'transactionScope' PipelineStageConfiguration property controls how the commit() and rollback() PipelineStage methods are invoked. See the getTransactionScope() method in PipelineStageConfiguration for details around configuring 'transactionScope' for PipelineStages.

Overrides:
runStage in class PipelineStage
Parameters:
eaiMessage - The EAI message, which is the output of the last PipeLineStage that invoked setOutputMessage(), or, if this is the first PiplelineStage, then this is the EAIMessage that the MessagePipeline was invoked with.
Returns:
true to continue pipeline processing or false to terminate pipeline processing.
Throws:
a - PipelineStageException if any errors occur (including validation failures).
PipelineStageException

main

public static void main(java.lang.String[] args)
main() For testing and sandboxing.

Parameters:
args - commandline arguments