Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

To Configure a REST Proxy

  1. Construct the Mule XML configuration to specify the REST proxy as shown in the following example:


       
    
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
34
35
36
37
38
39
40
41
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw"
        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"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/api-platform-gw http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
  <api-platform-gw:api id="${api.id}" apiName="${api.name}" version="${api.version}" flowRef="proxy" doc:name="API Autodiscovery">
        <api-platform-gw:description>${api.description}</api-platform-gw:description>
    </api-platform-gw:api>
    <http:request-config name="http-request-config" host="${implementation.host}" port="${implementation.port}" basePath="${implementation.path}" doc:name="HTTP Request Configuration"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="proxy">
        <http:listener config-ref="HTTP_Listener_Configuration" path="${proxy.path}" parseRequest="false" doc:name="HTTP"/>
        <flow-ref name="copy-headers" doc:name="Flow Reference"/>
        <http:request config-ref="http-request-config" method="#[message.inboundProperties['http.method']]"
                      path="#[message.inboundProperties['http.request.path'].substring(message.inboundProperties['http.listener.path'].length()-2)]" parseResponse="false" doc:name="HTTP">
            <http:request-builder>
                <http:query-params expression="#[message.inboundProperties['http.query.params']]"/>
            </http:request-builder>
            <http:success-status-code-validator values="0..599" />
        </http:request>
        <flow-ref name="copy-headers" doc:name="Flow Reference"/>
    </flow>
    <sub-flow name="copy-headers">
        <custom-transformer class="com.mulesoft.gateway.extension.CopyHeadersTransformer" doc:name="Java"/>
        <!-- This can be uncommented for customization
            <copy-properties propertyName="*"/>
            <remove-property propertyName="Host"/>
            <remove-property propertyName="Content-Length"/>
            <remove-property propertyName="MULE_*"/>
            <remove-property propertyName="Connection"/>
            <remove-property propertyName="Transfer-Encoding"/>
            <remove-property propertyName="Server"/>
        -->
    </sub-flow>
</mule>

+ . In the API project, configure the property placeholders in the configuration in the mule-app.properties file, which you can find in the Package Explorer under src/main/app.

+


       
    
1
2
3
4
5
6
7
8
9
api.id=apiId
api.name=My API
api.version=1.0.0
api.description=This is my API
proxy.path=/api/*
implementation.host=www.google.com
implementation.port=80
implementation.path=/
http.port=8081

+ If an API requires HTTPS communication, or returns internal API URLs as part of the response, additional configuration might be required.

+ The downloaded file is a deployable proxy application.

+ . If needed, modify the downloaded zip file to adjust for port conflicts, use shared connector resources, or include custom code for logic that you want to add to the proxy. Deploy the proxy application.

+ After deployment, the yellow circle in the status indicator turns green.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+