So what has happened in the wrong exception mapper for an exception has got registered?
On Mon, Jun 20, 2016 at 7:03 PM, Hemika Kodikara <[email protected]> wrote: > Hi All, > > I am currently writing unit test cases where exception mappers are being > used in my service. Intermittently I get the following error when running > my tests : > > ============== > java.lang.ClassCastException: > org.wso2.carbon.andes.service.exceptions.InternalServerException cannot be > cast to org.wso2.carbon.andes.service.exceptions.MessageNotFoundException > at > org.wso2.carbon.andes.service.internal.exception.mappers.MessageNotFoundMapper.toResponse(MessageNotFoundMapper.java:30) > at > org.wso2.msf4j.internal.MSF4JMessageProcessor.handleThrowable(MSF4JMessageProcessor.java:138) > at > org.wso2.msf4j.internal.MSF4JMessageProcessor.receive(MSF4JMessageProcessor.java:81) > at > org.wso2.carbon.transport.http.netty.listener.WorkerPoolDispatchingSourceHandler$1.run(WorkerPoolDispatchingSourceHandler.java:125) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) > at java.lang.Thread.run(Thread.java:745) > ============== > > In the above exception, "MessageNotFoundException" maps to > "MessageNotFoundMapper" and "InternalServerException" maps to > "InternalServerErrorMapper". > > The 2 exception classes have nothing in common and the 2 mapper classes > also have nothing in common. > > I debugged further to find the issue with the attached > patch(ex-map-msf4j.diff) for logging(not sure whether I have the latest > code). > > Following is the output when the error occurs : > > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.DestinationNotFoundMapper.toResponse( > *java.lang.Throwable*) > .... > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.InternalServerErrorMapper.toResponse( > *java.lang.Throwable*) > .... > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.MessageNotFoundMapper.toResponse( > *java.lang.Throwable*) > > The issue here is that the paramtype is as "java.lang.Throwable". The > correct value should be as follows since there is a comparator for the > exceptionMapper map : > > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.DestinationNotFoundMapper.toResponse( > *org.wso2.carbon.andes.service.exceptions.DestinationNotFoundException*) > ..... > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.InternalServerErrorMapper.toResponse( > *org.wso2.carbon.andes.service.exceptions.InternalServerException*) > ..... > [org.wso2.msf4j.internal.MicroservicesRegistry] : CLASS : public > javax.ws.rs.core.Response > org.wso2.carbon.andes.service.internal.exception.mappers.MessageNotFoundMapper.toResponse( > *org.wso2.carbon.andes.service.exceptions.MessageNotFoundException*) > > > According to what I was able to find out, this is an JDK error[1][2](Bug: > 8029459 <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8029459>) for > the method "em.getClass().getMethods()"[3]. > > Any advice on how to proceed or that needs to be checked from my side ? > > [1] - > http://www.oracle.com/technetwork/java/javase/8-known-issues-2157115.html > [2] - http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8029459 > [3] - > https://github.com/wso2/msf4j/blob/master/core/src/main/java/org/wso2/msf4j/internal/MicroservicesRegistry.java#L84 > > Regards, > Hemika > > Hemika Kodikara > Software Engineer > WSO2 Inc. > lean . enterprise . middleware > http://wso2.com > > Mobile : +94777688882 > -- *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 3320919blog: **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 <http://lk.linkedin.com/in/afkhamazeez>* *Lean . Enterprise . Middleware*
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
