0

Working with IBM MobileFirst 8.0 platform, I'm exploring the option of calling a Java adapter endpoint from other Java adapter endpoint.

The example that IBM explains (here) is pretty simple and works fine for a GET method. It is, simplifying, as follows:

String otherAdapterUrlendPoint = "/otherAdapter/endpoint?param="+param;
HttpUriRequest req = new HttpGet(otherAdapterUrlendPoint);
HttpResponse response = adaptersAPI.executeAdapterRequest(req);

Question here is what happens with a POST method (or PUT or DELETE)? I have not found any documentation, neither examples. I though it could be like this:

HttpPost httpPost = new HttpPost(otherAdapterUrlendPoint);
...
<<do something with httpPost object>>
...
HttpUriRequest req = httpPost;
HttpResponse response = adaptersAPI.executeAdapterRequest(req);

but I'm not sure about how to add the json body to this request... (about headers I guess I can use method httpPost.addHeader(name, value) );

Could anybody help me with this doubt? I'm pretty sure it is not an IBM MobileFirst topic, but a Java topic...

Thanks in advance!

Alex_ES
  • 205
  • 2
  • 15

1 Answers1

1

I found the solution to my problem. As I suspected, it was not a IBM MobileFirst topic, but a Java topic.

Solution is described here: HTTP POST using JSON in Java

basically I did as follows:

StringEntity postingString = new StringEntity(<<myStringObjectAsJson>>);

String url = "/HTTPJavaAdapter/endPoint";
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(postingString);
httpPost.setHeader("Content-type", "application/json");

HttpUriRequest req = httpPost;
adaptersAPI.executeAdapterRequest(req);
Alex_ES
  • 205
  • 2
  • 15