Introduction
This sample demonstrates a pizza ordering scenario with backend services deployed in WSO2 Application Server (AS) to which we create APIs in WSO2 API Manager. Then, we invoke those APIs using a Web application deployed in WSO2 AS.
Prerequisites
Download and install WSO2 Application Server. For instructions, see Installation.
- As you run the Application Server on the same server as the API Manager, increment the default port of the Application Server to avoid port conflicts. To do this, go to
<AS_HOME>/repository/conf/carbon.xml
and change<Offset>2</Offset>.
Building the sample
Go to
<APIM_HOME>/samples/PizzaShack/pizza-shack-api
in command shell and runmvn clean install
to build the sample.Go to
<APIM_HOME>/samples/PizzaShack/pizza-shack-web
in command shell and runmvn clean install
.- See step 7 below if you are rebuilding the sample.
Executing the sample
- Log in to the API Publisher (https://localhost:9443/publisher) and create the following APIs.
Delivery API API Name= pizzaShack Context = /pizzashack/delivery Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/delivery API Resources =Keep the default values Order API API Name= pizzashack-order Context = /pizzashack/order Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/order API Resources =Keep the default values Menu API API Name= pizzashack-menu Context = /pizzashack/menu Version = 1.0.0 Production Endpoint URL=http://localhost:9765/pizzashack-api-1.0.0/api/menu API Resources =Keep the default values
- Navigate to the Lifecycles tab of each API and promote them to PUBLISHED state. This will push the APIs to the Gateway and they will be available for subscription in the API Store.
- Log in to the API Store (https://localhost:9443/store) and click on each API created earlier. Next, subscribe to each of them using the default application.
- After subscription, a message appears. Choose Go to My Subscriptions.
- The Subscriptions page opens. Create a production key by clicking the Generate button associated with it. You also have the option to increase the default token validity period, which is 1 hour.
You get the access token, a consumer key and a consumer secret. Replace the consumer key and secret pair in
<APIM_HOME>/samples/PizzaShack/pizza-shack-web/src/main/webapp/WEB-INF/web.xml
with the newly generated ones. For example,<context-param> <param-name>consumerKey</param-name> <param-value>szsHscDYLeKUcwA1GhPARQlflusa</param-value> </context-param> <context-param> <param-name>consumerSecret</param-name> <param-value>wJEfRDE3JeFnGMuwVNseNzsXM1sa</param-value> </context-param>
You now have three APIs subscribed under an application and an access token to the application. Next, we deploy a Web application in the Application Server and use it to invoke the APIs.
Rebuild the sample.
If you are rebuilding this sample, execute the following steps:
- Remove the following module from
<APIM_HOME>/samples/PizzaShack/pom.xml
file:<module>pre-processor</module>.
- Delete the
PizzaShack.zip
file from<APIM_HOME>/samples/PizzaShack.
- Go to
<APIM_HOME>/samples/PizzaShack
in command shell and runmvn clean install.
- Remove the following module from
Start WSO2 AS (https://localhost:9445/console) and log into its management console. For instructions, see AS documentation (If the AS documentation link doesn't load, please clear your browser cache and retry).
Deploy the following into the Application Server.
- <
APIM_HOME>/samples/PizzaShack/pizza-shack-web/target/pizzashack.war
<APIM_HOME>/samples/PizzaShack/pizza-shack-api/target/pizzashack-api-1.0.0.war
- <
After deploying, access the application using
http://localhost:9765/pizzashack
. It opens the application in a Web browser.- You can use this application to order pizza. Internally, the APIs get invoked when you use the application.