The sample is described in the following topics.
Introduction
This sample invokes twitter API and display results in a web app.
Prerequisites
Need to access the appfactorypreview.wso2.com. We need to publish an API first in API Manager. You can create a API that gives Washington whether details in sandbox and London whether details in the production environment.
Executing the Sample
1. Create an application in AppFactory. Lets call it Customer Portal - cportal application. When you create an application in App Factory it will be automatically created in API-M.
2. Subscribe the application to the Weather API as follows.
3. Generate keys by clicking on the create dependencies.
4. Write your application to get keys by calling the CarbonContext and Registry APIs. The correct sandbox and production keys will be used depending on where the application is deployed. Here is the code to do that. Take the samples and commit it to your application location.
{applicationName} CarbonContext cCtx = CarbonContext.getCurrentContext(); Registry registry = (Registry) cCtx.getRegistry(RegistryType.SYSTEM_GOVERNANCE); Resource resource = registry.get("Key"); if(resource.getContent() instanceof String){ key = (String) resource.getContent(); }else{ key = new String((byte[]) resource.getContent()); }
5. Deploy the application to "Development" environment and view results
6. Promote the application to "Production" environment and view results.
The results of Development environment differs from Production environment because the keys that is used by the two environments are different. The programmer is unaware about the sandbox and production keys, and everything is handled underneath.