In one of my previous tutorials, I explained step by step how to create a RESTful service using TIBCO Rest & JSON Plugin with XML as input and output for the service method. In this tutorial, I will explain step by step how to Develop JSON REST service using TIBCO REST and JSON Plugin. This service will receive input as JSON and will return same data in XML format as an output.
Step 1: Develop Inbound Process for REST Service with REST Dispatch and Reply activity
We will first define a HTTP Connection to receive requests at a local host on port 9696. HTTP Connection resource is configured as shown below:
This connection will serve as transport for our service inbound process. Create a process with HTTP Receiver as process starter and use the above connection as transport in the configuration of HTTP Receiver. Since we are going to use POST method, no parameter is required
Next we will use Rest Dispatch and Reply activity. At the service level, specify the base URL. Host and Port will be same as we have in HTTP Connection that we used in HTTP Receiver.
Next, we need to add a Resource under service. Right click on service and choose Add–>Resource. At the resource level, in the Resource Path give the path as addemployee/
Since we are dealing with POST scenario here, we don’t need any Parameters to be defined at Resource or method level. So we don’t add any parameters at Parameters section.
Now right click at the Resource and choose Add–>Method. I named this method as add. For Method name choose POST from drop down list. For Process Name, we need to browse and choose the Process which has actual implementation of our business logic. For this example case, I have a process with the name AddEmployee which I have selected as shown below:
The core implementation process AddEmployee is kept very simple for this tutorial. We are just receiving JSON String as an input, we Parse JSON and then send XML data as an output from the process as you can see below:
To convert JSON to XML in the Parse JSON activity output editor tab, I have specified complex element corresponding to the JSON structure as shown below:
Please note that for above process, both Start and End activity have one parameter each with the name req and resp (both are String).
Once you have selected the implementation process, the next important task is to Bind the input and output. Click on the Bind and then map the HTTP POST data to the input. Similarly, output of End activity from the implementation process should be mapped to ASCII Content for HTTP Response as shown below:
We also need to add request and response for our method by right clicking on add method and choosing request and response one by one. Since we want to have JSON data as input to our service, make sure that you check JSON checkbox for the request for representations option.
This completes development part for our REST service. Validate the project to make sure everything is fine before we move to the next step of testing.
Step 2: Test JSON Based TIBCO REST Service
Load the RestDispatcher process in designer tester and then use any JSON Client to hit the service. I am using SOAP-UI REST feature to invoke this REST Service. For our implementation, sample input JSON data to be sent is as shown below:
{
“EMP_ID”: “22”,
“EMP_NAME”: “Ajmal Abbasi”,
“EMP_AGE”: “30”
}
As you can see in below screenshot, we have successfully invoked our REST service with JSON data as input and we have received back response in XML format as desired:
Feel free to comment if you face any problem and need any further clarification.
Hi Ajmal,
I tried to follow this tutorial, but when I try to sent http request it seem like PostData was empty.
I’ve already make sure that the method I used is POST.
here are HTTP Receiver output:
POST
/employee
HTTP/1.1
/employee
POST /employee HTTP/1.1accept: application/xml
content-type: application/json
user-agent: Jersey/2.25.1 (HttpUrlConnection 1.8.0_181)
host: localhost:8280
connection: keep-alive
content-length: 102
HTTP
8280
application/xml
application/json
102
keep-alive
127.0.0.1
Could you help me?!
Thank you.
How did you resolve your issue?
If you are using BW 5.14 you need to install hotfix1
I am using Tibco 5.11 and getting the same error .
POST
/
HTTP/1.1
/
POST / HTTP/1.1host: localhost:8056
connection: keep-alive
content-length: 43
sec-fetch-dest: empty
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36
content-type: application/json
accept: */*
origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
sec-fetch-site: none
sec-fetch-mode: cors
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
HTTP
8056
I am getting below error when I have executed above application .
BW-RESTJSON-3000001 Job-1 Error in [BusinessProcess/Process Definition.process/REST Dispatch and Reply]
Internal Server error occurred: java.lang.NullPointerException
I think that is something wrong with that tutorial (missing some precious information).
I tried all the steps and the post data it is always empty.
Can you please could be more specific please?
Dear Ana,
Nothing is missing as It worked fine for me. Try again and make sure you don’t miss any steps. If you have any issues at any particular step, feel free to comment and I will get back to you.
Hi Ajmal,
We created using the steps provided by you and we were able to do that without any issues but when we tried to export the Swagger then no input / Output fields were shown in that file, so when we provided the Swagger file to the client they were unable to understand what input to be send and what they will receive as an output. Since we created the process, we gave the sample request & response using which they were able to test our processes.
My question here, Is this correct to provide such swagger file without input & output parameter NOT displayed in it? And providing the sample request & response is the only way to inform client the structure of input & output?
Hi Ajmal,
I’m using TIBCO 514, how can we use mutual certs to invoke REST API from TIBCO. Any support is greatly appreciated , thanks
Dear Hp,
You will need to provide your public certificate to the other party and crate identity for your private key. Also you will need to import other party’s public certificate chain in your project (or in a folder referred using global variable BW_GLOBAL_TRUSTED_CA_STORE
Hi Ajmal , I am working on an existing Rest service as a aprt of my project . (receiving and sending JSON request)
Looks like , response header is text/html for me .
Hence , the JSON content is visible under raw/html section is SOAP UI but not under JSON.
is there any way we can change the response header?
the response is in JSON format . but because of the header “text/html” as content type , its not visible under the JSON section. It is sort of urgent .
Thanks in advance for your reply