The Oracle Integration Cloud services have the capability to expose HTTP REST endpoint, which clients can consume to pull/push data. Once the request is successful, the HTTP REST endpoint sends the successful HTTP response code (200 or 202). There are cases where another HTTP code is also required like 400 (Bad Request), 404 (Not found), etc..

See the complete list of HTTP error code here
In this article, we will demonstrate how to send different HTTP response codes in case of success/failure.

Below will be the use case which we’ll execute as part of this article:

  • Expose the REST endpoint which will take “Id” as a request parameter
  • Get the employee record based on the passed value of “Id” parameter from the database
  • If record found, send the HTTP response code “200 OK” along with the response
  • If “Id” parameter/value is missing then sends the HTTP response code “400 Bad Request
  • If employee record is not found send the HTTP response code “404 Not Found

Let’s execute the use case:

  • Create an Orchestration process in Integration Cloud Service with name “HTTP_Error_Code
  • Drop a REST adapter as a Trigger Endpoint, configure the below properties and click the Next button
    • What do you want to call your endpoint: GetEmpRecord
    • What is the endpoint’s relative resource URI?: /get
    • What action does this endpoint perform: GET
    • Check the checkbox Add and review parameters for this endpoint
    • Check the checkbox Configure this endpoint to receive the response
  • Add a new parameter with the name “id” of type integer and click the Next button
  • Select JSON Sample and then click the <<< inline >>> link, then enter below sample json
{
    “FirstName”: “Ankur”,
    “LastName”: “Jain”
}
  • Finish the wizard
  • Drop Switch activity just below the mapper and edit the condition to check if id!=” as shown in the below screenshot
  • In otherwise block, drop the “Fault Return” activity and click on “edit” icon of the mapper
  • Hard code the values as below:
    • APIInvocatoinError-> errorCode: 400
    • APIInvocatoinError-> errorDetails->errorPath: Missing mandatory parameter(id)
    • APIInvocatoinError-> errorDetails-> errorCode: 400
  • Drop DB adapter under If condition and configure the wizard. Enter below details and click the Next button
    • What do you want to call your endpoint: GetEmp
    • What operation do you want to perform: Run a SQL statement
  • Enter below query, click Validate SQL Query button and click the Next button
select * from EMP_TABLE where id=#X_ID
  • Edit the GetEmp mapper and map id-> X_ID
  • Drop switch activity and edit the 1st condition
  • Enter below expression and close
    • count($GetEmp/GetEmpOutputCollection/GetEmpOutput)>=1
  • Drop the map activity under If condition and map below fields:
    • FIRSTNAME-> FirstName
    • LASTNAME-> LastName
  • Drop the “Fault Return” activity under otherwise and click the “edit” icon of the mapper
  • Hard code the values as below:
    • APIInvocatoinError-> errorCode: 404
    • APIInvocatoinError-> errorDetails->errorPath: Record not found
    • APIInvocatoinError-> errorDetails-> errorCode: 404

The integration is completed now. It’s time to test the integration.

We’ll use the POSTMAN to test the API.

Test-1: Hit the API with valid id and see the response code would be 200

Test-2: Hit the API with invalid id and see the response code would be 404


Test-3: Hit the API without passing “id” and see the response code would be 400