DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)
  • Creating a Mule ESB Sample Hello World Application

Trending

  • Member Spotlight: Shai Almong
  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • How to Build a Scalable SaaS Product Architecture
  • RAG Architecture Patterns: Proxy, Caching, and Routing

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Constructing Dynamic Endpoint URLs in WSO2 ESB

Constructing Dynamic Endpoint URLs in WSO2 ESB

This post will explain three different ways to construct a dynamic URL in ESB.

By 
Jenananthan Yogendran
·
Jun. 04, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

There are situations where you need to modify or generate endpoint URL dynamically in runtime. It can be entire endpoint URL, context of the URL, resource path of the URL, or query parameters.

This post will explain three different ways to construct a dynamic URL in ESB.

1. HTTP Endpoint

HTTP endpoint can be dynamically constructed using uri template. Create a properties name starting with uri.var prefix and define the uri template to refer those created properties e.g if the property name is uri.var.context, then uri template cane be defined as: http:://localhost/{uri.var.context}. In the runtime, these place holders in the uri templates will be populated by the values in the property related to that.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SampleProxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <property name="uri.var.host" value="http://localhost:8280"/>
         <property name="uri.var.context" value="services"/>
         <property name="uri.var.resourcepath" value="get-records"/>
         <call>
            <endpoint>
               <http method="GET"
                     uri-template="{uri.var.host}/{uri.var.context}/{uri.var.resourcepath}"/>
            </endpoint>
         </call>
      </inSequence>
      <outSequence/>
      <faultSequence/>
   </target>
   <description/>
</proxy>


In the runtime, the URL would be http://localhost:8280/services/get-records

2. Using Default Endpoint

The default endpoint will look for the endpoint url from “To” transport header. Therefore, the endpoint can be constructed dynamically and set to “To” header.

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="SampleProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property name="host" scope="default" type="STRING" value="http://localhost:8280"/>
            <property name="context" scope="default" type="STRING" value="services"/>
            <property name="resourcepath" scope="default" type="STRING" value="get-records"/>
            <header expression="fn:concat($ctx:host,'/',$ctx:context,'/',$ctx:resourcepath)" name="To" scope="default"/>
            <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
            <call>
                <endpoint>
                    <default/>
                </endpoint>
            </call>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>

In the runtime, the URL would be http://localhost:8280/services/get-records

3. Using Address Endpoint

When working with address endpoint url context and resource path, query params can be dynamically appended to the endpoint using REST_URL_POSTFIX property.

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="SampleProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property name="context" scope="default" type="STRING" value="services"/>
            <property name="resourcepath" scope="default" type="STRING" value="get-records"/>
            <property expression="fn:concat($ctx:context,'/',$ctx:resourcepath)" name="REST_URL_POSTFIX" scope="axis2" type="STRING"/>
            <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
            <call>
                <endpoint>
                    <address uri="http://localhost:8280/"/>
                </endpoint>
            </call>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>

In the runtime, the URL would be http://localhost:8280/services/get-records

Enterprise service bus

Opinions expressed by DZone contributors are their own.

Related

  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)
  • Creating a Mule ESB Sample Hello World Application

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook