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

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

Trending

  • RAG Architecture Patterns: Proxy, Caching, and Routing
  • Microsoft Fabric Throttling: Diagnose Before You Scale
  • Designing Frontend Applications for Failure, Not Just Success
  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes

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. 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
·
Oct. 05, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
40.8K 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

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

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