Access to MQMD descriptor in Java Compute Node - Websphere

This is a discussion on Access to MQMD descriptor in Java Compute Node - Websphere ; How to read and reset MQMD input and output message header using Java Message Broker API? Thanks!...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Access to MQMD descriptor in Java Compute Node

  1. Access to MQMD descriptor in Java Compute Node

    How to read and reset MQMD input and output message header using Java Message Broker API?

    Thanks!

  2. Re: Access to MQMD descriptor in Java Compute Node

    I am not sure if you want to actually use the Java API in the
    JavaCompute node to access the MQMD or if you want to use XPath.

    The Java API has been around for years....it is the API that is used to
    write custom nodes in Java. Basically you navigate around the message
    tree using a collection of Java methods that positions you at a
    particular node in the message tree and then operate on that node with
    further method invocations. The MQMD is always the second child of
    Root (if it is an MQ message) so it is never a problem to position at
    that node in the tree. You then just process its children. These
    methods are detailed in the JavaDoc for the product. There is also info
    in the Help and there is a pdf on writting custom nodes that could be
    referenced as well.

    Using XPath to address and manipulate the MQMD does have one little
    quirk that needs to be understood....this actually applies to any
    portion of the message tree that is prior to Body. This results from
    the fact that to XPath Root is the head of the XML document. But in a
    message tree Root is further up the tree than that. As a result you
    MUST use relative path addressing to access or manipulate the MQMD,
    Propertires folder or any other node that is prior to Body in the
    message tree.

    So for XPath you would first position at the Root element of the message
    my using a Java API method then you would code a relative XPath
    expression that addressed the MQMD and whatever element in it you wanted
    to access or manipulate ....msg.getRootElement().evaluateXPath("MQMD/....");

    esadmin wrote:

    >How to read and reset MQMD input and output message header using Java Message Broker API?
    >
    >Thanks!
    >
    >


  3. Re: Access to MQMD descriptor in Java Compute Node

    Thanks!

    Now I would like to receive the text value of MsgId parameter.
    Which type is need for correct type casting?

    Code:
    ....
    MbElement mbInElement = inMessage.getRootElement();
    mbInElement = (MbElement)((List)mbInElement.evaluateXPath("MQMD/MsgId")).get(0);
    System.out.println("Result = " + mbInElement.getName() + " = " + mbInElement.getValue().toString());

    Result:
    ....
    Result = MsgId = [B@19480cdd




  4. Re: Access to MQMD descriptor in Java Compute Node

    The correct casting of MsgId or CorrelId value is right when i use byte array.

    MbElement mbInElement = inMessage.getRootElement();
    mbInElement = (MbElement)((List)mbInElement.evaluateXPath("MQMD/MsgId")).get(0);
    System.out.println("Result = " + mbInElement.getName() + " = " + new String((byte[])mbInElement.getValue()));

  5. Re: Access to MQMD descriptor in Java Compute Node

    esadmin wrote:
    > The correct casting of MsgId or CorrelId value is right when i use byte array.
    >
    > MbElement mbInElement = inMessage.getRootElement();
    > mbInElement = (MbElement)((List)mbInElement.evaluateXPath("MQMD/MsgId")).get(0);
    > System.out.println("Result = " + mbInElement.getName() + " = " + new String((byte[])mbInElement.getValue()));



    Or you could simply do:
    String id =
    message.getRootElement().evaluateXPath("string(MQMD/MsgId)").toString();



    Regards,
    Mårten


+ Reply to Thread