How to upload Server Module Files through Restman API

Document ID : KB000101540
Last Modified Date : 18/06/2018
Show Technical Document Details
Introduction:
The RESTMAN API has instructions on listing, creating, updating, and deleting Server Module Files to an API Gateway at this location:
https://YourGatewayHost:port/restman/1.0/doc/restDoc.html#1.0/serverModuleFiles



 
Background:
Using the RESTMAN documentation to create or POST a new Server Module File proves difficult in most cases whether using curl, postman, SOAPUI, or any REST API implementation strategy.
Use this kb article to gain a better understanding of what data is needed to successfully create a new Server Module File on your Gateway.
Environment:
API Gateway 9.3
Gateway REST Management Service /restman/*
SOAP UI 5.40

 
Instructions:
In this use case we are going to install the Server Module File using Policy Manager first, get the detail via REST call, delete it, and re-create it using SOAP UI.

The only way to get the proper server module detail is to first upload the saar file using policy manager and then using the following uri to GET the detail of the module in xml format.
/restman/1.0/serverModuleFiles?includeData=true

This will list all of your currently installed serverModuleFiles. You can alternatively use the Id of the target Server module noted in the RESTMAN docs:  1.0/serverModuleFiles/{id}
So you can be sure that what you copy is specific to your intended module file details.
Copy this detail to your preferred editor. Note that you will not merely copy this detail back into SOAP UI or your POST tool. You will be copying the needed string values into the template below. This is to avoid formatting errors or other http based errors as not all of the data in the GET response is required.

This is your template that you would POST with:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<l7:ServerModuleFile xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management">
<l7:Name>assertionName</l7:Name>
<l7:ModuleType>SpecifyCustomOrModularAssertion</l7:ModuleType>
<l7:ModuleSha256>COPY_HashStringProducedWhenUsing"serverModuleFiles/assertionIDvalue?includeData=true"_HERE</l7:ModuleSha256>
<l7:ModuleData>COPY_HashStringProducedWhenUsing"serverModuleFiles/assertionIDvalue?includeData=true"_HERE</l7:ModuleData>
<l7:Signature>
<l7:Property key="cert">
<l7:StringValue>COPY_StringProducedWhenUsing"serverModuleFiles/assertionIDvalue?includeData=true"_HERE</l7:StringValue>
</l7:Property>
<l7:Property key="signature">
<l7:StringValue>COPY_StringProducedWhenUsing"serverModuleFiles/assertionIDvalue?includeData=true"_HERE</l7:StringValue>
</l7:Property>
</l7:Signature>
<l7:Properties>
<l7:Property key="moduleAssertions">
<l7:StringValue>assertionName</l7:StringValue>
</l7:Property>
<l7:Property key="moduleFileName">
<l7:StringValue>assertionFileName</l7:StringValue>
</l7:Property>
<l7:Property key="moduleSize">
<l7:StringValue>sizeOfFile</l7:StringValue>
</l7:Property>
</l7:Properties>
</l7:ServerModuleFile>

SOAPUI would need to be configured with a trusted certificate if you are to connect to a secure port. Or you can modify the RESTMAN policy to allow only basic auth and then POST on a non-ssl port. The choice is yours.
In SOAP UI you need to specify an Id string in the resource field. You can use the Id from the output retrieved during the GET call.
Example: /restman/1.0/serverModuleFiles/78cbd6a04ab448f1a0e78b653a4c4dc1

Attached is an example of a jvm Metrics Custom Assertion xml
 
Additional Information:
This can also be used in gmu.bat via the following command:
gmu.bat restman -h gatewayHostName -u admin --plaintextPassword password --trustCertificate --method POST --path 1.0/serverModuleFiles --trustHostname --request serverModuleFile.txt

Here is the curl variant submitted by a customer:
curl -u admin:$PASSWORD --insecure --data "@/path/to/serverModuleFile.xml" --header "Content-Type:application/xml" --request POST https://localhost:9443/restman/1.0/serverModuleFiles

This article is limited to using SOAP UI and will not include instructions on setting up SOAP UI to make calls to API Gateway, nor configuring GMU, or curl.
 
File Attachments:
jvmMetricsSMF.zip