By using the CaslRest generator utility (CaslRestBuilder
), you can
include your own customized WebSphere Commerce REST services into the CaslRest library. Then,
you can test your custom REST services by using the CaslRest framework.
Procedure
-
In your Eclipse-based environment, open the Java perspective.
-
Update the
CaslRestBuilder
metadata with your new REST resources.
-
In the project explorer pane, expand the
CaslRestBuilder
project.
-
Click . Open the RestServicesSupp.json file.
-
At the top of the
restHandlersComponentMap
array, add an item for every new
REST resource you added.
The following is a code example of how a line might look:
{"componentName":"giftcenter", "type":"Wcs", "restType":"Bod", "handlers":[{"name":"UserContext"}]},
-
For the component name, replace the
giftcenter
with the name that you want to
refer your resource to in Java. This is generally a camel case version of the name, starting with a
lowercase letter, and without any underscores.
For example, the resource "my_resource"
in Swagger would become
"myResource"
. The name is arbitrary, so you can use what you want.
-
For the handlers list, replace the
UserContext
with what the resource is
called in the Swagger documentation.
Note: You must make it camel case and remove any underscores, using an uppercase for the first
letter.
For example, the same "my_resource"
resource would be
"MyResource"
for the handler name.
-
Putting it all together in an example, a Swagger resource called "my_resource" would look like
the following line of code:
{"componentName":"MyResource", "type":"Wcs", "restType":"Bod", "handlers":[{"name":"MyResource"}]},
-
Repeat these steps for every one new REST resource.
-
Run the generator utility against your WebSphere Commerce Server.
-
In the project explorer pane, expand the
CaslRestBuilder
project.
-
Right-click on
CaslRestBuilder
project, click .
-
In the left pane, scroll up, and click Java Applications.
-
From the top pane, click the New Launch icon.
A new run configuration is created for the generator.
- From the Main tab, click Search... for
the Main class.
- Search for
WebServicesApiParser
, click the result, then click
OK.
-
Click Augments.
-
Enter the program augments, replacing WC_HOST with your host name:
-wcHost WC_HOST --refresh-wc-lib --create-project -outputDir
../CaslRestLib-Wc -product wc
-
Click Run.
Wait for the execution to complete.
-
Refresh the
CaslRestLib-Wc
project to synchronize the changes in your
development environment.