Custom servlets on the Gateway

I’m investigating how to make Gateway instances communicate with each other.
I didn’t find anything advanced or anything obvious, useful for my purpose.

At the moment, I am thinking of making a custom servlet as a module. The weather
example shows that it shouldn’t be a problem to contact the servlet, but
how do configure the servlet to serve requests?

Thanks!

You can use a basic class that you write that extends HttpServlet. You don’t have to write anything Ignition-specific to use servlets.

The basic servlet looks something like MyServlet.java here:

javabeanz.wordpress.com/2009/02/ … et-filter/

You implement doGet() and/or doPost(), and can use information in the request object to decide what to send back in the response.

There are plenty of examples on this online as well.

In your module hook, as in the example, do a context.addServlet(servletName, servletClass);

That’s right - one more thing. Invariably your servlet will want access to the Context. Add a function like this:

private GatewayContext getContext() { GatewayContext context = (GatewayContext) getServletContext().getAttribute(GatewayContext.SERVLET_CONTEXT_KEY); return context; }