Develop > Presentation layer > Work with Web service feeds > Create a custom feed from a Web service
Define the URL and creating the Java class for the feed
Use a specific URL structure, define the URL for the RESTful HTTP Get request to retrieve data from the Web service. You must define the URL so that you can use certain data in the URL to create the Java class that supports the feed. When the customization is complete, the URL you define will display the Atom feed if you paste it into a feed reader or browser that supports Atom feeds.
Before you begin
- Review URL structure for Web service feeds so that you understand how to define the URL for the feed.
- Review JET RESTful Resource pattern input file and the Java class it generates so that you understand the format of a pattern input file and the variables it must contain.
- Check whether you have the Java Emitter Template (JET) package installed for WebSphere Commerce Developer. You require this package to run the pattern in this procedure. See Install the Java Emitter Template (JET) package.
To generate the required Java class file, WebSphere Commerce provides a pattern that uses a Java Emitter Template (JET). You provide XML input to the pattern using data from the URL you define, and the pattern generates the Java class that is the JAX-RS resource. This saves you from having to create the Java class yourself.
Procedure
- Define the URL for the custom feed:
- Open an empty file in a text editor, and paste the following basic URL structure into the file:
http://host/wcs/resources/stores/storeId/plural_noun_name/identifier
- Replace the variables in the URL (shown in italic font) with actual values for the feed. For information about the variables and for example URLs, see URL structure for Web service feeds.
- Add to the URL any optional query parameters to override default parameters, if required. For example, the URL will require the parameter responseFormat=atom to retrieve an Atom feed.
When you finish defining the URL, the result might look similar to this example, which returns an Atom feed containing data from the Catalog noun for a specific catalog that has an external ID of 99999:
http://mysite.example.com/wcs/resources/stores/10101/Catalogs/99999?responseFormat=atom
- Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
- Create the pattern input file:
- Right-click the WebSphereCommerceServerExtensionsLogic project and select New > Folder.
- Type RestInterfaceDefinition as the folder name. This creates a single location to store all RESTful Resource pattern input files.
- Right-click the RestInterfaceDefinition folder and select New > File.
- Type a name for the file using the syntax name_of_noun.xml, for example, Catalog.xml.
- Click Finish.
- Define the pattern input file in this file. For more information, see JET RESTful Resource pattern input file and the Java class it generates.
- Save the file.
- Right-click the pattern input file and select Run As > Input for Jet Transformation.
- In the Transformation section:
The pattern generates the Java class that is the JAX-RS resource and places it at the location specified in the pattern input file.
- Select the following ID, which is the JET RESTful Resource pattern:
com.ibm.commerce.toolkit.internal.pattern.rest
- Click Run.
- Register the new Java class to the JAX-RS runtime:
- Open the properties file at this path:
WCDE_INSTALL/workspace/Rest/WebContent/WEB-INF/config/resources-ext.properties
- In the properties file, add the fully qualified name of the Java class the pattern created, for example:
com.mycompany.commerce.Catalog.rest.resources.Catalog
- Save and close the file.
- Restart the WebSphere Commerce server.
Next topic: Create the Atom feed representation of the service
Related tasks
Install the Java Emitter Template (JET) package