Tutorials > Web services > Define an inbound Web service

< Previous | Next >


Create a Web service response JSP page

The WebSphere Commerce Web services framework uses JSP pages to create the responses to the Web service requests. The JSP pages generate the response document that matches the Web service definition. In creating response JSP pages, two activities are involved. One activity (described in this section) is creating the JSP template to generate the Web service response. The other activity (described in the next section) is registering the JSP page in the Struts configuration so that it can be picked up by the WebSphere Commerce Web services framework.

Create the Web service response JSP page is the same as creating any other JSP page, except that the response format will be an XML document that matches the XML schema definition. The typical data beans and other JSP programming concepts can be used to generate JSP responses. As an additional benefit, you can use the Rational XML tools to generate the skeleton of the JSP page; you just need to implement the logic to obtain the dynamic content.


Procedure

  1. Navigate to Stores > WebContent > webservices. Right-click webservices and select New > Folder. In the Folder name field, type MyCompany and click Finish.

  2. Select the XSD file that contains the schema definition of the web service response. For this tutorial, the file name should be xsd/MyCompany/ProductInformationServices.xsd found in the WebServicesRouter project.

  3. Right-click the XML schema definition and select Generate > XML File.

  4. A wizard opens. Specify the location for the generated XML document. Since JSP files are located in the Stores project, you should type Stores/WebContent/webservices/MyCompany in the Enter or select the parent folder field.

  5. In the File name field, type ShowProductInformation.jsp.

  6. Click Next. The Select Root Element page is displayed.

  7. In the Root element field, select ShowProductInformation from the list.

  8. Under Content options, select all the check boxes.

  9. Click Finish. The JSP page is created. This JSP page is just a skeleton of the XML document and needs the logic to add the appropriate content.

  10. Open the Source view of the XML editor.

  11. Remove the <?xml .. ?> tag from the generated XML source. This tag will cause the response to fail because it is redundant.

  12. Modify the generated XML template by adding the required JSP elements to provide the dynamic content. For this example of retrieving product information, the Product DataBean element is used. The request will loop though the product SKU that is specified and will populate the product information that is defined by the XML schema. Your ShowProductInformation.jsp file should look like the following:

    <% response.setContentType("text/xml"); %>
    <% response.setCharacterEncoding("UTF-8"); %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://commerce.ibm.com/base" prefix="wcbase" %> 
    <myco:ShowProductInformation
          xmlns:myco="http://www.mycompany.com/schema"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.mycompany.com/schema" >       
    <c:forEach var="productSKU" items="${paramValues.productSKU}">  
    <c:remove var="product"/>  
    <wcbase:useBean id="product" 
    classname="com.ibm.commerce.catalog.beans.ProductDataBean" scope="request">    
    <c:set target="${product}" property="productID" value="${productSKU}"/>  
    </wcbase:useBean>  
    <Product>    
    <ProductSKU>      
    <c:out value="${product.partNumber}"/>    
    </ProductSKU>    
    <ProductName>      
    <c:out value="${product.description.name}" escapeXml="false"/>    
    </ProductName>    
    <ShortDescription>      
    <c:out value="${product.description.shortDescription}" escapeXml="true"/>    
    </ShortDescription>    
    <LongDescription>      
    <c:out value="${product.description.longDescription}" escapeXml="true"/>    
    </LongDescription>    
    <Availability>In Stock</Availability>    
    <SuggestedRetailPrice>      
    <c:out value="${product.listPrice}" escapeXml="true"/>    
    </SuggestedRetailPrice>  
    </Product>
    </c:forEach>
    </myco:ShowProductInformation>
    

  13. To test the JSP page:

    1. Start WebSphere Commerce Test Server.

    2. Open a browser and type the following URL: http://localhost/webapp/wcs/admin/servlet/db.jsp. This will open an SQL session to the database.

    3. In the SQL window type the following SQL command:

      SELECT * FROM STORE;
      

    4. Find the store ID.

    5. Open a browser and log on to the store.

    6. Test the JSP page by pasting the following URL into a browser: http://localhost/webapp/wcs/stores/servlet/webservices/MyCompany/ShowProductInformation.jsp?storeId=yourStoreId&productSKU=10255&productSKU=10259

< Previous | Next >


+

Search Tips   |   Advanced Search