Skip to Content

HCI synchronous split

Hi guys,

I am quite new to HCI and am trying the following scenario:
I have a synchronous REST / JSON call from the sender which contains a structure as follows:

{
"messages" : {
"postId": ["1", "2", "3"]
}
}

Now I would like to split the incomming message by postId and make a call to
https://jsonplaceholder.typicode.com/posts/{postId} for each provided postId. These are all synchronous GET calls which provide back a JSON content such as:

{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et \nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

In the synchronous response to the sender I would like to collect all response messages and provide them back as a combined JSON to the sender.

I have tried the following:

HTTPS Sender -> JSON to XML converter -> General Splitter by xpath //postId -> content modifier which writes //postId to a header variable -> XML to JSON converter -> HTTPS receiver channel which uses the header variable from postId for making the call on receiver side.

What I am getting back in the synchronous response is the XML conversion of my request data, for example:

<?xml version='1.0' encoding='UTF-8'?><messages><postId>1</postId><postId>2</postId><postId>3</postId></messages>

Could you give me a hint what I am doing wrong or how my scenario would be achievable?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Aug 10, 2017 at 06:13 AM

    Hi Peter,

    You can try this:

    Main Integration Process:

    HTTPS Sender -> Start -> JSON to XML converter -> Process Call to Local Integration Process (Right-click and select looping process - Then configure looping condition) -> XML to JSON converter -> End Message

    Local Integration Process:

    Request-Reply step to the receiver -> Content-Modifier

    Regards,

    Prasanna

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Prasanna,

      Thank you for your reply! I have tried your solution but for me it fails within the call of the looping process with the message:

      org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: org.w3c.dom.Document with value [Body is not logged] due org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog., cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.

      I have only added one content modifier into the local integration process in order to take the //postId from Xpath and store it into the header variable postId in order to retrieve it in the request-reply channel for the dynamic URL.

      I did not use a second content modifier in the local integration process. Would I need to do so in order to append all the responses into the body before they will run through the XML to JSON converter? Could this cause the error above?

      This is the process model:

      Any hints would be appreciated!

  • Aug 18, 2017 at 05:38 AM

    Hello Peter,

    Few cents from my side,below might help you.

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Peter,

      Issue is not with your splitter, as per my observation its happening after your request reply.

      I think output of your http://jsonplaceholder.typicode.com/posts/${header.postId} call is is format JSON.

      You might need to convert from JSON to XML before Gathering ( if you want to use incoming format = XML (Same Format) ) or you can use plain text ( might need to write a script to perform transformation post gather ) which might be bit complex from transformation perspective.

      Regards,

      Sriprasad Shivaram Bhat

  • Aug 10, 2017 at 05:36 AM

    Hi Peter,

    Could you post the image of your iflow and also these kind of scenarios require request- reply and join- gather patterns after splitter.

    Regards,

    Chandan

    Add comment
    10|10000 characters needed characters exceeded