Skip to Content

Body length of an HCI message

How can I get the body length of an HCI message? In my scenario I have a sender Mail adapter but this question can be also generic.

Basically, I need to route the message if its body length is smaller than a certain value. I tried with the expression ${body.length} (from Apache Camel Simple Expression Language) but it is not accepted in the router.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jan 18, 2017 at 01:16 PM

    I solved through a Groovy script:

    message.setHeader("bodyLength", body.length());

    and checking the value ${header.bodyLength} in the router condition. But I'm wondering if there is a way without the usage of the script.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 18, 2017 at 03:22 PM

    Hello Davide,

    ${in.body.length} will give you the desired output.Please follow below about the usage

    Add an Content Modifier and store the value in Property like below. In later stage call the Property like ${property.Body_Length}

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 20, 2017 at 01:13 PM

    Hi Sriprasad,

    I tried your suggestion but I get:

    org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: .length on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: length on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: length not found on bean: javax.mail.internet.MimeMultipart@49169724 of type: javax.mail.internet.MimeMultipart. Exchange[][MailMessage@0x508de809], cause: org.apache.camel.component.bean.MethodNotFoundException: Method with name: length not found on bean: javax.mail.internet.MimeMultipart@49169724 of type: javax.mail.internet.MimeMultipart. Exchange[][MailMessage@0x508de809]
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 20, 2017 at 01:17 PM

    Hello Davide

    Could you please share more details of your Iflow like which step you have before setting this property and in which step you are getting this error,

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded