Implementing a simple web service

You can deploy simple web services on IBM® Product Master without any customization of WSDD (Web Services Deployment Descriptor) or WSDL. Simple web services must use only simple types such as string and int.

About this task

You can create simple web services in addition to writing web services that access the Product Master Java™ API.

Procedure

Implement the web service. Use one of the following methods: Java or script.
Option Description
Java The following sample code creates a simple web service that returns the number of items in a catalog.
public class SimpleSampleWebService
{

    public int getNumberOfItemsInCatalog(String catalogName)
    {
        Context ctx = null;
        try
        {
            ctx = PIMWebServicesContextFactory.getContext();
            CatalogManager catalog_manager = ctx.getCatalogManager();
            Catalog catalog = catalog_manager.getCatalog(catalogName);
            if (null == catalog)
            {
                return -1;
            }
            else
            {
                Collection items = catalog.getItems();
                if (items == null)
                {
                    return 0;
                }
                else
                {
                    return items.size();
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        return -2;
    }
}
Script
The following sample code creates a script-based web service.
// Search a given catalog for the items that have the given attribute 
// with a value containing the given value string.
function getListOfMatchingItems(catalogName, attributePath, attributeValue)
{
      var pkList = [];
      catchError(e) {
          var query = " select item.pk from catalog('" + catalogName + "')\n"
                    + "  where item['" + attributePath + "'] like '%" + attributeValue + "%'\n" ;
          var qry = new SearchQuery(query);
          var rs = qry.execute();
          if (rs.size() > 0) {
              var i = 0; 
              while (rs.next()) {
                  pkList[i] = rs.getString(1);
                  i = i+1;
              }
          } else {
          	  pkList[0] = "Item not found";
          }
      }
      if (e != null) {
          pkList[0] = "Exception occurred. Item not found: " + e;
      }
      
      return pkList;
}

// parse the request document
var doc = new XmlDocument(soapMessage);

// get the ticker parameter
var ctgName = parseXMLNode("catalogName");
var attrPath = parseXMLNode("attributePath");
var attrValue = parseXMLNode("attributeValue");
var pks = getListOfMatchingItems(ctgName, attrPath, attrValue);
out.println("<getListOfMatchingItemsResponse xmlns=\"\">");
for(var i = 0; pks[i] != null; i=i+1)
{
	out.println("  <getListOfMatchingItemsReturn>" + pks[i] + "</getListOfMatchingItemsReturn>");
}
out.println("</getListOfMatchingItemsResponse>");
The simple web service is implemented.

What to do next

Next, deploy the web service.