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
Please enter at least three characters to search
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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Consuming SOAP Service With Apache CXF and Spring
  • MuleSoft Integration With RabbitMQ
  • Object Store Connector in Mulesoft
  • How to Use Mulesoft VM Connector

Trending

  • The Role of Functional Programming in Modern Software Development
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • Key Considerations in Cross-Model Migration
  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Working With Headers in Mule Flows

Working With Headers in Mule Flows

Learn how to send SOAP and transport headers while invoking external web services from Mule flows, as for API implementations, in this tutorial.

By 
Rakesh Kumar Jha user avatar
Rakesh Kumar Jha
·
Oct. 05, 17 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
40.3K Views

Join the DZone community and get the full member experience.

Join For Free

As a MuleSoft Certified Architect, Designer and Developer, I recently worked on API implementations for one of our clients using MuleSoft’s CloudHub. One common feature that we needed to use across APIs implementations was to consume an external web service from Mule flows. MuleSoft HTTP Request Connector and Web Service Consumer are the most popular connectors which developers use to consume external web services from Mule flows. While making HTTP requests to an external web service, connectors need to be configured with all the required parameters like endpoint URL, HTTP method/operations, headers, and authentications.

In this blog, I will demonstrate how to send headers (SOAP headers and transport headers) while invoking external web services from Mule flows.

1. SOAP Headers: While consuming external SOAP services from a Mule flow, we can send SOAP headers to the external web service by using the MuleSoft property transformer.

Here, we need to create outbound properties with the prefix “soap.” using the MuleSoft property transformer. Outbound properties that begin with a “soap.” prefix will be treated as SOAP headers and ignored by the transport. All properties that aren’t named with a “soap.” prefix will be treated as HTTP transport headers (by default, the WSC uses the HTTP transport).

As we can see in the below screen, the MuleSoft property transformer named “BW_Headers” is used to create a SOAP header named “cccmoiheaders.”

Image title

The value of these headers can be static or can also be dynamic (by reading from flowVars or property placeholders). The above screen will generate the below code snippet:

<set-property propertyName="soap.cccmoiheaders" value="&lt;wsse:Security
xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;
xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot; soapenv:mustUnderstand=&quot;1&quot;&gt;&lt;
    wsse:UsernameToken wsu:Id=&quot;UsernameToken-03184DA938DBE5406314344062579892&quot;&gt;&lt;wsse:Username&gt;${BW.UserName}&lt;/wsse:Username&gt;&lt;
    wsse:Password Type=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText&quot;&gt;${BW.Password}&lt;/wsse:Password&gt;&lt;
    /wsse:UsernameToken&gt;&lt;/wsse:Security&gt;" 
doc:name="BW_Headers"/>

The output of this code snippet will generate a SOAP header named “cccmoiheaders” with the value below.

<wsse:Security

            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"

            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">

            <wsse:UsernameToken wsu:Id="UsernameToken-03184DA938DBE5406314344062579892">

                        <wsse:Username>abcddddd</wsse:Username>

                        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">absbbsbs</wsse:Password>

            </wsse:UsernameToken>

</wsse:Security>

2. Transport Headers: While consuming external web services (REST using HTTP Connector or SOAP using Web Service Consumer) from Mule flows, we can send transport headers in different ways.  Let’s see how we can send transport level headers from Mule flows while using these connectors to invoke external web services.

 2.1 Using Web Service Consumer: To send transport level headers while consuming an external SOAP service using WS Consumer, MuleSoft's property transformer is the best option. Here we need to create outbound properties (without the “soap.” prefix) using the MuleSoft property transformer before the WS Consumer. These outbound properties will be treated as transport headers (by default, the WSC uses the HTTP transport).

The below code snippet will create a transport header named “Content-Type” with the value “application/json.”

     <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>

2.2 Using HTTP Request Connector: To send transport level headers while consuming external web service using the HTTP Request Connector, we can use the MuleSoft property transformer (as described in section 2.1) or we can explicitly configure the transport headers in the HTTP Request Connector’s configuration. Outbound properties in the Mule message that arrives at the HTTP Request Connector are automatically added as HTTP request headers.

The below screen shows the header configuration in the HTTP Requester Configuration. Here the values of headers are static, but this can be fetched dynamically from flowVars or a property placeholder.

Image title

That concludes the approaches described above are useful to send headers while invoking external web services from a Mule flow. In Mule flows, we can also copy all the existing properties from the inbound scope onto the outbound scope of the message using “copy-properties.” Please see the below code snippet for how to configure copy-properties in Mule.

<copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>

Let’s share our knowledge to expand our MuleSoft community.

Thank you!

Flow (web browser) Web Service Property (programming) MuleSoft Connector (mathematics) SOAP Web Protocols

Opinions expressed by DZone contributors are their own.

Related

  • Consuming SOAP Service With Apache CXF and Spring
  • MuleSoft Integration With RabbitMQ
  • Object Store Connector in Mulesoft
  • How to Use Mulesoft VM Connector

Partner Resources

×

Comments
Oops! Something Went Wrong

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
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!