Creating a Web service response JSP page
In this tutorial lesson, you are defining the Web service response JSP pages. When your Web service executes, either a successful execution or a failure of the operation response returns. In this lesson, you are creating the template for these success and a failure message.
About this task
When executing the business logic, there are two types of responses that can be returned. The responses comply with the OAGIS ConfirmBOD schema definition. One response is used to show a successful execution of the service operation while the other represents a failure of the service operation. In a successful operation, the confirmation response would return the internal WebSphere Commerce identifier of the customer. In a failure operation, the confirmation indicates the error for why the request failed. In this section, the process of defining both JSP templates is described.
The ConfirmBOD schema is 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.
The following steps demonstrate how to create the ConfirmBOD template for successful execution with the Rational XML Tooling.
Procedure
- Create a MyCompany folder in the Stores project,
if one does not exist:
- In the Enterprise Explorer view, navigate to Stores/WebContent/webservices.
- Right-click the webservices folder; select New > Folder.
- Name the folder MyCompany.
- Generate a ConfirmSyncCustomerSuccessBOD.xml XML
file template:
- Navigate to WebServicesRouter/WebContent/xsd/OAGIS/9.0/BODs/Developer.
- Right-click the ConfirmBOD.xsd file; select Generate > XML File.
- In the New XML File dialog, for the Enter or select the parent folder, enter Stores/WebContent/webservices/MyCompany as the parent folder.
- For the File name, enter ConfirmSyncCustomerSuccessBOD.xml as the name.
- Click Next.
- In the Select Root Element dialog, for the Root element, select ConfirmBOD.
- For the Namespace Information, select the default Prefix p; click the Edit... button.
- In the New Namespace Information dialog, For the Prefix, enter oa. Click OK.
- Ensure the options to Create optional attributes or Create optional elements are not selected.
- Click Finish to create the XML template.
- Repeat step 2 to create a ConfirmSyncCustomerErrorBOD.xml XML template. This template is used when the Web service operation fails.
- Edit the ConfirmSyncCustomerSuccessBOD.xml file
to add the elements to be included with a successful confirmation
of a service request.You are creating the following XPath attributes and elements to the success confirmation:
ConfirmBOD/DataArea/BOD/BODSuccessMessage/UserArea/ReviewerContact/ID ConfirmBOD/DataArea/BOD/BODSuccessMessage/UserArea/ReviewerContact/Name
- Navigate to Stores/WebContent/webservices/MyCompany.
- Right-click the ConfirmSyncCustomerSuccessBOD.xml file; select Open With > XML Editor.
- In the
Outline
view, expand oa:ConfirmBOD/oa:DataArea/oa:BOD. - Right-click
oa:BOD
; select Add Child > New Element. Enter oa:BODSuccessMessage for the element name. - Right-click
oa:BODSuccessMessage
; select Add Child > New Element. Enter oa:UserArea for the element name. - Right-click
oa:UserArea
; select Add Child > New Element. Enter oa:ReviewerContact for the element name. - Right-click
oa:ReviewerContact
; select Add Child > New Element. Enter oa:ID for the element name. - Right-click
oa:ReviewerContact
; select Add Child > New Element. Enter oa:Name for the element name. - Save your changes and close the file.
- Edit the ConfirmSyncCustomerErrorBOD.xml file
to add the elements to be included with a failure confirmation of
a service request:You are creating the following XPath attributes and elements to the success 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
- Right-click the ConfirmSyncCustomerErrorBOD.xml file; select Open With > XML Editor.
- In the
Outline
view, expand oa:ConfirmBOD/oa:DataArea/oa:BOD. - Right-click
oa:BOD
; select Add Child > New Element. Enter oa:BODFailureMessage for the element name. - Right-click
oa:BODFailureMessage
; select Add Child > New Element. Enter oa:ErrorProcessMessage for the element name. - Right-click
oa:ErrorProcessMessage
; select Add Child > New Element. Enter oa:ID for the element name. - Repeat steps 5.e. to create the XML elements
oa:Description
,oa:Note
,oa:Type
, andoa:ReasonCode
. - Save your changes and close the file.
- Rename ConfirmSyncCustomerSuccessBOD.xml and ConfirmSyncCustomerErrorBOD.xml with a .jsp extension instead of the .xml extension. Your modified files are now named ConfirmSyncCustomerSuccessBOD.jsp and ConfirmSyncCustomerErrorBOD.jsp
- 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.
- Right-click ConfirmSyncCustomerSuccessBOD.jsp; select Open.
- Click the Source tab.
- Remove the
<?xml..?>
tag from the JSP because the template XML is appended to the SOAP response and this tag invalidates the resulting XML response. - Add the following code to the beginning of your JSP:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- Add the user identifier and distinguish name in the
review ID and Name elements.
<oa:ID><c:out value="${CommandContext.userId}" /></oa:ID> <oa:Name><c:out value="${CommandContext.user.distinguishedName}" /></oa:Name>
- Ensure that your JSP code resembles the following code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <oa:ConfirmBOD releaseID="" xmlns:clm54217="http://www.openapplications.org/oagis/9/currencycode/54217:2001" xmlns:clm5639="http://www.openapplications.org/oagis/9/languagecode/5639:1988" xmlns:clm66411="http://www.openapplications.org/oagis/9/unitcode/66411:2001" xmlns:clmIANAMIMEMediaTypes="http://www.openapplications.org/oagis/9/IANAMIMEMediaTypes:2003" xmlns:oa="http://www.openapplications.org/oagis/9" xmlns:p1="http://www.openapplications.org/oagis/9/codelists" xmlns:qdt="http://www.openapplications.org/oagis/9/qualifieddatatypes/1.1" xmlns:udt="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" 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:CreationDateTime</oa:CreationDateTime> </oa:ApplicationArea> <oa:DataArea> <oa:Confirm /> <oa:BOD> <oa:OriginalApplicationArea> <oa:CreationDateTime>oa:CreationDateTime</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 ConfirmSyncCustomerErrorBOD.jsp to
represent the result of the Web service operation.
- Right-click ConfirmSyncCustomerErrorBOD.jsp; select Open.
- Remove the
<?xml..?>
tag from the JSP because the template XML is appended to the SOAP response and this tag invalidates the resulting XML response. - Add the error information to the beginning of your JSP
to associate the business operation to the
ErrorProcessMessage
elements.<% 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(); } %>
- Add the values for your
ErrorProcessMessage
elements:<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>
- Ensure that your JSP code resembles the following code:
<% 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="" xmlns:ao="http://www.openapplications.org/oagis/9" xmlns:clm54217="http://www.openapplications.org/oagis/9/currencycode/54217:2001" xmlns:clm5639="http://www.openapplications.org/oagis/9/languagecode/5639:1988" xmlns:clm66411="http://www.openapplications.org/oagis/9/unitcode/66411:2001" xmlns:clmIANAMIMEMediaTypes="http://www.openapplications.org/oagis/9/IANAMIMEMediaTypes:2003" xmlns:p1="http://www.openapplications.org/oagis/9/codelists" xmlns:qdt="http://www.openapplications.org/oagis/9/qualifieddatatypes/1.1" xmlns:udt="http://www.openapplications.org/oagis/9/unqualifieddatatypes/1.1" 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:CreationDateTime</oa:CreationDateTime> </oa:ApplicationArea> <oa:DataArea> <oa:Confirm /> <oa:BOD> <oa:OriginalApplicationArea> <oa:CreationDateTime>oa:CreationDateTime</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>
Results
You have created the JSP templates used to represent the SyncCustomer web service. The final step required for creating the web service is to register the JSP as shown in the next section.