<http:listener-config name="lisConfig" basePath="api">
<http:listener-connection protocol="https" port="${serverPort}" host="localhost" usePersistentConnections="true">
<tls:context>
<tls:key-store path="keystore.jks" keyPassword="key" password="pass"/>
</tls:context>
</http:listener-connection>
</http:listener-config>
HTTP Connector XML Reference
Anypoint Connector for HTTP (HTTP Connector) listens for events or performs operations based on the HTTP or HTTPS protocol. When using the HTTPS protocol, the connector requires a TLS context child element configuration. The following examples show HTTP Connector source and operations configuration in XML.
HTTP Listener XML Configuration Example
The http:listener-config
parent element organizes connection elements, such as the listen port
and tls:context
, inside a child http:listener-connection
element. The following example shows the XML configuration:
The following example shows the XML configuration of an http:listener
source in a flow:
<flow name="server">
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
<logger message="HEY"/>
</flow>
To access HTTP listener attributes, use DataWeave syntax as shown in the following table:
HTTP object | Mule runtime engine 3.x | Mule runtime engine 4.x |
---|---|---|
Method |
|
|
Path |
|
|
Relative Path |
|
|
Request URI |
|
|
Query String |
|
|
Query Parameters |
|
|
URI Parameters |
|
|
Version |
|
|
Scheme |
|
|
Headers |
|
|
Remote Address |
|
|
Client Certificate |
|
|
HTTP Request XML Configuration Example
The http:request-config
parent element organizes connection elements of the request inside a child http:request-connection
element. The following example shows the XML configuration:
<http:request-config name="reqConfig" basePath="api/v2">
<http:request-connection protocol="HTTP" port="${clientPort}" host="localhost">
<tls:context>
<tls:trust-store path="ssltest-cacerts.jks" password="changeit"/>
</tls:context>
<http:authentication>
<http:basic-authentication username="#[user]" password="#[password]" preemptive="#[preemptive]" />
</http:authentication>
</http:request-connection>
</http:requester-config>
The following example shows the XML configuration of an http:request
operation in a flow:
<flow name="client">
<http:request path="/" config-ref="reqConfig"/>
</flow>
The HTTP request returns HttpResponseAttributes
. To access HTTP request attributes, use DataWeave syntax as shown in the following table:
HTTP object | Mule runtime engine 3.x | Mule runtime engine 4.x |
---|---|---|
Status Code |
|
|
Reason Phrase |
|
|
Headers |
|
|
HTTP Load Static Resource XML Configuration Example
The following example shows the XML configuration of an http:load-static-resource
operation in a flow:
<flow name="server">
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig"/>
<http:load-static-resource resourceBasePath="root" defaultFile="index.html"/>
</flow>
HTTP Basic Security Filter XML Configuration Example
The following example shows the XML configuration of an http:basic-security-filter
operation in a flow:
<flow name="listenerBasicAuth">
<http:listener config-ref="listenerConfigBasicAuth" path="/basic"/>
<http:basic-security-filter realm="mule-realm"/>
<logger message="TestBasicAuthOk"/>
</flow>
HTTP Request, Response, and Error Response Body XML Example
Defining the body of an HTTP request, response, and error response is optional. When you do not explicitly define the body element, the request or response returns the default payload.
The following example shows the XML configuration of an http:request
operation that defines a custom body
, a key/value query-parameter
, an X-Custom header
, and a uri-params
with the uriParamsMap
variable that populates the URI parameter uriParam
:
<http:request path="/{uriParam}/test" config-ref="reqConfig">
<http:body>
#['Custom body']
</http:body>
<http:headers>
#[{'X-Custom' : 'custom'}]
</http:headers>
<http:uri-params>
#[uriParamsMap]
</http:uri-params>
<http:query-params>
#[{'key’' : 'value’'}]
</http:query-params>
</http:request>
The following example shows the XML configuration of an http:listener
source that lacks a defined body
element. The returned value is the default payload. The payload defines an http:response
to a successful execution that consists of a 200
statusCode
and Ok
as the reasonPhrase
, with headers
Name
as content
, and Something
as someValue
:
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
<http:response statusCode="200" reasonPhrase="Ok">
<http:headers>
#[{"Name" : "content", "Something" : someValue}]
</http:headers>
</http:response>
</http:listener>
The following example shows the XML configuration of an http:listener
source that defines a response to an execution failure that returns a 502
statusCode
and Failure
as the reasonPhrase
, with headers
Error
as FIRE
and body
as Oops, something is wrong
:
<http:listener path="test" allowedMethods="GET" config-ref="lisConfig">
<http:error-response statusCode="502" reasonPhrase="Failure">
<http:body>
#[‘Oops, something is wrong’]
</http:body>
<http:headers>
#[{"Error" : "FIRE"}]
</http:headers>
</http:error-response>
</http:listener>