简体   繁体   中英

How to send acknowledgment message to requester in mule flow Rest Web Service which will accept post method and

Here i am producing Rest Web service. But i am not using RAML and Api Kit.

I just want to send acknowledgment which is in the form of JSON. I don't what to interrupt my flow.

Below is my Requirement. Consumer will send json object using post operation. I will parse that json, Here, if (json is pared properly i have to sent acknowledgment message to consumer and i will do my business login then i will send result back to consmer.)

else

i have to send response as Mulformer JSON. Here i am not proceeding my business logic.

Please help me the approach how to send acknowledgement message to consumer

It's quite simple .. If you are not using RAML and Apikit, then you can parse the JSON received from POST operation in your Java file using GSON or Jackson Apis ..and then you can directly set the response from the Java class ... example :-

@Override
    @POST
    @Produces("application/json")
    @Path("/insert/")
    public DataResponse insertDataOperation(@RequestBody String message) {

        DataResponse dataResponse = new DataResponse();


        //Your bussness logic here if json parse properly using GSON or Jackson 
        //then 
        //return dataResponse;
        //else set your own response

        dataResponse.setMessage("Your acknowledgement message");
        return dataResponse;

         }
         }

My suggestion is to have JSON response always with well defined structure for success and error cases and make use of HTTP status codes to define your success/failure of the request. For your requirement once you receive the request store the original payload into a flow variable then use java component and return the validation result as true/false after this component put choice router, If request is valid assign the payload with original payload then invoke REST component.If request is invalid respond with the appropriate error payload with HTTP status code (example: HTTP status code as 400 with JSON payload {"error":"Bad Request"} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM