Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to SSL Your APIs in Mule ESB

DZone's Guide to

How to SSL Your APIs in Mule ESB

You can use a self-signed certificate for your SSL API in Mule ESB to create an HTTPS-based API. Just add the certificate to the project and use SSL for API.

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

In my previous blog, I showed you how to create a self-signed certificate for your SSL API. 

In this blog, I will be showing how you can use this certificate in Mule ESB to create an HTTPS-based API.

Screen Shot 2017-03-18 at 19.20.04

Adding Certificate to Project

Let's add the certificate to our project src/main/resources folder. We will be using this to add TLS/SSL to our HTTP endpoint listener.

Screen Shot 2017-03-18 at 19.18.27

As shown in the image, we have added localserver.p12 to the project resources folder.

You can also create a subfolder and add your certificate to it, but make sure you use the proper location of certificate while adding it to the HTTP listener in your config file.

Using SSL for API

Once you are done adding the certificate to your project resources, let's drag and drop an HTTP listener to your Mule config file and start configuring the listener and adding the certificate detail to your listener.

Screen Shot 2017-03-18 at 19.19.21

After adding the certificate detail to your listener, add a set payload to get the response in your browser.

Screen Shot 2017-03-18 at 20.11.09

We will be calling our API at this URL: https://localhost:4443/localapi

When you call the above URL in your browser, be aware that you will be welcomed with an error message/warning by the browser saying that your connection isn't private.

Various browsers may use different words, but the root cause is same: the certificate you are using is not certified by a Certificate Authority (CA).

Screen Shot 2017-03-18 at 20.18.49

To overcome this error, you can go to Advanced, add the exception to your browser, and refresh the page. You will be able to see the response from the API.

Screen Shot 2017-03-18 at 20.19.10

This will be the output:

Screen Shot 2017-03-18 at 20.19.16

With this tutorial, you can see how to add HTTPS to your API in Mule ESB. 

Watch the video tutorial below.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
mule esb ,ssl certificates ,anypoint ,https ,api ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}