Tutorials > Web services > Define a User Registration Web Service

< Previous | Next >


Create a Web service ConfirmBOD responses JSP page

When executing the business logic, there are two types of responses that can be returned. Both responses comply with the OAGIS ConfirmBOD schema definition but only one response is used to show a successful execution of the service operation while the other represents a failure of the service operation. In the case of a successful operation, the confirmation response would return the internal WebSphere Commerce identifier of the customer and, in the case of a failure operation, the confirmation should indicate the error for why the request failed. In this section, the process of defining both JSP templates will be described.

Since the ConfirmBOD schema is quite verbose and the result of this service request does not require most of the elements in this schema, it is recommended to use the Rational XML tooling to generate a template for success and failure message. By using the tooling, a skeleton of the JSP template can be created to contain only the information from each response.Without the assistance of the tooling, it can be rather difficult to determine what elements of the confirmation response to include.

The following steps demonstrate how to create the ConfirmBOD template for successful execution using the Rational XML Tooling.


Procedure

  1. In the Stores project, create the MyCompany folder under the WebContent/webservices directory if one does not already exist. For example, navigate to the webservices folder, right-click the folder, and select New > Folder.

  2. In the WebServicesRouter project, find and select the WebContent/xsd/OAGIS/9.0/BODs/Developer/ConfirmBOD.xsd.

  3. Right-click the ConfirmBOD.xsd and select Generate > XML File.

  4. In the wizard to generate a new XML file, navigate to the WebContent/webservices/MyCompany folder.

  5. In the File name field, type ConfirmSyncCustomerSuccessBOD.xml and click Next. Note: Unlike in the inbound Web service tutorial, the generated file in this tutorial will have a .xml extension. This will allow you to open the file with the Rational XML Editor.

  6. In the Select Root Element window:

    1. In the Root Element field, select ConfirmBOD.

    2. Change the namespace prefix for the OAGIS namespace to oa.

      1. Select the default prefix and click the Edit button.

      2. In the Prefix field, type oa and click OK.

    3. Ensure the check boxes to create optional elements and optional attributes are unchecked.Click Finish to create the XML template.

  7. Repeat steps 2-5 to create a ConfirmSyncCustomerErrorBOD.xml template that will be used to when the web service operation fails.

  8. Open the ConfirmSyncCustomerSuccessBOD.xml file with the XML Editor to add the elements to be included with a successful confirmation of the service request.

  9. Use the XML Editor, create the following XPath attributes and elements to the success confirmation:

    ConfirmBOD/DataArea/BOD/BODSuccessMessage/UserArea/ReviewerContact/ID
    ConfirmBOD/DataArea/BOD/BODSuccessMessage/UserArea/ReviewerContact/Name
    

    1. In the Outline view, expand oa:ConfirmBOD >oa:DataArea > oa:BOD.

    2. Right-click oa:BOD and select Add Child > oa:BODSuccessMessage.

    3. Right-click oa:BODSuccessMessage and select Add Child > oa:UserArea.

    4. Right-click oa:UserArea and select Add Child > oa:ResourceCodes - oa:ReviewerContact > oa:ReviewerContact.

    5. Right-click oa:ReviewerContact and select select Add Child > oa:ID.

    6. Right-click oa:ReviewerContact and select select Add Child > oa:Name.

  10. Open the ConfirmSyncCustomerErrorBOD.xml file with the XML Editor. Using the XML Editor, we will add elements that will be included with a failure confirmation of the service request.

  11. Use the XML Editor, create the following XPath attributes and elements to the failure confirmation.

    ConfirmBOD/DataArea/BOD/BODFailureMessage/ErrorProcessMessage/ID
    ConfirmBOD/DataArea/BOD/BODFailureMessage/ErrorProcessMessage/Description
    ConfirmBOD/DataArea/BOD/BODFailureMessage/ErrorProcessMessage/Note
    ConfirmBOD/DataArea/BOD/BODFailureMessage/ErrorProcessMessage/Type
    ConfirmBOD/DataArea/BOD/BODFailureMessage/ErrorProcessMessage/ReasonCode
    

    1. In the Outline view, expand oa:ConfirmBOD >oa:DataArea > oa:BOD.

    2. Right-click oa:BOD and select Add Child > oa:BODFailureMessage.

    3. Right-click oa:BODFailureMessage and select Add Child > oa:ErrorProcessMessage.

    4. Right-click oa:ErrorProcessMessage and select Add Child > oa:ID.

    5. Repeat step d to add oa:Description, oa:Note, oa:Type, and oa:ReasonCode.

  12. Rename both XML files with a .jsp extension instead of the .xml extension.

  13. Add the JSP code to ConfirmSyncCustomerSuccessBOD.jsp to represent the result of the web service operation. For the success confirmation, add the user identifier and distinguish name in the review id and name elements. The JSP can be...


    Note: Remove the <?xml..?> tag from the JSP because the template XML will be appended to the SOAP response and this tag will invalidate the resulting XML response.

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <oa:ConfirmBOD releaseID="9.0"
          xmlns:oa="http://www.openapplications.org/oagis/9"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.openapplications.org/oagis/9 ../../../../WebServicesRouter/WebContent/xsd/OAGIS/9.0/BODs/Developer/ConfirmBOD.xsd ">      
    <oa:ApplicationArea>            
    <oa:CreationDateTime/>      
    </oa:ApplicationArea>      
    <oa:DataArea>            
    <oa:Confirm />            
    <oa:BOD>                  
    <oa:OriginalApplicationArea>                        
    <oa:CreationDateTime/>                  
    </oa:OriginalApplicationArea>                  
    <oa:BODSuccessMessage>                        
    <oa:UserArea>                              
    <oa:ReviewerContact>                                    
    <oa:ID><c:out value="${CommandContext.userId}" /></oa:ID>                                    
    <oa:Name><c:out value="${CommandContext.user.distinguishedName}" /></oa:Name>                              
    </oa:ReviewerContact>                        
    </oa:UserArea>                  
    </oa:BODSuccessMessage>            
    </oa:BOD>      
    </oa:DataArea>
    </oa:ConfirmBOD>
    

    Add the JSP code to the ConfirmSyncCustomerErrorBOD.jsp to represent the result of the service operation. For the failure confirmation, add the error information associated with the business operation to the ErrorProcessMessage elements. The JSP can be...


    Note: Ensure to remove the <?xml..?> tag from the JSP because the template XML will be appended to the SOAP response and the this tag will cause invalidate the resulting XML response.

    <%
          com.ibm.commerce.beans.ErrorDataBean errorBean = new com.ibm.commerce.beans.ErrorDataBean ();       com.ibm.commerce.beans.DataBeanManager.activate(errorBean, request, response); 
          String id = errorBean.getECMessage().getSystemMessageIdentifier();       String reasonCode = errorBean.getErrorCode();       String type = errorBean.getExceptionType();       String note = errorBean.getCorrectiveActionMessage();       
          String message = errorBean.getSystemMessage();       if(message == null || message.trim().length() == 0) {
                message = errorBean.getMessage();       }
    %>
    <oa:ConfirmBOD releaseID="9.0"
          xmlns:oa="http://www.openapplications.org/oagis/9"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.openapplications.org/oagis/9 ../../../../WebServicesRouter/WebContent/xsd/OAGIS/9.0/BODs/Developer/ConfirmBOD.xsd ">      
    <oa:ApplicationArea>            
    <oa:CreationDateTime/>      
    </oa:ApplicationArea>      
    <oa:DataArea>            
    <oa:Confirm />            
    <oa:BOD>                  
    <oa:OriginalApplicationArea>                        
    <oa:CreationDateTime/>                  
    </oa:OriginalApplicationArea>                  
    <oa:BODFailureMessage>                        
    <oa:ErrorProcessMessage>                              
    <oa:ID><%= id %></oa:ID>                              
    <oa:Description><%= message %></oa:Description>                              
    <oa:Note><%= note %></oa:Note>                              
    <oa:Type><%= type %></oa:Type>                              
    <oa:ReasonCode><%= reasonCode %></oa:ReasonCode>                        
    </oa:ErrorProcessMessage>                  
    </oa:BODFailureMessage>            
    </oa:BOD>      
    </oa:DataArea>
    </oa:ConfirmBOD>
    

Now that the JSP templates used to represent the SyncCustomer web service are created, the final step required for creating the web service is to register the JSP as shown in the next section.

< Previous | Next >


+

Search Tips   |   Advanced Search