Layer7 API Management

  • 1.  Which wizard should I use for creating a service?

    Posted Sep 24, 2018 05:07 AM

    Hi,

    There's a request from my client that he need to publish a SOAP web service as a RESTful web service through CA API gateway.

    I know it can be done but I just know how to create a SOAP to SOAP service.

    I have no idea which wizard should I use.

    Is there any sample for reference?

     

    Regards,



  • 2.  Re: Which wizard should I use for creating a service?

    Broadcom Employee
    Posted Sep 24, 2018 07:03 PM

    Hello Gary,

    I assume you're talking about publishing restful API for the soap backend.

    There are some tools, the such as  "Apply JSON Transformation” assertion, "Apply XSL Transformation” assertion,  json path assertion, xpath assertion, regex assertion, etc.

     

    There is no wizard so far, you will need to design restful apis as per the backend soap api, and inside restful apis, you're going to build the soap request (using above assertions) to call the backend soap api.

     

    Regards,

    Mark

     



  • 3.  Re: Which wizard should I use for creating a service?

    Posted Sep 25, 2018 05:39 AM

    Hi Mark,

    Thanks for your response

    Yes. I'm creating a RESTful API for SOAP backend.

    I have no experience in creating service like this before. Most of the requirements I met before is to create service through the wizard. (SOAP to SOAP)

    That's why I'm looking for an example for reference.



  • 4.  Re: Which wizard should I use for creating a service?

    Broadcom Employee
    Posted Sep 25, 2018 07:30 PM

    Dear Gary,

    You're welcome.

    If you have a (simple) use case (wsdl), I may try to provide an example to show how it works.

    Basically, you need to build the correct soap request for the backend service, in your restful api policy.

     

    Regards,

    Mark



  • 5.  Re: Which wizard should I use for creating a service?

    Posted Sep 27, 2018 12:10 AM

    Hi Mark,

    It's wonderful if you can show me a way to create the service

    Here's a simple Operator.wsdl. It contains several methods for different job and it already been settled in my API gateway as a SOAP to SOAP service.

    here're the methods.

    -add

    -getType

    -getTotalPrice

    -getAllProduct

    -getPrice

     

    I have no idea how you will do this sample but please don't take too much of your time.

    I really appreciate your kindly help.

     

     

    Here's the content of the wsdl.

    ------------------------------------------------wsdl start----------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://ws.apache.org/axis2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" targetNamespace="http://ws.apache.org/axis2">
    <wsdl:documentation>
    Please Type your service description here
    </wsdl:documentation>
    <wsdl:types>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2">
    <xs:element name="getType">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="product" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getTypeResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getTotalPrice">
    <xs:complexType>
    <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="products" nillable="true" type="ns:ArrayOfString"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:complexType name="ArrayOfString">
    <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="array" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="getTotalPriceResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="return" type="xs:int"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getPrice">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="productName" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getPriceResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="getAllProduct">
    <xs:complexType>
    <xs:sequence/>
    </xs:complexType>
    </xs:element>
    <xs:element name="getAllProductResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="add">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="a" type="xs:int"/>
    <xs:element name="b" type="xs:int"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="addResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="return" type="xs:int"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    </wsdl:types>
    <wsdl:message name="addRequest">
    <wsdl:part name="parameters" element="ns:add"/>
    </wsdl:message>
    <wsdl:message name="addResponse">
    <wsdl:part name="parameters" element="ns:addResponse"/>
    </wsdl:message>
    <wsdl:message name="getTypeRequest">
    <wsdl:part name="parameters" element="ns:getType"/>
    </wsdl:message>
    <wsdl:message name="getTypeResponse">
    <wsdl:part name="parameters" element="ns:getTypeResponse"/>
    </wsdl:message>
    <wsdl:message name="getTotalPriceRequest">
    <wsdl:part name="parameters" element="ns:getTotalPrice"/>
    </wsdl:message>
    <wsdl:message name="getTotalPriceResponse">
    <wsdl:part name="parameters" element="ns:getTotalPriceResponse"/>
    </wsdl:message>
    <wsdl:message name="getAllProductRequest">
    <wsdl:part name="parameters" element="ns:getAllProduct"/>
    </wsdl:message>
    <wsdl:message name="getAllProductResponse">
    <wsdl:part name="parameters" element="ns:getAllProductResponse"/>
    </wsdl:message>
    <wsdl:message name="getPriceRequest">
    <wsdl:part name="parameters" element="ns:getPrice"/>
    </wsdl:message>
    <wsdl:message name="getPriceResponse">
    <wsdl:part name="parameters" element="ns:getPriceResponse"/>
    </wsdl:message>
    <wsdl:portType name="OperatorPortType">
    <wsdl:operation name="add">
    <wsdl:input message="ns:addRequest" wsaw:Action="urn:add"/>
    <wsdl:output message="ns:addResponse" wsaw:Action="urn:addResponse"/>
    </wsdl:operation>
    <wsdl:operation name="getType">
    <wsdl:input message="ns:getTypeRequest" wsaw:Action="urn:getType"/>
    <wsdl:output message="ns:getTypeResponse" wsaw:Action="urn:getTypeResponse"/>
    </wsdl:operation>
    <wsdl:operation name="getTotalPrice">
    <wsdl:input message="ns:getTotalPriceRequest" wsaw:Action="urn:getTotalPrice"/>
    <wsdl:output message="ns:getTotalPriceResponse" wsaw:Action="urn:getTotalPriceResponse"/>
    </wsdl:operation>
    <wsdl:operation name="getAllProduct">
    <wsdl:input message="ns:getAllProductRequest" wsaw:Action="urn:getAllProduct"/>
    <wsdl:output message="ns:getAllProductResponse" wsaw:Action="urn:getAllProductResponse"/>
    </wsdl:operation>
    <wsdl:operation name="getPrice">
    <wsdl:input message="ns:getPriceRequest" wsaw:Action="urn:getPrice"/>
    <wsdl:output message="ns:getPriceResponse" wsaw:Action="urn:getPriceResponse"/>
    </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="OperatorSoap11Binding" type="ns:OperatorPortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <wsdl:operation name="add">
    <soap:operation soapAction="urn:add" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getType">
    <soap:operation soapAction="urn:getType" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getTotalPrice">
    <soap:operation soapAction="urn:getTotalPrice" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllProduct">
    <soap:operation soapAction="urn:getAllProduct" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getPrice">
    <soap:operation soapAction="urn:getPrice" style="document"/>
    <wsdl:input>
    <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="OperatorSoap12Binding" type="ns:OperatorPortType">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <wsdl:operation name="add">
    <soap12:operation soapAction="urn:add" style="document"/>
    <wsdl:input>
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getType">
    <soap12:operation soapAction="urn:getType" style="document"/>
    <wsdl:input>
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getTotalPrice">
    <soap12:operation soapAction="urn:getTotalPrice" style="document"/>
    <wsdl:input>
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllProduct">
    <soap12:operation soapAction="urn:getAllProduct" style="document"/>
    <wsdl:input>
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getPrice">
    <soap12:operation soapAction="urn:getPrice" style="document"/>
    <wsdl:input>
    <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
    <soap12:body use="literal"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="OperatorHttpBinding" type="ns:OperatorPortType">
    <http:binding verb="POST"/>
    <wsdl:operation name="add">
    <http:operation location="add"/>
    <wsdl:input>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:input>
    <wsdl:output>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getType">
    <http:operation location="getType"/>
    <wsdl:input>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:input>
    <wsdl:output>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getTotalPrice">
    <http:operation location="getTotalPrice"/>
    <wsdl:input>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:input>
    <wsdl:output>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllProduct">
    <http:operation location="getAllProduct"/>
    <wsdl:input>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:input>
    <wsdl:output>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getPrice">
    <http:operation location="getPrice"/>
    <wsdl:input>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:input>
    <wsdl:output>
    <mime:content type="application/xml" part="parameters"/>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="Operator">
    <wsdl:port name="OperatorHttpSoap11Endpoint" binding="ns:OperatorSoap11Binding">
    <soap:address location="http://localhost:8080/axis2/services/Operator.OperatorHttpSoap11Endpoint/"/>
    </wsdl:port>
    <wsdl:port name="OperatorHttpSoap12Endpoint" binding="ns:OperatorSoap12Binding">
    <soap12:address location="http://localhost:8080/axis2/services/Operator.OperatorHttpSoap12Endpoint/"/>
    </wsdl:port>
    <wsdl:port name="OperatorHttpEndpoint" binding="ns:OperatorHttpBinding">
    <http:address location="http://localhost:8080/axis2/services/Operator.OperatorHttpEndpoint/"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>

    ------------------------------------------------wsdl end----------------------------------------

     

    Zhijun He 留言:

     

    Dear Gary,

    You're welcome.

    If you have a (simple) use case (wsdl), I may try to provide an example to show how it works.

    Basically, you need to build the correct soap request for the backend service, in your restful api policy.

     

    Regards,

    Mark



  • 6.  Re: Which wizard should I use for creating a service?
    Best Answer

    Broadcom Employee
    Posted Sep 27, 2018 02:03 AM
      |   view attached

    Hello Gary,

    From the wsdl, there are 2 endpoints, I just give an example to implement the http://localhost:8080/axis2/services/Operator.OperatorHttpSoap11Endpoint/ , and only 2 actions of add, getAllProduct.

     

    So the rest api interface is designed as below,

    /myapi?op=?&action=?

    op=11 (for /Operator.OperatorHttpSoap11Endpoint) or 12(for another endpoint)

    action=add, or getAllProduct

     

    for action=add, the json payload is designed as below,

    {
    "a":"value of a",
    "b":"value of b"
    }

     

    NOTE:

    - In the attached policy, we are going to translate the payload directly, (as "Apply XSL Transformation” assertion has limitation on array, or namespace, etc.)

     

    - the policy will call a fake soap backend on the localhost(the ${soapServer} is set to localhost), you should set ${soapServer} to a real backend server for testing.

     

    - the policy doesn't transfer  the xml response back to json format, you might add the formatting snippet after route via http assertion, and use return template assertion to return the json payload.

     

    - the policy is just to show how it works, there is no error handling, parameter validation, security check, etc.

     

    Regards,

    Mark

    Attachment(s)

    zip
    myapi.xml.zip   1 KB 1 version


  • 7.  Re: Which wizard should I use for creating a service?

    Posted Sep 29, 2018 12:46 AM

    Hi Mark,

    I have imported your policy and run the tests successfully.

    It helps me a lot and thanks for your obliging help 

     

    There's a question about the response.

    It's XML format. I believe that it due to the backend service is SOAP service. Am I right?

    Is to possible to transfer it from XML response to JSON format?

     

    Regards,



  • 8.  Re: Which wizard should I use for creating a service?

    Posted Oct 01, 2018 04:52 AM

    Hi Mark,

    I found an assertion named "Apply JSON transformation" and it can transfer response from XML to JSON.

    It works fine

     

    Regards,