Storing the raw xml of a http request in a mendix object

1
My question refers to a workaround for publishing webservices without authentication. Is it possible to publish a microflow as a "webservice" which receives plain http requests? Possibly by making available on the server next to ....mendix.com/ws a different service (for example ....mendix.com/ws2)? If so, how? My second question refers to received messag3 of the http request. Is it possible to store the raw xml within the request in a mendix object? And again, if so, how?
asked
1 answers
3

You can accomplish something that resembles what you're trying to do in the following manner (from a java action, you'll probably want to set this up as your startup event)

    // BEGIN USER CODE
    Core.addRequestHandler("bugter/", new CustomWSRequestHandler());
    Core.getLogger("Bugter").info("Registered requesthandler for 'bugter/'");
    return true;
    // END USER CODE

For this to work you will also need a class "CustomWSRequestHandler" which should contain something like this:

public class CustomWSRequestHandler extends RequestHandler {

    @Override
    public void processRequest(IMxRuntimeRequest request, IMxRuntimeResponse response, String path) throws Exception {
        Core.getLogger("Bugter").info("Received request for path: " + path);
        String content = IOUtils.toString(request.getInputStream());
        Core.getLogger("Bugter").info("Received content: " + content);

        String answer = "ok!";
        OutputStream outputStream = response.getOutputStream();
        IOUtils.write(answer, outputStream);
        IOUtils.closeQuietly(outputStream);
    }
}

You can test this by using something like curl or Firefox Poster

PS: this is exemplifying code and should never be used in production.

answered