Search code examples
jsonrestjettyignite

Pass JSON POST Data to Ignite 2.7 ComputeTask


I have a complicated API request that needs to pass JSON data to an Ignite ComputeTask, but I can only seem to pass in data through the URL query string, which seems awkward, and potentially limiting. I have two questions:

  1. Does the Ignite REST API have a max GET request limit, and if so, is there a way to increase it?

  2. Is there any way to pass in JSON data through a POST request? I've experimented with ConnectorMessageInterceptor, but the args parameter is just the value of p1 from the query string.


Solution

    1. If you're OK with passing JSON data in as a GET parameter, you can set the max GET size in your jetty configuration in your connector configuration using <Set name="requestHeaderSize">BYTES</Set>, though this is clearly not an optimal solution.

    2. The short answer is no, there's no built-in way to intercept JSON POST body data in Ignite's built-in REST API. Although the Ignite documentation suggests that you configure Jetty's handlers, Ignite 2.7's implementation of Jetty (see GridJettyRestProtocol) actually overrides the configured Handler with its own GridJettyRestHandler, which only accepts requests in the form /ignite?cmd=cmdName&p1=params&name=taskName. To work around this, you can drop the ignite-rest-http lib and roll your own jetty implementation. If that seems like too much work and don't mind a somewhat hacky solution, you can piggyback on ignite's optional lib structure, and copy in just the file org.apache.ignite.internal.processors.rest.protocols.http.jetty.GridJettyRestProtocol from the ignite-rest-http lib, which Ignite will automatically pick up at start up. In GridJettyRestProtocol swap out GridJettyRestHandler for your own custom AbstractHandler that accepts POST data. Remember to import jetty as a project dependency.