Skip to Content
0

Receive JSON with an OData link, parse JSON and call that received OData

May 11, 2017 at 09:50 AM

230

avatar image

Currently I have a requirement, I'll try to detail it as much as possible, first what I need and below that my current attempts

1. An external system is suscribed to an URL (This URL is my HTTP Sender in HCI) so, every time that someone makes a modification into some master data, the action will trigger and the subscription will call the URL that I provided and will send a JSON content very similar to this one:

[{
	"businessObject": "Example",
	"businessObjectId": "00163E0918ED1ED5A8EFE211DAAEBA55",
	"odataServiceEndPoint": "https://external.system.com/odata/v1/c4coda ta/OpportunityCollection(00163E0918ED1ED5A8EFE211DAAEBA55)"
}]

As you can see under odataServiceEndPoint there's a valid OData link.

2. I need to parse that JSON, get the OData link and make a call to it.

3. After doing that, I need to send the info from this OData to another external system (This one is not that complicated, the problem I have is with step 1 and 2)

So far I have created the iFlow and it looks like this:

Under the sender, I have set the HTTP so it will listen to the calls, but besides that, I can't find a way to know if that sender is in fact receiving the JSON or not.

Also, you'll see that I have configured an Email Receiver, in my attempt to send the content of the Sender via email so I can visualize it, that didn't work either (I'm having some trouble with gmail and their logon security).

But either way, I need to have a configured receiver, otherwise the endpoint url for the Sender is not reachable (Calling manually the service will return 404 error).

Any suggestions? Is there anyway to make another HTTP receiver and return a JSON or an HTML message in the response?

I would like to have this at least to know if the communication or some of my actions are being or not executed, you know to at least have feedback from the service.

Thanks in advance!

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

4 Answers

Sanjali Salian May 11, 2017 at 02:06 PM
2

Hi Melvin,

Firstly you would need to resolve your gmail logon security error so that we have an end to end working,
https://blogs.sap.com/2016/09/29/connect-gmail-from-hci/

Or you could also enable tracing for your IFlow if you just need to see the header and payload processing,
https://blogs.sap.com/2016/04/29/monitoring-your-integration-flows/

To get the 'odataServiceEndPoint' value one option is to convert the request from JSON to XML using the Converter and in a content modifier use XPath,

The other bit is a question whether the URL being passed in 'odataServiceEndPoint' is always same with different Id or the whole URL will be different each time i.e. endpoint to a completely different system?

Kind Regards
Sanjali


Share
10 |10000 characters needed characters left characters exceeded
Sriprasad Shivaram Bhat May 11, 2017 at 04:21 PM
1

Hello Melvin,

Below might help you.

Scenario In detail:

Step2:

Write a script which will set incoming JSON url to the External Calls url.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*


def Message processData(Message message) {
    
    //Get Body 
    def body = message.getBody(String.class);
    def jsonSlurper = new JsonSlurper()
    def list = jsonSlurper.parseText(body)
    def val=list[0].odataServiceEndPoint.toString()
    message.setHeader("CamelHttpUri",val);
    return message;
}

Screenshot from POSTMAN:

I think you can cross check the HTTP Url which you are using in your POSTMAN.

https://answers.sap.com/questions/44799/http-adapter-without-endpoint-hci.html

Hope it helps with your steps 1 and 2 problems.

Regards,

Sriprasad Shivaram Bhat


Share
10 |10000 characters needed characters left characters exceeded
Melvin Hidalgo May 15, 2017 at 07:35 AM
0

Thanks for the help guys, however when making the example of parsing the JSON using code I'm getting the following error:

An internal server error occured: java.lang.NullPointerException: Cannot get property 'odataServiceEndPoint' on null object@ line 49 in script.groovy.

Now, this brings me another question, how can I set up parameters to then populate fields in other process steps?


Example,

def Message processData(Messagemessage){//Get Body 
def body =message.getBody(String.class);
def jsonSlurper =new JsonSlurper()
def list= jsonSlurper.parseText(body)
def val=list[0].odataServiceEndPoint.toString()

//Here a header is being populated in the CamelHttpUri.
message.setHeader("CamelHttpUri",val);


//Can I do something like this?

message.setProperty("HappyURL", "www.google.com")
returnmessage;

}

And then use this Happy URL in a subject or content of an email?

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

Hi Melvin,


Regarding the error you are getting could it be that you are not passing an array anymore, if so you would have to retrieve the value directly in your script,

def val=list.odataServiceEndPoint.toString();

Your script is correct to set the property, you can also simple use a content modifier for this,

Then you can retrieve this value when sending the email,

Kind Regards,
Sanjali

0
Sriprasad Shivaram Bhat May 15, 2017 at 10:32 AM
0

Hello Melwin,

Please check the JSON message which you are sending to your IFlow.

Above code was written to parse the data for the sample data you have shared only.

[{
        "businessObject": "Example",
        "businessObjectId": "00163E0918ED1ED5A8EFE211DAAEBA55",
        "odataServiceEndPoint": "https://external.system.com/odata/v1/c4coda ta/OpportunityCollection(00163E0918ED1ED5A8EFE211DAAEBA55)"
    }
]

If any changes to that field or structure need to be accommodated accordingly.

You can enable the trace to find out incoming JSON message to your IFlow.

Regards,

Sriprasad Shivaram Bhat

Share
10 |10000 characters needed characters left characters exceeded