Thursday, June 25, 2015



Closure compiler is a great tool which can be used to compress or minify JavaScripts. It easily out performs yui library. You can read more about Closure from here.

Recently I was trying to compile a third party JS library specifically swagger-ui.js. When compiling the code it produced humongous amounts of errors. Since I could not correct all of the errors since the outcome is unclear I had to compile the code by ignoring some errors I faced.

This is one error I faced.


ERROR - Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option.
            'dblclick .curl': 'selectText',
                                          ^

So in this post I'll explain hoe to ignore theses errors when compiling. In closure you can do this by parsing the --jscomp_off flag. Following is an example for this.



java -jar compiler.jar --jscomp_off=suspiciousCode --js swagger-ui.js --js_output_file swagger-ui2.js


You see "suspiciousCode" parameter I'm parsing, this is a predefined error class thats in closure. Inorder to get a list of error classes you can view the help section as shown below.



java -jar compiler.jar --help


This will give the following list under --jscomp_off

Turn off the named class of warnings.
                                          Options:accessControls, ambiguousFunct
                                          ionDecl, checkEventfulObjectDisposal,
                                          checkRegExp, checkStructDictInheritanc
                                          e, checkTypes, checkVars, conformanceV
                                          iolations, const, constantProperty,
                                          deprecated, deprecatedAnnotations,
                                          duplicateMessage, es3, es5Strict,
                                          externsValidation, fileoverviewTags,
                                          globalThis, inferredConstCheck,
                                          internetExplorerChecks, invalidCasts,
                                          misplacedTypeAnnotation, missingGetCss
                                          Name, missingProperties, missingProvid
                                          e, missingRequire, missingReturn,newCh
                                          eckTypes, nonStandardJsDocs, reportUnk
                                          nownTypes, suspiciousCode, strictModul
                                          eDepCheck, typeInvalidation, undefined
                                          Names, undefinedVars, unknownDefines,
                                          uselessCode, useOfGoogBase, visibility


So what if you need to ignore multiple errors when compiling? This is easy you can parse multiple flags as shown below. 


java -jar compiler.jar --jscomp_off=suspiciousCode --jscomp_off=internetExplorerChecks --js swagger-ui.js --js_output_file swagger-ui2.js


In closure you also can define your own error classes and groups. This will allow you to ignore any custom errors that are being generated. 

Monday, June 22, 2015



When it comes to Automating API Creation in Api Manager there two methods you can follow. One is to use the ApiPublisher Api provided to add an API. This is well documented here. Other way is t use the Design Implement and publish phases to create the API just like creating an API from the UI. So here are some samples commands to be used to create a API. Please note I'm using Api Manager 1.8 and these parameters may vary in other versions.

Creating an API with Publisher API

Make sure you login to Api Manager first with the following command.

curl -X POST -c cookies http://localhost:9763/publisher/site/blocks/user/login/ajax/login.jag -d 'action=login&username=admin&password=admin'

Now create the API by parsing the session cookie

curl -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-add/ajax/add.jag -d 'action=addAPI&name=MyNewAPI6&visibility=public&version=1.0&description=My New API created and published by curl&endpointType=secured&http_checked=&https_checked=https&wsdl=&tags=automated published&tier=Gold&thumbUrl=https://pbs.twimg.com/profile_images/493735622587064320/z7qZUG0E_bigger.png&context=/apicurl6&tiersCollection=Gold,Silver,Bronze,Unlimited&resourceCount=5&resourceMethod-0=GET&resourceMethodAuthType-0=Application,Application User&resourceMethodThrottlingTier-0=Unlimited&uriTemplate-0=/assignments&resourceMethod-1=OPTIONS&resourceMethodAuthType-1=None&resourceMethodThrottlingTier-1=Unlimited&uriTemplate-1=/assignments&resourceMethod-2=GET&resourceMethodAuthType-2=Application,Application User&resourceMethodThrottlingTier-2=Unlimited&uriTemplate-2=/journeys&resourceMethod-3=OPTIONS&resourceMethodAuthType-3=None&resourceMethodThrottlingTier-3=Unlimited&uriTemplate-3=/journeys&resourceMethod-4=GET&resourceMethodAuthType-4=Application,Application User&resourceMethodThrottlingTier-4=Unlimited&uriTemplate-4=/info&resourceMethod-5=OPTIONS&resourceMethodAuthType-5=None&resourceMethodThrottlingTier-5=Unlimited&uriTemplate-5=/info' -d 'endpoint_config={"production_endpoints":{"url":"https://internal-mysampleapi.com:9443","config":null}, "sandbox_endpoints": {"url":"https://internal-mysampleapi.com:9443/mock","config":null},"endpoint_type":"http"}'

The above command will create the API successfully.

Creating the API with Normal Creating Flow

Design Call

curl -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F context="/myapiycr555555context" -F visibility="public" -F roles="" -F apiThumb="" -F description="" -F tags="testtag" -F action="design" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & Application User","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

Implement Call

curl -F implementation_methods="endpoint" -F endpoint_type="http" -F endpoint_config='{"production_endpoints":{"url":"http://appserver/resource/ycrurlprod","config":null},"endpoint_type":"http"}' -F production_endpoints="http://appserver/resource/ycrurlprod" -F sandbox_endpoints="" -F endpointType="nonsecured" -F epUsername="" -F epPassword="" -F wsdl="" -F wadl="" -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F action="implement" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & ApplicationUser","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

Publish and Manage Call



curl -F default_version_checked="" -F tier="Unlimited" -F transport_http="http" -F transport_https="https" -F inSequence="none" -F outSequence="none" -F faultSequence="none" -F responseCache="disabled" -F cacheTimeout="300" -F subscriptions="current_tenant" -F tenants="" -F bizOwner="" -F bizOwnerMail="" -F techOwner="" -F techOwnerMail="" -F name="myapiycr555555" -F version="1.0" -F provider="admin" -F action="manage" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/myapiycr555555context/1.0","swaggerVersion":"1.2","resourcePath":"/test","apis":[{"index":0,"path":"/test","operations":[{"nickname":"get_test","auth_type":"Application & ApplicationUser","throttling_tier":"Unlimited","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_test","auth_type":"None","throttling_tier":"Unlimited","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/test"}],"info":{"title":"myapiycr555555","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -F outSeq="" -F faultSeq="json_fault" -F tiersCollection="Unlimited" -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

The above commands will also create the API successfully.

Tuesday, June 16, 2015



Some times you may accidentally delete an Api from the carbon management console. If you delete an API from Management console (Which is not the correct way) It will only delete API related metadata. Some of the data related to that API won't get removed from APi Manager tables. This will corrupt the Database and result in errors.

The recommended way of deleting an API is to use the APIM Publisher application and delete it. This will remove all information related to the API. And if there are subscriptions for that API, it will inform you to unsubscribe it first (these won't happen if you use the management console. It is only provided for management tasks such as user management, etc)
Following is a list of things you need to do to completely remove the api from the API manager 1.8.

Please keep a backup of the database and any other resources before you do this.
Step 1 - Remove subscriptions of that api.
1. execute following query to get the application related information (You will need the APPLICATION_ID value to unsubscribe an API from that application)
SELECT * FROM AM_APPLICATION;
2. execute following query to get the API related information (You will need the API_ID value to unsubscribe an API from an application)
SELECT * FROM AM_API;
3. execute following to delete the subscription (Set the necessary ids. If you do not know which Application id to use, the use all ids from the AM_APPLICATION table. it will delete only the correct combination)
DELETE FROM AM_SUBSCRIPTION WHERE API_ID = ? AND APPLICATION_ID = ?;
Step 2 - Remove API
1. If you have an icon to this api, To delete it, go to following registry location in the management console and and delete the API (select 'Action' and delete)
/_system/governance/apimgt/applicationdata/icons/admin 
2. Delete API related meta data by login to the management console and navigating to Home > Metadata > List > APIs (You have already done that)
3. To delete the Swagger resources related to this API , go to following registy location and delete the resource collection (select on the api-doc resource and it will display swagger docs for all the resources. delete related on by selecting the Action button)
/_system/governance/apimgt/applicationdata/api-docs
4. Delete the synapse configuration for that api in AM_HOME/repository/deployment/server/synapse-configs/default/api location
5. Run following database queries to remove api related data
DELETE FROM AM_API_LC_EVENT WHERE API_ID=? 
DELETE FROM AM_API_COMMENTS WHERE API_ID=? 
DELETE FROM AM_API_RATINGS WHERE API_ID=? 
DELETE FROM AM_SUBSCRIPTION WHERE API_ID=?
DELETE FROM AM_EXTERNAL_STORES WHERE API_ID=?
DELETE FROM AM_API WHERE API_PROVIDER=? AND API_NAME=? AND API_VERSION=? 
DELETE FROM AM_API_URL_MAPPING WHERE API_ID = ?
following are two sample queries
DELETE FROM AM_SUBSCRIPTION WHERE API_ID=5;
DELETE FROM AM_API WHERE API_PROVIDER='admin' AND API_NAME='SampleAPI' AND API_VERSION='1.0';
6. remove api related collection from the registry location
/_system/governance/apimgt/applicationdata/provider/<user>. There should be an empty collection with the api name on it.
7. Restart the AM to remove any cached content.
This should remove all the content related to the api.

I would like to thank ChamilaA who provided the resources needed for this post. Hope this would help someone who is in need. Please drop a comment if you have further queries.
Subscribe to RSS Feed Follow me on Twitter!