Nav

To Modify a Proxy

In most cases, the proxy you generate in API Manager is suitable for deployment out of the box. However, you can modify the proxy to log data to a file or send data to a Splunk account with the Anypoint Splunk Connector, for example. To inspect or change a proxy application, import the proxy application in Anypoint Studio. You can modify the application to perform additional functionality, provided essential structures remain in place. This section shows skeletal XML examples of several types of proxy applications having the essential structures.

To inspect the essential structures of a proxy application:

  1. After setting up a proxy using API Manager, in the Status area, click one of the Download proxy options.

  2. In Studio, select File > Import.

  3. In the Import dialog, expand the Mule node, and select Anypoint Studio Generated Deployable Archive (.zip). Click Next.

  4. Navigate to a proxy zip file that you downloaded from API Manager.

  5. Click Finish.

You can now edit the proxy application.

Handling Domains Linked to the Proxy

After editing the proxy, you can export the project and then deploy it either on-premises or to CloudHub. API Gateway Runtime 1.3 - 2.x has a domain named api-gateway. In Mule 3.8.0, due to the unification of API Gateway Runtime with Mule Runtime 3.8.0 and several usability issues, the api-gateway domain has been removed. If you installed the api-gateway domain and linked the proxy to it, you are exporting and deploying only the proxy app. When deployed to production, the app relies on the domain, if there is one, that exists in that environment.

The following sections introduce the anatomy of the automatically generated proxy applications for a REST API. The anatomy of a SOAP proxy is similar.

Anatomy of a REST Proxy

This section describes the structure of a REST proxy for an API that you can set up in API Manager. From this structure, you can add additional functionality – to log data, for example. 

A proxy abstracts the API to a layer that can be managed by API Manager. A proxy for a REST API should meet the following criteria:

  • Accepts incoming service calls from applications and routes them to the URI of the target API.

  • Copies any message headers from the service call and passes them along to the API.

  • Avoids passing internal Mule headers both to the API and back to the requester. 

  • Captures message headers from the API response and attaches them to the response message.

  • Routes the response to the application that made the service call.

Here’s what a REST proxy might look like in Studio.

proxying-your-api-a2d91

The following example shows an XML configuration of the REST proxy:


    
            
         
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>

When importing the proxy for the API into Studio 5.x and earlier, the project is linked to a domain project named api-gateway. Studio 5.x and earlier creates a domain project if necessary. The domain project is identical to the domain that exists in CloudHub and in an API Gateway On-Premises by default. Match the production deployment conditions when deploying an app to the Anypoint Studio 5.x server. If you modify the domain on the API Gateway on-prem installation, replicate the changes on the domain that exists in Studio 5.x or earlier. This domain project contains the <http:listener-config statement that the Mule flow requires.

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 as shown in the HTTPS example 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.