OHI HTTP Library - Conversion Examples

Introduction

Release 4.25.1 introduces the OHI HTTP Library, which you can use to make HTTP requests in dynamic logic. This guide provides instructions on how to convert dynamic logic that utilizes the deprecated initCallOut and webTarget to the new OHI HTTP library, through the examples performing GET, POST, PUT, DELETE, and PATCH requests. You can use OHI HTTP Library in Callout Rule and other dynamic logic signatures.

Conversion Examples

Example 1: GET Request Replacing initCallOut

Deprecated Approach using initCallOut

String response = initCallOut(WebTarget.class)
    .path("enrollment")
    .queryParam("person", eligibilityCheck.person.code)
    .queryParam("requestDate", requestDate)
    .request("application/xml;responseDefinitionCode=type1")
    .buildGet()
    .invoke()
    .readEntity(String. class)

// As the response is XML we can "slurp" it
xml = new XmlSlurper().parseText(response)

New Approach using OHI HTTP Library

def paramsMap = [
    queryParams: [
        "person": eligibilityCheck.person.code,
        "requestDate": requestDate
    ],
    headers: ["Accept": "application/xml;responseDefinitionCode=type1"]
]

def response = ohiHttpRequest()
    .get("enrollment", paramsMap)

if (response.status == 200) {
    // As the response is XML we can "slurp" it
    xml = new XmlSlurper().parseText(response.body)
}
If ohiHttpRequest does not include any parameters, the system resolves the endpoint dynamically from the dynamic logic code in the current execution context. In non-OIG (Oracle Insurance Gateway) applications, Callout Rules can also be used to resolve the endpoint from the Callout Rule code. As a result, endpoint configuration is supported through both the dynamic logic code and the Callout Rule code.

Example 2: GET Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

def premiumScheduleURL = "premiumschedulelines/PS_TEST_001/defaulttimeperiod/2025-04-07"
def policyTarget = webTarget("POLICIES_API_DEST_CODE")
Response queryResponse = policyTarget
    .path("generic").path(premiumScheduleURL)
    .queryParam("limit", 200)
    .request()
    .accept("application/json;")
    .get()

if (queryResponse.status == 200) {
    def resourceObjects = new JsonSlurper().parseText(
        queryResponse.readEntity(String. class)
    )
    result.addAll(resourceObjects.items)
}

New Approach using OHI HTTP Library

def premiumScheduleURL = "premiumschedulelines/PS_TEST_001/defaulttimeperiod/2025-04-07"
def httpRequest = ohiHttpRequest("POLICIES_API_DEST_CODE")

def paramsMap = [
    queryParams: ["limit": "200"],
    headers: ["Accept": "application/json"]
]

def queryResponse = httpRequest.get("generic/" + premiumScheduleURL, paramsMap)

if (queryResponse.status == 200) {
    def resourceObjects = new JsonSlurper().parseText(queryResponse.body)
    result.addAll(resourceObjects.items)
}

Example 3: Another GET Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

String response = webTarget("destination_ecl_mockSync1")
    .path("eclipse").path("callout")
    .request()
    .header("Accept", "application/json")
    .buildGet()
    .invoke()
    .readEntity(String. class)

def resp = new JsonSlurper().parseText(response)

New Approach using OHI HTTP Library

def httpRequest = ohiHttpRequest("destination_ecl_mockSync1")
def paramsMap = [headers: ["Accept": "application/json"]]

def response = httpRequest.get("eclipse/callout", paramsMap)

if (response.status == 200) {
    def resp = new JsonSlurper().parseText(response.body)
}

Example 4: POST Request Replacing initCallOut

Deprecated Approach using initCallOut

def callout = initCallOut(WebTarget.class)

Object mdmResponse = callout.request("claims_target_api")
    .path("claims/search")
    .header("Accept", "application/json")
    .header("Content-Type", "application/json")
    .buildPost(Entity.json(jsonBuilder.toString()))
    .invoke()

if (mdmResponse.status() != 200 && mdmResponse.status() != 201) {
    mdmResponse.close()
    log.error(mdmResponse.toString())
    throw new RuntimeException("Unexpected response received")
    return
}

mdmResponse.close()

New Approach using OHI HTTP Library

def request = ohiHttpRequest("claims_target_api")

def paramsMap = [
    headers: [
        "Accept": "application/json",
        "Content-Type": "application/json"
    ],
    data: ["json": jsonBuilder.toString()]
]

def response = request.post("claims/search", paramsMap)

if (response.status != 200 && response.status != 201) {
    log.error(response.body)
    throw new RuntimeException("Unexpected response received")
    return
}

Example 5: POST Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

def xmlBody = <xml_payload_here>
Response applyCreditMemoResponse = webTarget("fusionFinApi_post_applyCredMemo")
    .request()
    .buildPost(new Entity(xmlBody.toString(), MediaType.TEXT_XML_TYPE)).invoke()

if (applyCreditMemoResponse.status() != 201) {
    log.error("Applying Credit Memo");
}

New Approach using OHI HTTP Library

def httpRequest = ohiHttpRequest("fusionFinApi_post_applyCredMemo")
def xmlBody = <xml_payload_here>
//Here the payload is processed using XML content-type,
//hence not required to add headers with content-type application/xml
def paramsMap = [data: ["xml": xmlBody.toString()]]

def applyCreditMemoResponse = httpRequest.post(paramsMap)
if (applyCreditMemoResponse.status != 201) {
    log.error("Applying Credit Memo");
}

Example 6: DELETE Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

def refSheetLineId = <reference_sheet_line_id>
def claimsTarget = webTarget(RestDestinationsConstants.CLAIMS_API_GET)

Response refSheetLinesResponse = claimsTarget.path("generic")
    .path("referencesheetlines")
    .path("reprocessARHGProviders")
    .path(String.valueOf(refSheetLineId))
    .request()
    .accept("application/json")
    .buildDelete().invoke()
}

New Approach using OHI HTTP Library

def refSheetLineId = <reference_sheet_line_id>
def httpRequest = ohiHttpRequest(RestDestinationsConstants.CLAIMS_API_GET)

def refSheetLinesResponse = httpRequest.delete(
    "generic/referencesheetlines/reprocessARHGProviders/"+ refSheetLineId
)

Example 7: PUT Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

def someDate = <some_date_value>
def existingProcedureGroup = <some_existing_procedure_group_object>
def procedureGroupDetailBuilder = new JsonBuilder()
procedureGroupDetailBuilder {
    endDate someDate
}
def claimsTarget = webTarget(RestDestinationsConstants.CLAIMS_API_GET)

Response procedureGroupDetailCreateResponse = claimsTarget.path("generic")
    .path("proceduregroupdetails")
    .path(existingProcedureGroup.id.toString())
    .request()
    .buildPut(Entity.json(procedureGroupDetailBuilder.toString()))
    .invoke()

New Approach using OHI HTTP Library

def someDate = <some_date_value>
def existingProcedureGroup = <some_existing_procedure_group_object>
def procedureGroupDetailBuilder = new JsonBuilder()
procedureGroupDetailBuilder {
    endDate someDate
}
def httpRequest = ohiHttpRequest(RestDestinationsConstants.CLAIMS_API_GET)

def paramsMap = [data: ["json": procedureGroupDetailBuilder.toString()]]

def procedureGroupDetailCreateResponse = httpRequest.put(
    "generic/proceduregroupdetails" + existingProcedureGroup.id.toString(),
    paramsMap
)

Example 8: PATCH Request Replacing webTarget (Applicable to OIG only)

Deprecated Approach using webTarget

def patchReqJson = <json_payload>
def response = webTarget("claims_api_get").path("generic").path("episodes")
    .request()
    .header("Accept", "application/json")
    .build("PATCH", Entity.json(patchReqJson))
    .invoke()
    .readEntity(String. class)

New Approach using OHI HTTP Library

def patchReqJson = <json_payload>
def paramsMap = [
    headers: ['Accept': 'application/json'],
    data: ["json": patchReqJson]
]

def httpRequest = ohiHttpRequest("claims_api_get")
def response = httpRequest.patch("generic/episodes", paramsMap)