Skip to content

Implement a "suspend based on content" component #5

@riha

Description

@riha

Could be something like the below.

The idea is to have a comp that could for example examine the content in a message and if a specific value exist, suspend it. Maybe could support regex?

A typical scenario is a web service that respond with 200 OK but has an error in the message.

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
           
            String value = null;
            bool suspend = false;

            IBaseMessagePart bodyPart = pInMsg.BodyPart;

           

            Stream inboundStream = bodyPart.GetOriginalDataStream();
            VirtualStream virtualStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);
            ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream);

            XmlTextReader xmlTextReader = new XmlTextReader(readOnlySeekableStream);
            XPathCollection xPathCollection = new XPathCollection();
            XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection);
            xPathCollection.Add(XPath);

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(0))
                {
                    if (xPathReader.NodeType == XmlNodeType.Attribute)
                    {
                        value = xPathReader.GetAttribute(xPathReader.Name);
                    }
                    else
                    {
                        value = xPathReader.ReadString();
                    }
 
                    break;
                }
            }

           
            suspend = ScriptExpressionHelper.ValidateExpression(value, Expression);

            if (suspend)
            {
              readOnlySeekableStream.Position = 0;
                pContext.ResourceTracker.AddResource(readOnlySeekableStream);
                bodyPart.Data = readOnlySeekableStream;
                pInMsg.Context.Write("SuspendAsNonResumable", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);
                pInMsg.Context.Write("SuppressRoutingFailureDiagnosticInfo", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);

                throw new Exception(String.Format("Expression {0} {1} did not evaluate to true", value, Expression));
            }
            else
            {
                pInMsg = null;
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions