Skip to Content
2

HCI synchronous split

Aug 09, 2017 at 08:50 AM

629

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

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

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

Show 1 Share
10 |10000 characters needed characters left 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!

0
Sriprasad Shivaram Bhat
Aug 18, 2017 at 05:38 AM
1

Hello Peter,

Few cents from my side,below might help you.

Regards,

Sriprasad Shivaram Bhat


Show 3 Share
10 |10000 characters needed characters left characters exceeded

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?

0

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

0
Former Member

Hi Peter,

Not sure why your splitter step is failing.

I tried these steps and it worked.

splitter1.jpg (70.6 kB)
splitter2.jpg (32.6 kB)
splitter1.jpg (70.6 kB)
splitter3.jpg (32.6 kB)
0
Hemachandan A S Aug 10, 2017 at 05:36 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded