DataPower WebServiceProxy selection of data

687 views Asked by At

i'm looking for solution for a problem. I will start with a example: we have a SOAP webservice that returns userData (userName + userAddress), I'm using Web Service Proxy to extract the UserData, but then I want to receive only userName - this needs to be done through DataPower as well. How to achieve this? I was thinking about adding another Web Service Proxy, but how to add the logic to the application that selects only the userName? Is there any message transform in dp?

UsersCatalog.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://wtp" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://wtp" xmlns:intf="http://wtp" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://wtp" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="getUserData">
    <complexType/>
   </element>
   <element name="getUserDataResponse">
    <complexType>
     <sequence>
      <element maxOccurs="unbounded" name="getUserDataReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="setUserData">
    <complexType>
     <sequence>
      <element name="userName" type="xsd:string"/>
      <element name="userAddress" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="setUserDataResponse">
    <complexType/>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="setUserDataResponse">

      <wsdl:part element="impl:setUserDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getUserDataRequest">

      <wsdl:part element="impl:getUserData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="setUserDataRequest">

      <wsdl:part element="impl:setUserData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getUserDataResponse">

      <wsdl:part element="impl:getUserDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="UsersCatalog">

      <wsdl:operation name="getUserData">

         <wsdl:input message="impl:getUserDataRequest" name="getUserDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:getUserDataResponse" name="getUserDataResponse">

       </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="setUserData">

         <wsdl:input message="impl:setUserDataRequest" name="setUserDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:setUserDataResponse" name="setUserDataResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="UsersCatalogSoapBinding" type="impl:UsersCatalog">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="getUserData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getUserDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="getUserDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="setUserData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="setUserDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="setUserDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="UsersCatalogService">

      <wsdl:port binding="impl:UsersCatalogSoapBinding" name="UsersCatalog">

         <wsdlsoap:address location="http://localhost/WebServiceProject/services/UsersCatalog"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

UsersCatalog.java (class UserImpl has 2 fields - userName and userAddress + setter and getter that sets/gets both of them in strings array at once)

package wtp;

import javax.jws.WebMethod;
import javax.jws.WebService;


@WebService
public class UsersCatalog implements User{
    public static final User userImpl = new UserImpl();


    @Override
    @WebMethod
    public String[] getUserData() {
        System.out.println("getUserData");
        return userImpl.getUserData();
    }

    @Override
    @WebMethod
    public void setUserData(String userName, String userAddress) {
        System.out.println("setUserData");
        userImpl.setUserData(userName, userAddress);
    }
}

I heard about something called message transform in datapower. It would make that so simple if i could just select xml entity to return.

I will add something more to specify my needs better:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <getUserDataResponse xmlns="http://wtp">
         <getUserDataReturn>John</getUserDataReturn>
         <getUserDataReturn>New York</getUserDataReturn>
      </getUserDataResponse>
   </soapenv:Body>
</soapenv:Envelope>

This is what i receive, i want DataPower to transform it somehow to return only first row - only the username John. How to receive such result?

1

There are 1 answers

0
dnzbrkyrk On

You can use Transform action and an XSLT to achieve this requirement. When you create a Web Service Proxy (WSP), a processing rule is automatically created for each operation. You can view those processing rules in the Policy tab of the WSP. You can add an Transform action to that rule which is created for getUserData operation.

To find about how to create an XSLT to exclude an element from an XML you can take a look at this page