Using a specific URL structure, you must 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.
About this task
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 your custom feed:
- Open an empty file in a text editor, and paste the following
basic URL structure into the file:
http://host_name/wcs/resources/stores/storeId/plural_noun_name/identifier
- Replace the variables in the URL (shown in italic font)
with actual values for your feed.
- Add to the URL any optional query parameters to override
default parameters, if required. For example, your URL will require
the parameter
responseFormat=atom
to retrieve an
Atom feed.When you finish defining your 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 .
- 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 .
- Type a name for the file using the syntax name_of_noun.xml,
for example, Catalog.xml.
- Click Finish.
- Define your pattern input file in this file.
- Save the file.
- Right-click your pattern input file and select .
- In the Transformation section:
- Select the following ID, which is the JET RESTful Resource pattern:
com.ibm.commerce.toolkit.internal.pattern.rest
- Click Run.
The pattern generates the Java class that is the JAX-RS resource
and places it at the location specified in your pattern input file.
In certain cases, the generated Java class file might have
errors in the following lines, similar to this example:
import com.mycompany.commerce.catalog.facade.client.CatalogFacadeClient;
import com.mycompany.commerce.catalog.facade.client.CatalogException;
This
issue occurs if you are creating a feed for an existing noun and Web
service that WebSphere Commerce ships, rather than a custom noun and
Web service. If you get a similar error, open the generated Java class
file and change mycompany
to ibm
so
that the Java class file references the existing WebSphere Commerce FacadeClient
and Exception
class.
- Register the new Java class to the JAX-RS runtime:
- Open the properties file at this path:
WCDE_installdir/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.