Exposing an Integration SOAP Service as a Managed API¶
Managed APIs refer to the APIs that are managed using MWARE ESB, namely REST APIs, GraphQL APIs, SOAP APIs, and Streaming APIs. This guide explains how to create a Proxy Service (SOAP backend) for the integration solution, generate relevant metadata for the corresponding Proxy service, publish the WSDL definition in the MWARE ESB Service Catalog and then creating a SOAP Pass-Through API.
Also, this demonstrates how the integration components and API management components of MWARE ESB work together to enable API-led integration.
Let's get started!¶
Follow the steps given below to build this use case and try it out.
Note
For more information on generating metadata artifacts if you are using an older Integration Studio workspace, see Generating Service Catalog Metadata Artifact.
Step 1: Develop the integration service¶
Follow the instructions given in this section to create and configure the required artifacts.
- Download the relevant ESB Integration Studio based on your operating system.
- Open ESB Integration Studio.
-
Click New Integration Project in the Getting Started tab as shown below.
This will open the New Integration Project dialog box.
-
Enter
ProxyServiceSample
as the project name and select the following check boxes to create the required modules.- Create ESB Configs
- Create Composite Exporter
-
Click Finish.
You can see the projects listed in the Project Explorer as shown below:
Note
A resources folder is created in the
ProxyServiceSampleConfigs
project. This folder holds the metadata YAML files of the created proxy services. These YAML files will be uploaded to the Service Catalog later in this tutorial. -
Create a Proxy Service artifact.
- In the project explorer, right-click ProxyServiceSampleConfigs and click New -> Proxy Service.
- Follow the Using a Simple Proxy Service to create the StockQuoteProxy Proxy Service.
-
Enter the details given below to create a new Proxy Service.
Property Value Description Name StockQuoteProxy
The name of the Proxy Service. Save location ProxyServiceSampleConfigs This is the ESB Config module where the artifact will be saved. -
Click Finish.
-
Open the Source view of the StockQuoteProxy that you created and edit the integration solution.
<?xml version="1.0" encoding="UTF-8"?> <proxy name="StockQuoteProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse"> <target> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> <inSequence> <log description="Request Log" level="custom"> <property name="Message" value=""You have successfully invoked the StockQuoteProxy""/> </log> </inSequence> <outSequence> <send/> </outSequence> <faultSequence/> </target> <publishWSDL uri="file:/path/to/sample_proxy_1.wsdl"/> </proxy>
When the StockQuoteProxy is created, the following new file is created in the metadata folder.
StockQuoteProxy_proxy_metadata.yaml | This file contains the metadata of the integration service you created in the previous step. |
---|
Step 2: Configure service metadata¶
Let's update the metadata of the integration service.
- Open the
StockQuoteProxy_proxy_metadata.yaml
file from the project explorer. -
Update the following values in the file.
Parameter Value Description description Response a sample payload from the service
Explain the purpose of the Proxy Service. serviceUrl http://localhost:8290/services/StockQuoteProxy
This is the URL of the API when it gets deployed in the Micro Integrator. You (as the integration developer) may not know this URL during development. Therefore, you can parameterize the URL to be resolved later using environment variables. By default, the {MI_HOST}
and{MI_PORT}
values are parameterized with placeholders. In the runtime, if placeholder values are not defined server default hostname and http/https listener ports will be used. You can configure the serviceUrl in the following ways:-
Add the complete URL without parameters. For example:
http://localhost:8290/services/StockQuoteProxy
. Let's use this option for this tutorial. -
Parameterize using the host and port combination. For example:
http://{MI_HOST}:{MI_PORT}/services/StockQuoteProxy
. -
Parameterize using a preconfigured URL. For example:
http://{MI_URL}/services/StockQuoteProxy
.
Tip
See the Service Catalog API documentation for more information on the metadata in the YAML file.
-
Add the complete URL without parameters. For example:
-
Important: Be sure to change the
serviceUrl
from HTTPS to HTTP. This is required because the StockQuoteProxy is not secured. -
Leave the default values for the remaining parameters.
Step 3: Configure the Micro Integrator¶
The Micro Integrator contains a client application, which automatically publishes artifacts to the Service Catalog in the API Publisher portal.
Let's enable this client for the embedded Micro Integrator of ESB Integration Studio.
- Click the Embedded Micro Integrator Configuration () icon on the upper menu to open the dialog box.
-
Uncomment the
[[service_catalog]]
section as shown below and change the APIM server configurations accordingly.Tip
The default username and password for connecting to the API gateway is
admin
.[[service_catalog]] apim_host = "https://localhost:9443" enable = true username = "admin" password = "admin"
-
Optionally, you can encrypt the username and password for better security:
-
Update the configuration as shown below.
[secrets] userName = "[admin]" password = "[admin]" [[service_catalog]] apim_host = "https://localhost:9443" enable = true username = "$secret{username}" password = "$secret{password}"
-
Click Encrypt Secrets.
Tip
See Encrypt static (embedded) server secrets for details.
-
-
Save the configurations.
-
Optionally, inject environment variables to your Micro Integrator. Default in runtime, if placeholder
{MI_HOST}
and{MI_PORT}
values are not defined server default hostname and http/https listener ports will be used.If you chose to parameterize the
serviceUrl
in the metadata file, you must inject the parameterized values as environment variables. Shown below are example placeholder values that you may have used in theserviceUrl
followed by the corresponding environment variables.{MI_HOST} : localhost {MI_PORT} : 8290 #for http protocols. Otherwise 8253 {MI_URL} : localhost:8290 #for http protocols. Otherwise localhost:8253
Tip
See the instructions on injecting environment variables to the embedded Micro Integrator.
Step 4: Package the artifacts¶
Package the artifacts in your composite exporter module to be able to deploy the artifacts in the server.
- Open the
pom.xml
file of the ProxyServiceSampleCompositeExporter module. -
Ensure that the following artifact is selected in the POM file.
StockQuoteProxy
-
By default, the
Publish to Service Catalog
checkbox is enabled. If not, please select the checkbox in the wizard so that it will include metadata files of the selected artifacts. -
Save the changes.
Step 5: Start the ESB runtime¶
Let's start the ESB runtime before starting the Micro Integrator.
- Download and set up MWARE ESB.
- Start the server.
Step 6: Build and run the service¶
Let's deploy the packaged artifacts in the embedded Micro Integrator:
Info
When you do this step:
- The Micro Integrator first reads the metadata files.
- If you used placeholders in the metadata file, they are replaced with environment variable values.
- It gets the WSDL 1 definition of the deployed proxy service from the 'serviceUrl' as in 'Step 2: Configure service metadata' and ZIP file is created along with the metadata file.
- Finally, it uploads the metadata to the API management runtime.
- Right-click the composite exporter module and click Export Project Artifacts and Run.
- In the dialog box that opens, confirm that the required artifacts from the composite exporter module are selected.
- Click Finish.
The artifacts are deployed in the embedded Micro Integrator and the Micro Integrator starts. The integration service is also deployed in the Service Catalog during server startup. You will see the following in the server start-up log.
Successfully updated the service catalog
Step 7: Create and Deploy the Proxy Service as a SOAP Pass-Through API¶
Create the API
Let's expose the integration service as a managed API.
-
Sign in to the API Publisher portal:
https://localhost:9443/publisher
.Tip
Use
admin
as the username and password. -
You can also click the hamburger icon on the upper-left and click Services to see the available services.
-
Open StockQuoteProxy from the above list.
-
Click Create API in the above screen to open the Create API dialog box.
-
Specify an API name, context, and version, and then click Create API.
Tip
You will find these values already populated based on the information in the integration service.
You can now see the new API's overview page.
Note
- You can use the left-hand navigation to explore the new API.
- Click Endpoints in the left-hand navigator. You will see that the new API uses the integration service deployed in the Micro Integrator as the endpoint (backend).
Select business plans
Let's allocate some business plans for the API.
-
Go to the API overview and click Business Plan.
-
Select at least one business plan for the API and save.
Deploy API in the Gateway
Let's deploy the API in a gateway environment.
-
Go to the API overview and click Deploy.
Tip
This opens the Deployment tab in the left-hand navigator.
-
Click Default to specify the gateway environment and host.
Tip
This setting deploys the API in Production as well as Sandbox gateways. Find out more about gateway environments.
-
Optionally, you can add a description.
-
Click Deploy.
You will now see the deployment as the first revision of the API:
Step 8: Publish the API¶
Go to the API overview in the Publisher portal and click Publish for the StockQuoteProxy
as shown below.
The API is now available in the Developer portal for consumers to access.
Step 9: Subscribe to the API¶
Now, let's assume you are an API consumer who wants to use the API. As a consumer, you need to first subscribe to the API.
-
Sign in to the Developer portal:
https://localhost:9443/devportal/apis
.Tip
Use
admin
as the username and password. -
Go to the API tab. The
StockQuoteProxy
is listed as shown below. -
Select the
StockQuoteProxy
to open the API overview. -
Go to the Subscriptions tab and subscribe using the DefaultApplication as shown below.
Tip
For detailed instructions, see Subscribe to an API.
Step 10: Use the SOAP Pass-Through API¶
Before you begin
Let's start the back-end service.
- Download the back-end service.
- Extract the downloaded zip file.
- Open a terminal, navigate to the
axis2Server/bin/
directory inside the extracted folder. -
Execute the following command to start the axis2server with the SimpleStockQuote back-end service:
sh axis2server.sh
axis2server.bat
Generate access token
When you consume an API from the marketplace, your access to the API is authenticated. Therefore, the DefaultApplication that you used for subscribing to the API should get an access token for the gateway environment in which the API is deployed. Since the StockQuoteProxy
is deployed in the Production gateway, you must generate PROD keys.
- Go to the Subscriptions tab for the
StockQuoteProxy
in the Developer portal. -
Click PROD KEYS for the DefaultApplication.
-
Click Generate Keys (at the bottom of this view) to apply a consumer key and secret as shown below.
Note
The application may already have a consumer key and secret generated. In this case, you can skip this step.
-
Click Generate Access Token in the above view to generate the access token.
-
Save the generated token.
Try out the service
Now, let's test the use case by sending a simple client request that invokes the service.
-
Click Try Out for the
StockQuoteProxy
in the Developer portal as shown below. -
Enter the following details.
Security Type Select OAuth as the security type. Applications Select DefaultApplication from the list of application. Key Type Select Production as the key type. This means that the production gateway (environment) is used. access.token Add the access token you generated for the DefaultApplication. You can also click GET TEST KEY to generate a test token. Gateway Select Default as the gateway. -
Expand the / POST resource and click Try it out.
- Let's specify 'urn:getQuote' as the SOAP Action.
- Let's input the following payload as the SOAP Request.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <soapenv:Header/> <soapenv:Body> <ser:getQuote> <ser:request> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getQuote> </soapenv:Body> </soapenv:Envelope>
-
Click Execute.
You will get the response message from the StockQuoteProxy service:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:change>3.9976027101114964</ax21:change>
<ax21:earnings>13.346364457377131</ax21:earnings>
<ax21:high>-73.39500514990955</ax21:high>
<ax21:last>73.6913265107944</ax21:last>
<ax21:lastTradeTimestamp>Fri Sep 24 22:10:56 IST 2021</ax21:lastTradeTimestamp>
<ax21:low>-71.88761385784731</ax21:low>
<ax21:marketCap>4.3004624870633185E7</ax21:marketCap>
<ax21:name>IBM Company</ax21:name>
<ax21:open>-71.86467758088759</ax21:open>
<ax21:peRatio>24.390401836247552</ax21:peRatio>
<ax21:percentageChange>-5.715833533678435</ax21:percentageChange>
<ax21:prevClose>-69.93910313442652</ax21:prevClose>
<ax21:symbol>IBM</ax21:symbol>
<ax21:volume>8029</ax21:volume>
</ns:return>
</ns:getQuoteResponse>
</soapenv:Body>
</soapenv:Envelope>
Now, check the Console tab of ESB Integration Studio and you will see the following message:
INFO - LogMediator Message = "You have successfully invoked the StockQuoteProxy"
Tip
For detailed instructions see Invoke an API using the Integrated API Console.