cancel
Showing results for 
Search instead for 
Did you mean: 

HCI synchronous split

former_member198060
Participant

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?

Accepted Solutions (0)

Answers (3)

Answers (3)

Sriprasadsbhat
Active Contributor

Hello Peter,

Few cents from my side,below might help you.

Regards,

Sriprasad Shivaram Bhat

former_member198060
Participant
0 Kudos

Hi Sriprasad,

Thank you for your response and sorry for the late reaction from my side (was on vacation).
I have tried your solution but I am receiving an exception in my splitter.

So from sender side I am using https and the JSON to XML converter looks to work fine, this is the XML it is generating:

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

Now in the general splitter I am using:

Expression Type = XPath
Xpath Expression = /messages/message
Grouping = 1
Streaming and Stop on Exception checked

According to the log the splitter step is failing with the message

com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog..

In the payload log I have set after the splitter I can see only the first message:

<?xml version="1.0" encoding="UTF-8"?>
<messages>
  <message>
    <postId>1</postId>
  </message>
</messages>
<br>

In the content modifier after the splitter I am doing the following:

Create postId with Type = Xpath, data type = java.lang.String, Value = //postId

In the Request reply CC I am using a GET call to

http://jsonplaceholder.typicode.com/posts/${header.postId} without Authentication.

Finally, in the Gather I have set incoming format = XML (Same Format) and Aggregation Algorithim = Combine.

Any idea what is wrong with my iFlow?

Former Member
0 Kudos

Hi Peter,

Not sure why your splitter step is failing.

I tried these steps and it worked.

Sriprasadsbhat
Active Contributor
0 Kudos

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

Former Member

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

former_member198060
Participant
0 Kudos

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!

former_member198979
Participant
0 Kudos

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