Introduction
The most popular connector probably is HTTP connector. However, for the enterprise application, this is not good enough. We need to setup HTTPS connect. Since Anypoint Studio, previously called Mule Studio, the configuration of HTTPS has been change. In this blog, I am going document the procedures on how to setup the HTTPS connector for the on-premise application, together with few other technical aspects. Here is the flow I have setup:
In this flow, I have few interesting parts. One is about content-based-routing, and the other is how to setup response content-type. In my case, I setup it as applicaiton/json.Generate Self-signed Keystore
For the self-signed certificates, we can use keytool coming with JDK. First created a directory name something like certs. In my case, it is located at:1 | /Users/Gary2013/AnypointStudio-3.7/certs |
1 | keytool -genkey -alias mule-server -keyalg RSA -keystore keystore.jks |
Setup HTTPS Connector
The following 2 pictures show where to put the certificates. In order to setup HTTPS connector, we need to configure 2 pages from the Anypoint Studio as shown below:Setup The Mule Flow
The flow setup is not that complicated. Here I just provide the configuration file. For the details, I will provide a video, you can my youtube video.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <!--xml version="1.0" encoding="UTF-8"?--> < mule xmlns:tracking = "http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json = "http://www.mulesoft.org/schema/mule/json" xmlns:http = "http://www.mulesoft.org/schema/mule/http" xmlns:tls = "http://www.mulesoft.org/schema/mule/tls" xmlns = "http://www.mulesoft.org/schema/mule/core" xmlns:doc = "http://www.mulesoft.org/schema/mule/documentation" xmlns:spring = "http://www.springframework.org/schema/beans" version = "EE-3.7.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> < http:listener-config name = "HTTPS_Listener_Configuration" protocol = "HTTPS" host = "0.0.0.0" port = "${https.port.onpremise}" doc:name = "HTTP Listener Configuration" > < tls:context > < tls:trust-store > < tls:key-store type = "jks" path = "/Users/Gary2013/AnypointStudio-3.7/certs/keystore.jks" alias = "mule-server" keypassword = "changeit" password = "changeit" > </ tls:key-store ></ tls:trust-store ></ tls:context > </ http:listener-config > < http:listener-config name = "HTTP_Listener_Configuration" host = "0.0.0.0" port = "${http.port.onpremise}" doc:name = "HTTP Listener Configuration" > < flow name = "lineagelogisticsinventoryFlow" > < http:listener config-ref = "HTTPS_Listener_Configuration" path = "/inventory" doc:name = "HTTP" allowedmethods = "GET, POST" > < logger message = "#[payload]" level = "INFO" doc:name = "Logger" > < set-variable variablename = "method" value = "#[message.inboundProperties.'http.method']" doc:name = "Variable" > < choice doc:name = "Choice" > < when expression = "#[flowVars['method'] == 'POST']" > < set-payload value = "#[payload]" doc:name = "Set Payload" > </ set-payload ></ when > < otherwise > < set-variable variablename = "name" value = "#[message.inboundProperties.'http.query.params'.name]" doc:name = "Variable" > < set-payload value = "{"name": "#[flowVars.name]"}" doc:name = "Set Payload" > </ set-payload ></ set-variable ></ otherwise > </ choice > < response > < set-property propertyname = "Content-Type" value = "application/json" doc:name = "Property" > </ set-property ></ response > </ set-variable ></ logger ></ http:listener ></ flow > </ http:listener-config ></ mule > |
1 2 3 4 5 6 | < http:listener-config name = "HTTPS_Listener_Configuration" protocol = "HTTPS" host = "0.0.0.0" port = "${https.port.onpremise}" doc:name = "HTTP Listener Configuration" > < tls:context > < tls:trust-store > < tls:key-store type = "jks" path = "/Users/Gary2013/AnypointStudio-3.7/certs/keystore.jks" alias = "mule-server" keypassword = "changeit" password = "changeit" > </ tls:key-store ></ tls:trust-store ></ tls:context > </ http:listener-config > |
Test The Flow
I use PostMan to test the flow for GET and POST methods with following URL:
To test POST method, put the following JSON into the body of the PostMan:1 2 3 4 5 6 | { "name" : "Barack Obama" , "phone" : "888-555-8888" , "address" : "1600 Pennsylvania Avenue Northwest, Washington, DC 20500" , "Title" : "US President" } |
You should get the same json back as the following:
1 2 3 4 5 6 | { "name" : "Barack Obama" , "phone" : "888-555-8888" , "address" : "1600 Pennsylvania Avenue Northwest, Washington, DC 20500" , "Title" : "US President" } |
1 | https: //localhost:8443/inventory?name=Gary Liu Jr. |
1 2 3 | { "name" : "Gary Liu Jr." } |
ReplyDeleteThank you for sharing wonderful information with us to get some idea about it.
Mulesoft Online Training
Mulesoft Online Course