Implementing a complex web service
You can implement a complex web service for complex operations such as deriving information from a Java™ API call.
Procedure
- Write and compile the code for creating a complex web service.
Use the Java API.
The following sample Java API creates a complex web service. It returns a WBSItem with a specified primary key from a catalog with the requested name. Because WBSItem is a complex class, you must create a WSDD for correct deployment within IBM® Product Master.
Main Class:public class ComplexSampleWebService { public WBSItem getItemFromCatalog(String catalogName, String primaryKey) throws Exception { Context ctx = null; try { ctx = PIMWebServicesContextFactory.getContext(); CatalogManager catalog_manager = ctx.getCatalogManager(); Catalog catalog = catalog_manager.getCatalog(catalogName); if (null == catalog) { throw new Exception("No Catalog found."); } else { Item item = catalog.getItemByPrimaryKey(primaryKey); if (item == null) { throw new Exception("No matching Item found."); } else { WBSItem wbsItem = new WBSItem(); wbsItem.setItemPK(item.getPrimaryKey()); wbsItem.setItemDisplayName(item.getDisplayName()); wbsItem.setCatalogName(catalogName); return wbsItem; } } } catch (Exception e) { e.printStackTrace(); throw new Exception(e.getMessage()); } } }
WBSItem Object Class:public class WBSItem { private String itemPK = null; private String itemDisplayName = null; private String attributeValue = null; private String catalogName = null; private int price = 0; public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public String getAttributeValue() { return attributeValue; } public void setAttributeValue(String attributeValue) { this.attributeValue = attributeValue; } public String getItemPK() { return itemPK; } public void setItemPK(String itemPK) { this.itemPK = itemPK; } public String getItemDisplayName() { return itemDisplayName; } public void setItemDisplayName(String itemDisplayName) { this.itemDisplayName = itemDisplayName; } public String getCatalogName() { return catalogName; } public void setCatalogName(String catalogName) { this.catalogName = catalogName; } }
The complex web service is created. - Prepare to deploy a complex web service to Product Master.
You need to generate the deploy.wsdd file for deployment. You can use Java2WSDL, and then WSDL2Java to create the sample deploy.wsdd file.
- Run Java2WSDL on the Java API
to generate WSDL.
You can use the WBSItem to generate the WSDD for Product Master.
java org.apache.axis.wsdl.Java2WSDL -o wp.wsdl -l "http://192.168.0.1:9080/services/ComplexSampleWebService" -n "http://tests.ibm.com" com.ibm.tests.ComplexSampleWebService -y WRAPPED -u LITERAL
- Run WSDL2Java on the generated WSDL.
java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -S true wp.wsdl
- Edit the WSDD.
<ati:deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:ati="http://xml.apache.org/axis/wsdd/"> <ati:service name="ComplexSampleWebService" provider="java:WPCDocument" style="wrapped" use="literal"> <ati:parameter name="wsdlTargetNamespace" value="http://tests.ibm.com"/> <ati:parameter name="wsdlServiceElement" value="ComplexSampleWebServiceService"/> <ati:parameter name="wsdlServicePort" value="ComplexSampleWebService"/> <ati:parameter name="className" value="com.ibm.tests.ComplexSampleWebService"/> <ati:parameter name="wsdlPortType" value="ComplexSampleWebService"/> <ati:parameter name="allowedMethods" value="*"/> <ati:parameter name="scope" value="Session"/> <ati:typeMapping xmlns:ns="http://tests.ibm.com" qname="ns:WBSItem" type="java:com.ibm.tests.WBSItem" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle=""/> /ati:service> </ati:deployment>
- Run Java2WSDL on the Java API
to generate WSDL.