Initializing own servlet in Mendix 2.5

3
Hello, I was wondering how I can initialize my own servlet in Mendix 2.5. In the previous versions it was sufficient to define the service in the web.xml and add the servlet then to the userlib/lib directory of the running project. In Mendix 2.5 the only web.xml I've found is in the INSTALL_DIR/server dir of Mendix but I get an javax.servlet.UnavailableException "Error 404 Servlet Not Initialized" when I want to call the servlet. Is there any solution? Greetings, Michael Walker
asked
6 answers
2

You can use the Core.addRequestHandler method, which can be invoked from a java action, to add servlets to the server. The object it requires is slightly different from a javax http servlet, however it is quite easy to wrap a http servlet in most cases.

answered
2

Well, OK. And how do I get a map of the parameters of MxRuntimeRequest/HttpMxRuntimeRequest? I can't get several unknown parameters by request.getParameter(String arg0).

answered
2

To add a servlet in Mendix 2.5 you have to do the next thing.

In a java code what is called from your Mendix project (from a microflow) where you add a requesthandler via the

 Core.addRequestHandler(String URL, RequestHandler handler)

The string URL is the extra text to give the servlet a adres in your webapplication URL. The URL of your webapplication is for example: www.website.com If you give the string URL in the addRequestHandler a text like "/servlet", the address to your servlet in the URL of the webapplication will be: www.website.com/servlet

The second parameter RequestHandler is the servlet class. It is not excactly the javax servlet, but you have your request en response parameters in yout class.

public class ConnectServlet extends RequestHandler{   }

I hope this will help you to create a servlet in Mendix 2.5

answered
1

Thanks for the answer. Where can I find the specification of the RequestHandler? There is no "com.mendix.externalinterface.connector.RequestHandler" in the javadoc :(

answered
1

I don't think there currently is any documentation on this, but we'll be sure to release it before 2.5 final.

In the meantime, I'd suggest creating a class which implements the RequestHandler. Eclipse is pretty good at filling in the blanks and getting you on your way :) The M2EE API (MxRuntimeRequest, MxRuntimeResponse) kind of mimics the servlet api so that shouldn't be too hard to figure out.

answered
1

I have got the same question to add a servlet to the XAS. Is it possible to post some code wat is needed to add a servlet and what te structure is with the RequestHandler? How must you handle with the Session and Icontext?

answered