camunda-community-hub / zeebe-http-worker

Zeebe worker for HTTP calls
Apache License 2.0
44 stars 28 forks source link

Body of Http Post #45

Open nizarelouaer opened 4 years ago

nizarelouaer commented 4 years ago

Hello, I am using the http worker to communicate with my Rest Microservices. One of my services accepts a POST request with a JSON body. I tried to set the body cariables in the headers using the zeebe modeler but it does not work. In the modeler there is no option to set Variables, the only options are Variable Mappings and Headers. How can I set the body of my request using the modeler ? Thank you

saig0 commented 4 years ago

Hi @nizarelouaer,

you have different options to set the body of the request.

If the body is static then you can define a custom header body on the service task (e.g. body : {"x":1}).

Otherwise, the body can be passed as a workflow instance variable with the name body. If the workflow instance doesn't have such a variable with the name then you can define an input mapping on the service task to map an existing variable in, for example, source: x.y -> target: body.

Does this help you?

nizarelouaer commented 4 years ago

Hi @saig0 thank you for the comment. The body is not static so I’m my input mappings I am setting it like the following : Input : variable1 output body.variable1 Input : variable2 output body.variable2 When I open my workflow instance using the operate I can set that there is a body variable body = {variable1:value1, variable2:valie2}. That is ok but my service is returning bad request, it seems that the body is not sent. I am trying to debug and see what is the problem exactly

nizarelouaer commented 4 years ago
I am now able to set the body, but I am having an issue with the header. In my request I have a key in the header: """" Connection Upgrade, HTTP2-Settings """ This is making the server reject the request with 400 Bad Request. Is it a key added by the http worker ? zeebe ? thank you
salaboy commented 4 years ago

@nizarelouaer that is interesting.. that is probably the case.. let's investigate

salaboy commented 4 years ago

@nizarelouaer For some reason, we are using HttpClient class, https://github.com/zeebe-io/zeebe-http-worker/blob/master/src/main/java/io/zeebe/http/HttpJobHandler.java#L55 that might be automatically initialized with that... I will look deeper

nizarelouaer commented 4 years ago

@salaboy I just read the http worker java code and there is nothing that sets the connection key header. I guess it is set in the zeeebe itself maybe

nizarelouaer commented 4 years ago

@salaboy in the java code the header are set without any connection key. I think that I will add the header key “””” Connection=keep-alive” in the java code : final HttpRequest.Builder builder = HttpRequest.newBuilder() .header(“Connection”, “keep-alive”) “”””” And compile to see if it solves the issue

salaboy commented 4 years ago

@nizarelouaer awesome! lets us know how it goes!