Friday, February 6, 2026

OIC - Using OCI Functions to Resolve Redirect URLs for Oracle Integration Cloud (OIC)

Introduction

Oracle Integration Cloud (OIC) is great at orchestrating APIs, but it has a limitation when dealing with HTTP redirects. Many external services return shortened or deflected URLs that internally redirect multiple times before reaching the final destination URL.

OIC REST Adapter does not reliably expose the final redirected URL in such cases. This becomes a blocker when downstream logic depends on extracting values (like UUIDs, tokens, or IDs) from the final URL.

To solve this, we can use OCI Functions as a lightweight middleware to resolve redirects and return the final URL back to OIC.

Problem Statement (Use Case)

OIC invokes an external API (for example: email body from Microsoft Graph, SendGrid, or any notification service). The response contains a short or redirected URL. OIC needs the final resolved URL to:

Extract a UUID or parameter

Call another API

Perform validation or tracking

OIC REST Adapter does not provide the final redirected URL easily.

Solution Overview

We introduce OCI Functions between OIC and the redirected URL.

High-Level Flow

OIC extracts the redirected/short URL from API response.

OIC calls an OCI Function, passing the URL as input.

OCI Function:

Follows HTTP redirects

Resolves the final destination URL

OCI Function returns the final URL to OIC.

OIC continues processing (UUID extraction, API calls, etc.).

Architecture Diagram (Logical):

OIC → OCI Function → External Redirect URL

      ↑                     ↓

      └──── Final URL ──────┘

OCI Function Implementation

You can use Java, Node.js or Python. Below I have used Java code.

package com.clp.fn;

import java.net.URI;

import java.net.URLDecoder;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import java.nio.charset.StandardCharsets;

import java.time.Duration;

import java.util.Optional;

import java.util.logging.Level;

import java.util.logging.Logger;

public class SendGridRedirectResolver {

private static final Logger logger =

Logger.getLogger (SendGridRedirectResolver.class.getName());

private static final int MAX REDIRECTS = 10;

private static final HttpClient CLIENT = HttpClient.newBuilder()

.connectTimeout (Duration.ofSeconds (60))

.followRedirects (HttpClient.Redirect.NEVER)

.build();

//DTOS (Modern Java Records)

public static class Input {

public String input_url;

}

public static class Result {

public String output_url;

public String uuid;

public String executionInfo;

}

// Entry method

public Result handleRequest (Input input) {

Result result = new Result();

try {

logger.log(Level.INFO, "OIC-Input URL: {0}", input.input_url);

System.out.println("OIC-Input URL: " + input.input_url);

String decodedUrl = extractFromUrlDefense (input.input_url);

logger.log (Level.INFO, "OIC-Decoded SendGrid URL: (0)", decodedUrl); System.out.println("OIC-Decoded SendGrid URL : " + decodedUrl);

String finalUrl = resolveFinalUrl (decodedUrl);

logger.log (Level.INFO, "OIC-Final URL: (0)", finalUrl);

System.out.println("OIC-Final URL:: " + finalUrl);

result.output_url = finalUrl;

result.uuid = "";

result.executionInfo = "SUCCESS";

return result;

} catch (Exception e) {

result.executionInfo = e.getMessage();

logger.log (Level.SEVERE, "Processing failed", e);

System.out.println("OIC- Exception: + e);

return result;

}

}

// Core Logic

private static String extractFromUrlDefense (String url) {

int start = url.indexOf("/");

int end = url.indexOf(";");

if (start < 0 || end < 0 || end <= start + 3) {

throw new IllegalArgumentException("Invalid urldefense URL");

}

}

String encoded = url.substring(start + 3, end);

return URLDecoder.decode (encoded, StandardCharsets.UTF8);

private static String resolveFinalUrl (String url) throws Exception {

URI current URI.create(url);

for (int i = 0; i < MAX REDIRECTS; i++) {

HttpRequest request = HttpRequest.newBuilder (current) .timeout(Duration.ofSeconds (60))

.GET()

.build();

HttpResponse<Void> response =

CLIENT.send(request, HttpResponse.BodyHandlers.discarding());

int status = response.statusCode();

if (status >= 300 && status < 400) {

Optional<String> location =

response.headers().firstValue("Location");

if (location.isEmpty()) {

}

throw new RuntimeException("Redirect without Location header");

current = current.resolve(location.get());

} else {

}

return current.toString();

}

}

throw new RuntimeException("Too many redirects");

}

// Standalone Test

public static void main(String[] args) {

String urlDefense =

"Paste your redirect url here";

Input input = new Input();

input.input_url = urlDefense;

SendGridRedirectResolver resolver = new SendGridRedirectResolver();

Result result resolver.handleRequest(input);

System.out.println("output_url:" + result.output_url);

System.out.println("uuid:" + result.uuid);

}

}

Snap of codes:





Deploying OCI Function

  • Create an OCI Function Application
  • Deploy the function using Fn CLI
  • Expose it via OCI API Gateway
  • Secure it using:
  • OCI IAM
  • API Key or OCI Resource Principal
  • Calling OCI Function from OIC

Steps in OIC

Create a REST Adapter integration

Configure API Gateway endpoint

Pass the redirected URL as request payload

Receive response:

Json

{

  "finalUrl": "https://example.com/path/uuid/12345"

}

Extracting Required Data in OIC

Once OIC receives the final URL:

Extract UUID or parameters

Continue downstream orchestration

Example:

substring-after(finalUrl, '/uuid/')

Benefits of This Approach

✅ Overcomes OIC redirect limitations

✅ Clean separation of concerns

✅ Serverless and cost-effective

✅ Reusable across multiple integrations

✅ Easy to maintain and enhance

Real-World Scenarios

Email tracking links (SendGrid, Twilio)

Microsoft Graph email body links

Payment gateway redirect URLs

Identity verification flows

Short URL expansion

Conclusion

Using OCI Functions as a redirect resolver is a simple yet powerful pattern when working with OIC. It keeps integrations clean, avoids complex workarounds, and provides full control over HTTP behavior.

If your OIC flow depends on the final destination URL, this approach is highly recommended.


No comments:

Post a Comment

Featured Post

OIC - Using OCI Functions to Resolve Redirect URLs for Oracle Integration Cloud (OIC)

Introduction Oracle Integration Cloud (OIC) is great at orchestrating APIs, but it has a limitation when dealing with HTTP redirects. Many e...