RESTServices - How to get entire BODY from POST action?

1
I'm trying to extract the full body content sent in a POST action to a service that i've published. For verification purposes i require to encrypt the entire body with SHA1 and compare it to a header that was sent along. If I use serializeObjectToJSON on the initial object passed into the microflow. It only extracts one level as JSON. How could I get all the contents?
asked
2 answers
1

I believe you'd have to modify the Java code.

Right here is where the "data" String first exists (that's the JSON body), and then a few lines later it's parsed into Mendix objects and that root object is returned. It would require a few code modifications, but you could certainly find a way to return the data String to your published REST microflow instead.

Another option would be to add the hash verification right in the Java code. This might be simpler overall.

EDIT: I just had a thought. There's a utility action now to get the request header: getResponseHeader

You could write a similar utility action to get the body in the same way. I'm sure the code would be very similar.

answered
0

Okay so i'll just add this in case anyone ever searches for this same topic, how we've resolved the issue, and i'm open to hear about more elegant solutions.

We've used a RestService Primitive as parameter to the rest service microflow. in the java code of JsonDeserializer we've then included an extra else if statement. Which does prim.setPrimitiveType(RestPrimitiveType.String); in case the jsonValue is of the type JSONObject. Unfortunately this is the case because the code in parseInputData already converts to a JSONObject with these lines below.

    IMendixObject argObject = Core.instantiate(rsr.getContext(), argType);
    JSONObject data = new JSONObject();

    //json data
    else if (rsr.getRequestContentType() == RequestContentType.JSON || (rsr.getRequestContentType() == RequestContentType.OTHER && !isFileSource)) { 
        String body = IOUtils.toString(rsr.request.getInputStream());
        data = new JSONObject(StringUtils.isEmpty(body) ? "{}" : body);
    }

I guess perhaps in a future release of the rest services module it would be handy if both the original parameters passed could be sent to the microflow as string parameter, and a single object that will be the translation of those parameters parsed into a mendix object. Even if the string parameter would just be for debugging purposes.

answered