It is not correct to return CarbonContextHolder since it is an internal implementation detail. Also, that holder cannot be cast to CarbonContext.
On Thu, Oct 4, 2012 at 6:35 PM, Lalaji Sureshika <[email protected]> wrote: > Hi, > > With the latest API-M pack build in public branch,when thrift > enabled,there was an ClassCastException[1] thrown while invoking APIs > published through APIStore. > > When going through the code,found that issue is appearing with obtaining > the current context for a Thrift Session. > > In the method 'getCurrentCarbonContextHolder(ThriftSession thriftSession, > boolean > addToSession)' of 'CarbonContextDataHolder' class there's an attribute is > set for ThriftSession with the object type 'CarbonContextDataHolder' > [which is currently resides inside a private package] and without > wrapping it through publicly accessible interface class object either " > CarbonContext/PrivilegedCarbonContext" as below. > > * private static CarbonContextDataHolder > getCurrentCarbonContextHolder(ThriftSession thriftSession,* > * > boolean addToSession) {* > * Object contextObject = > thriftSession.getSessionCarbonContextHolder();* > * if (contextObject != null) {* > * return (CarbonContextDataHolder) contextObject;* > * } else if (!addToSession) {* > * return null;* > * }* > * CarbonContextDataHolder context = getClone();* > * log.debug("Added CarbonContext to the Thrift Session");* > * thriftSession.setAttribute(CARBON_CONTEXT_HOLDER, context);* > * return context;* > * }* > > From the APIMgt Keymgt code,we are invoking the method which returns the > above setter attribute and with the current implementation though it is > returning a 'CarbonContextDataHolder' object,it's trying to cast that > object to 'CarbonContext' type as below. > > public CarbonContext getSessionCarbonContextHolder() { > CarbonBaseUtils.checkSecurity(ALLOWED_METHODS); > * return (CarbonContext) attributeMap.get(CARBON_CONTEXT_HOLDER);* > } > > and then the error[1] is appearing. This issue is fixed[r 144918] > .Thanks Pradeep for help on it. > > Additionally we noticed same issue can be appeared when getting carbon > context holder for *HTTPSession* as well. It would be great Platform team > can look in to that as well. > > > [1] java.lang.ClassCastException: > org.wso2.carbon.context.internal.CarbonContextDataHolder cannot be cast to > org.wso2.carbon.context.CarbonContext > at > org.wso2.carbon.utils.ThriftSession.getSessionCarbonContextHolder(ThriftSession.java:141) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.populateCurrentCarbonContextFromAuthSession(APIKeyValidationServiceImpl.java:56) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:99) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:177) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:165) > at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32) > at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34) > at > org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176) > at > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:662) > [2012-10-04 13:26:53,929] ERROR - ThriftKeyValidatorClientPool Login > failed.. Reauthenticating again.. > [2012-10-04 13:26:53,984] ERROR - TThreadPoolServer Error occurred during > processing of message. > java.lang.ClassCastException: > org.wso2.carbon.context.internal.CarbonContextDataHolder cannot be cast to > org.wso2.carbon.context.CarbonContext > at > org.wso2.carbon.utils.ThriftSession.getSessionCarbonContextHolder(ThriftSession.java:141) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.populateCurrentCarbonContextFromAuthSession(APIKeyValidationServiceImpl.java:56) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationServiceImpl.validateKey(APIKeyValidationServiceImpl.java:99) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:177) > at > org.wso2.carbon.apimgt.keymgt.service.thrift.APIKeyValidationService$Processor$validateKey.getResult(APIKeyValidationService.java:165) > at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:32) > at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:34) > at > org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:176) > at > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:662) > > Thanks; > -- > Lalaji Sureshika > Software Engineer; Development Technologies Team;WSO2, Inc.; > http://wso2.com/ > email: [email protected]; cell: +94 71 608 6811 > blog: http://lalajisureshika.blogspot.com > > > > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Afkham Azeez* Director of Architecture; WSO2, Inc.; http://wso2.com Member; Apache Software Foundation; http://www.apache.org/ * <http://www.apache.org/>** email: **[email protected]* <[email protected]>* cell: +94 77 3320919 blog: **http://blog.afkham.org* <http://blog.afkham.org>* twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> * linked-in: **http://lk.linkedin.com/in/afkhamazeez* * * *Lean . Enterprise . Middleware*
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
