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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks
  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.

Jenananthan Yogendran user avatar by
Jenananthan Yogendran
·
Jun. 04, 18 · Tutorial
Like (2)
Save
Tweet
Share
15.83K 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.

Trending

  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: