This documentation is for WSO2 App Factory 1.0.0. View documentation for the latest release.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Executing the Sample

 1. Create an a web 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. Checkout the cportal source code and the folder structure should be as follows:

Image Added

3. 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.

Image Added

Note: A sample index.jsp is attached with the above changes.    index.jsp

4. Commit the changes made.

5. Subscribe the application to the Weather API as follows:

  • Click on cportal application in Home page.
  • Click on 'Configure Resources' menu item.
  • Go under 'APIs' section and click 'Subscribe' button.
  • Go under 'Subscribe to an API' section and click 'Add Api' button.
  • You will be redirected to API Manager Homepage (https://apimanager.appfactorypreview.wso2.com/store/).
  • Click on 'twitter - 1.0.0' application.


  • Select cportal from 'Applications' drop down and click 'Subscribe' button. You will get the 'Subscription Successful' pop-up.

36. Generate keys for cportal from App Factory.

  •  Go under 'Subscribe to an API' section and click 'Add Api' button.
  •  Go under 'Saved Keys' section and click 'Generate Keys' button and keys will be generated for sandbox and production separately. 

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.

 

Code Block
themeEclipse
languagejava
linenumberstrue
{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

 67. Deploy the application to "Development" environment and add the endpoint and click 'Submit'.

     E.g: http://apimanager.appfactorypreview.wso2.com:8280/twitter/1.0.0/search.atom?q=wso2 

8. Promote the application to "Production" environment and view results.

Note: 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.