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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)
  • Creating a Mule ESB Sample Hello World Application
  • Step By Step Guide To Using Mule ESB
  • Is Enterprise Service Bus (ESB) Obsolete After Microservices?

Trending

  • When Caches Collide: Solving Race Conditions in Fare Updates
  • Server-Driven UI: Agile Interfaces Without App Releases
  • Automating E2E Tests With MFA: Streamline Your Testing Workflow
  • Testing the MongoDB MCP Server Using SingleStore Kai
  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 user avatar
Jenananthan Yogendran
·
Jun. 04, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
17.4K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • Step By Step Guide To Using Mule ESB
  • Is Enterprise Service Bus (ESB) Obsolete After Microservices?

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: