Hi,
I am working on altering "org.wso2.carbon.apimgt.interceptor" component to
support generic API formats. In the available version it supports only one
context noun before version therefore we cannot define APIs like
foo/bar/1.0.0
What I am doing is make it generic to support any sub context after root
context like a/b/c/d/1.0.0
The logic is to compare existing AM_API table records against current
request including version and pick up context, version from database
record. The logic works fine and I had to modify
interceptorOps.doThrottle(request, accessToken) -->
interceptorOps.doThrottle(request, accessToken, context, apiVersion); to
pass context and version
now altered doThrottle method like
public boolean doThrottle(Request request, String accessToken, String
context, String version) throws APIFaultException {
String apiName = context;
String apiVersion = version;
String apiIdentifier = apiName + "-" + apiVersion;
APIThrottleHandler throttleHandler = null;
ConfigurationContext cc = DataHolder.getServerConfigContext();
if (cc.getProperty(apiIdentifier) == null) {
throttleHandler = new APIThrottleHandler();
/* Add the Throttle handler to ConfigContext against
API Identifier */
cc.setProperty(apiIdentifier, throttleHandler);
} else {
throttleHandler = (APIThrottleHandler)
cc.getProperty(apiIdentifier);
}
if (throttleHandler.doThrottle(request, apiKeyValidationDTO,
accessToken)) {
return true;
} else {
throw new
APIFaultException(APIManagerErrorConstants.API_THROTTLE_OUT,
"You have exceeded your
quota");
}
}
What happen here is ConfigurationContext getting null and throws null
pointer exception. This can be avoided by doing simple null check but will
there be any side effects by doing it ?
If configuration context is null how can I invoke setProperty ?
--
Gayan Gunawardana
Software Engineer; WSO2 Inc.; http://wso2.com/
Email: [email protected]
Mobile: +94 (71) 8020933
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev