Using WSDII invoker

About this task
Before you use BTT WSDII invoker in your Client, make sure the web service is deployed successfully in your environment.

After deploying Web Service successfully, follow these steps to dynamically invoke Web Service with BTT WSDII Invoker:

  1. Address invoker definition in btt.xml file:
    <kColl id="invoker">
    		
    			<kColl id="classTable">
    				 			<field id="WSDII"  value="com.ibm.btt.invoker.ws.dynamic.WSDynamicInvoker" />
    						
    			</kColl>
    
    			<field id="initializer" value="com.ibm.btt.invoker.InvokerInitializer"/>
    			<field id="extFile" value="invoker.xml"/>
    			
    		</kColl>
  2. Address web service definition in invoker.xml file. Define a web service named newWS:
    <WSDII id="newWS" wsdlURL="http://localhost:9080/BTTSOAModule2Web/wsdl/NewWSDLFileExport1_NewWSDLFileHttp_Service.wsdl"  operation="NewOperation" >		     
    	<parameters>
    		<wsDIIparameter id="input1"  />
    		<wsDIIparameter id="input2" type="String" />
    	</parameters>
    				 			
    	</WSDII> 

    The following table describes the parameters specified for WSDII Invoker:

    Table 1. Parameters specified for WSDII Invoker
    Parameter Description
    id The wsdl definition name, mandatory
    wsdlURL The wsdl url address, mandatory
    operation The operation which will be called in WSDL, mandatory
    wsDefinitionFile wsDefinitionFile can be defined in global default, or in specific invoker. If it is not defined in both locations, the Web service information is extracted dynamically at the first invocation. Optional.
    parameters wsDIIparameter, The parameter is only useful when mapping BTT Context to/from WSDL messages. The id must match with the operation paramName in wsDefinitionFile. Optional.
    id The parameter id, mandatory
    type The id data type, optional
  3. Following are three examples about how to call WSDII invoker:
    1. Call a Web service with simple message:
      The WSDL content is as follows:
      <wsdl:message name="NewOperationRequest">
               <wsdl:part name="NewOperationRequest" type="xsd:string"></wsdl:part>
                <wsdl:part name="NewOperationRequest1" type="xsd:string"></wsdl:part>
                <wsdl:part name="NewOperationRequest2" type="xsd:integer"></wsdl:part>
              </wsdl:message>
              <wsdl:message name="NewOperationResponse">
                <wsdl:part name="NewOperationResponse " type="xsd:integer"></wsdl:part>
              </wsdl:message>
              <wsdl:portType name="NewWSDLFile">
                <wsdl:operation name="NewOperation">
                  <wsdl:input message="tns:NewOperationRequest"/>
                  <wsdl:output message="tns:NewOperationResponse"/>
                </wsdl:operation>
              </wsdl:portType>
      The WSDII invoker definition is as follows:
      <WSDII id="newWS" wsdlURL=http://localhost:9080/BTTSOAModule2web/wsdl/NewWSDLFile.wsdl operation="NewOperation" />
      Following is the code to call the invoker:
      InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/invoker/ut/invoker.xml");
            Invoker inv2= ivf.createInvoker("newWS");
            Object result =  inv2.execute(new Object[]{"hello", "test", "123"});
            System.out.println("######## testInvoker2 Execute  result= "+result);
    2. Call a Web service with complex typed message by mapping data automatically:

      This example shows how to use BTT invoker utility API to map the data between BTT Context and Web service complex message. The rule of map is the name matching between the BTT data element and message part of WSDL on the same level.

      Following is the design view of the complex data: PurchaseOrderType.xsd:

      the design view of the complex data: PurchaseOrderType.xsd

      Following is BTT context data definition:
      <kColl id="Order_Data">
      <field id="orderData" />
      <field id="comment" />
      <kColl id="shipTo">
            	<field id="city" />
            	<field id="zip" />
            	<field id="street" />
      </kColl>
      <kColl id="billTo">
            	<field id="city" />
            	<field id="zip" />
            	<field id="street" />
      </kColl>
      <kColl  id="orderItems" >
                       <iColl id="item" size="2">
            	<kColl>
      	                  <field id="productName"/>
            		<field id="quantity" />
            		<field id="USPrice" />
            		<field id="shipDate" />
            		<field id="partNum"  />
            	</kColl>				
            	</iColl>
      </kColl>
      </kColl>
      The WSDII invoker definition is as follows:
      <WSDII id="purshOrderJaxBSampleWS" 
      wsdlURL="http://localhost:9083/WebServiceProviderWeb/wsdl/OrderSOAP.wsdl"  
      operation="NewOperation" >	
      <parameters>      							
      <wsDIIparameter id="NewOperationRequest" type="GenericDataObject"/> 
      </parameters> 				 		
      </WSDII>
      The following code shows how to call the Web service and how to use WSDynamicInvoker API: convertContexDataToGenericDataObject and convertGenericDataObjectToContext to map the data automatically between BTT context and complex data of Web Service.nult:
      Context diiTestCtx , diiTestTempCtx ;
            // init the diiTestCtx context data for WS request
            inv3=(WSDynamicInvoker) ivf.createInvoker("purshOrderJaxBSampleWS");
            WebServiceInfo wsinfo=((WSDynamicInvoker)inv3).getWsInfo();
            UserDefineTypeInfo invoker3UserType = wsinfo.getUserDefineTypeByName("PurchaseOrderType");
            invoker3ParameterValue = inv3.convertContexDataToGenericDataObject(inv3.getParameters().get("NewOperationRequest") , invoker3UserType, diiTestCtx);
            			 
            Object result = (WSDynamicInvoker) inv3.execute(new Object[]{ invoker3ParameterValue  });
            if (result instanceof GenericDataObject)
            	inv3.convertGenericDataObjectToContext(inv3.getParameters().get("NewOperationRequest"), invoker3UserType, (GenericDataObject) result, diiTestTempCtx) ;
    3. Call a Web service with complex typed message by filling data manually:
      Following is an example using the same Web service and invoker definition as described in Example b. The data is filled by manual application using populateDataObject API.
      inv3=(WSDynamicInvoker) ivf.createInvoker("purshOrderWS");
            WebServiceInfo wsinfo=((WSDynamicInvoker)inv3).getWsInfo();
            UserDefineTypeInfo invoker3UserType = wsinfo.getUserDefineTypeByName("PurchaseOrderType");
            UserDefineTypeInfo usaddressType = wsInfo.getUserDefineTypeByName("USAddress");
            UserDefineTypeInfo itemType = wsInfo.getUserDefineTypeByName("item");
      
            java.math.BigDecimal  dec=new java.math.BigDecimal(100085);
            GenericDataObject  shipTo= usaddressType.populateDataObject(new 
            Object[]{"king","Zhong Guan Chun Street","BJ","BJ",dec});
            GenericDataObject  shipFrom= usaddressType.populateDataObject(new Object[]{"wei", "hai 
            dian, lai zheng","BJ","BJ",dec});
            GenericDataObject  item1= itemType.populateDataObject(new Object[]{"cell phone", 10,399,"2007-10-21.});
            GenericDataObject[]  items= new GenericDataObject[]{item1}; 
            GenericDataObject paramDO= invoker3UserType.populateDataObject
            (new Object[]{ shipTo, shipFrom, "cell phone order", items });
            Object result = (WSDynamicInvoker) inv3.execute(new Object[]{ paramDO });