java.lang.LinkageError when implementing request handler

1
Hi All, I have a RequestHandler set up in my project that was working fine yesterday. Without making any changes to the project, I'm now getting an error when trying to hit the endpoint. It looks like this is being caused by the cast to the Jetty server Request object. import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; import com.mendix.externalinterface.connector.RequestHandler; import com.mendix.m2ee.api.IMxRuntimeRequest; import com.mendix.m2ee.api.IMxRuntimeResponse; public class MyRequestHandler extends RequestHandler { @Override protected void processRequest(IMxRuntimeRequest mxReq, IMxRuntimeResponse mxRes, String path) throws Exception { Request req = (Request) mxReq.getHttpServletRequest(); Response res = (Response) mxRes.getHttpServletResponse(); req.setContextPath("odataV2/"); } } Error stacktrace below: java.lang.LinkageError: loader constraint violation: when resolving interface method "com.mendix.m2ee.api.IMxRuntimeRequest.getHttpServletRequest()Ljavax/servlet/http/HttpServletRequest;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, customodata/MyRequestHandler, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for the method's defining class, com/mendix/m2ee/api/IMxRuntimeRequest, have different Class objects for the type javax/servlet/http/HttpServletRequest used in the signature at customodata.ODataRequestHandler.processRequest(ODataRequestHandler.java:23) at com.mendix.externalinterface.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:69) at com.mendix.externalinterface.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:66) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:36) at com.mendix.externalinterface.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:72) at com.mendix.core.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:745) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:561) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) at java.lang.Thread.run(Thread.java:748) To me, this looks like there are conflicting imports of the HttpServletRequest class between Mendix and my MyRequestHandler class. But I don't have the import anywhere in the class definition. Any thoughts on the cause? 10/19/18 Edit: Deleting the JAR per the troubleshooting documentation (https://docs.mendix.com/refguide/troubleshooting) fixed the above error, but now I'm getting the below error. Looks to be caused by the same kind of issue - differing Class Loaders. Same issue can be found here: http://jetty.4.x6.nabble.com/org-eclipse-jetty-server-Request-cannot-be-cast-to-org-eclipse-jetty-server-Request-td4965029.html. My error is below.   com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.ClassCastException: org.eclipse.jetty.server.Request cannot be cast to org.eclipse.jetty.server.Request at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:40) Caused by: java.lang.ClassCastException: org.eclipse.jetty.server.Request cannot be cast to org.eclipse.jetty.server.Request at customodata.ODataRequestHandler.processRequest(MyRequestHandler.java:31) at com.mendix.externalinterface.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:69) at com.mendix.externalinterface.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:66) at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:36) at com.mendix.externalinterface.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:72) at com.mendix.core.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:745) at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) at org.eclipse.jetty.server.Server.handle(Server.java:561) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597) at java.lang.Thread.run(Thread.java:748)  
asked
2 answers
1

Hi Steven,

Have you seen this question?

https://forum.mendix.com/link/questions/7252

 

They had a similar issue and were pointed to this documentation.

https://docs.mendix.com/refguide/troubleshooting

answered
0

The link that Austin provided above is part of the solution.I had to delete the servlet-api.jar from the userlib directory of the project to solve the first error. Additionally, I had to delete all of the jetty jar files from the userlib directory and only add them as External JARs to the Java Build Path from within Eclipse. Having them in both the userlib directory and the build path must cause some overlap in the class loaders.

Following this solution means that every time the project is deployed for Eclipse from the Mendix modeler and refreshed in Eclipse you will have to add the libraries back to the Java Build Path.

Is this a bug that I should put in a ticket for?

answered