DZone
Integration Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Mule How-To: CXF Proxy Client

Mule How-To: CXF Proxy Client

This tutorial walks you through using a CXF proxy client to create a simple Mule service for consuming SOAP web services.

Patryk Bandurski user avatar by
Patryk Bandurski
·
Jul. 14, 17 · Integration Zone · Tutorial
Like (3)
Save
Tweet
7.84K Views

Join the DZone community and get the full member experience.

Join For Free

When it is time to consume SOAP web services, Mule has a couple of ways to handle this task. There was a time when I would generate stub classes based on a WSDL file, but I wanted to create flows without generating a single line of code, so I found out that we could use the cxf proxy client to handle my wish.

The Mule versions used are Mule ESB EE and Mule ESB CE.

I am going to use following tools:

  • Postman to make HTTP calls.
  • Soap UI to mock a SOAP service.
  • Anypoint Studio.

Background

We are going to create a simple service in Mule which consumes SOAP web services. Clients can call our flow by sending a GET request; then we will route to the service, consume its payload, and, based on the response's status, we will return two different kinds of response.

Time to Mock

Soap UI is a great tool which allows us to quickly mock SOAP services based on a WSDL file.

  1. Open the SOAP UI.
  2. Create a project based on a local or remote WSDL file.
  3. Right click the service endpoint and, in the context menu, choose "Generate SOAP Mock Service."
  4. In the "Generate Mock Service" window, choose which operations you would like to mock. I will select only one operation: GetObjectList.Generate MockService
  5. In the new window, double-click on the operation you will mock and then, in the next window, click Response 1.
  6. It is time to edit your mock response. It will be always returned in the way you define it here.response-cxf-proxy.png
  7. The last thing is to start the service by clicking the green play button. We are ready to write our service.

Code Sample

code.pngWe start out with the HTTP Listener configured to listen to port 8081. When a user sends a GET request for the resource /users , a flow will be invoked. Then we set the payload statically- here, we could either set a SOAP envelope or SOAP body; it is up to you which one is better for the specific use case. I have decided to set only a SOAP body.

<v1:GetObjectList xmlns:v1="http://www.omninet.de/OtWebSvc/v1">
  <v1:Get folderPath="Users">
  </v1:Get>
</v1:GetObjectList>

Next, the message processor proxy-wsSub_Flow invokes a subflow. This subflow is divided into two steps:

  1. Configuring the proxy client: it creates an outbound endpoint to send raw XML content.
  2. Sending an HTTP request to the web service endpoint.

To setup the proxy client, you have to set the Operation to Proxy client. In the Proxy Client section, you should specify what part of the SOAP message you are going to send. The body is the default option- as I mentioned earlier, it could be set to envelope.article1-1To send the prepared XML payload, we should configure the HTTP request connector - like setting host, port, path, and method (always POST). When invoking a web service, we are required to provide headers like:

  • SoapAction- which operation we would like to invoke.

  • Content Type- what is the type of content.

  • Authorization- username and password in case of basic authorization (optional).

To set up custom headers in the HTTP request connector, go to the Parameters section and click the button to Add Parameter. It will allow you to add headers one by one, or you can use the builder which will hold all custom headers in one place. Here are some examples for the mentioned headers:

  • SoapAction- http://www.omninet.de/OtWebSvc/v1/ModifyObject

  • Content-Type- application/soap+xml;charset=UTF-8

  • Authorization- Basic #[org.mule.util.Base64.encodeBytes("user:password".getBytes())]

To hash the username and password, we are using Base64's method encodeBytes. The header after evaluation: Basic c3VlcjpwYXNzd29yZA==

Code View

The code is available on GitHub.

Web Service SOAP Web Protocols

Published at DZone with permission of Patryk Bandurski, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • API Security Weekly: Issue 171
  • Distributed Tracing for Microservices on Elastic (ELK Stack)
  • What Makes the Architecture of Geo-Distributed Apps Different?
  • What Happened to HornetQ, the JMS That Shattered Records?

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • 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
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo