Web service call from camunda to external service(using REST POST method)

I am facing a problem when making web service call from camunda using http-connector.
I am trying to post some data, request is going but the payload is going empty.
I constructed the payload using freemarker script, in following way
{
“txt1” : ${value1},
“txt2” : ${value2}
}

please find the attachment of BPMN file.
Please help us the way request body(JSON) can be sent.

BPMN File
[Web Service call from camunda to External Service](http://Web Service call from camunda to External Service)

Hi,

the BPMN file is missing in your post. Would be great if you could share it again.

Cheers,
Sebastian

calculator.bpmn (10.8 KB)

Hi Please find BPMN file.

From camunda how can we send the JSON(format) request using http-connector

Hi,

I am always getting 400 bad request, but from postman client it is working fine.
External service i am using is python rest api.
Please find the python(flask) code.

#RestAPI script for addition and substraction
from flask import Flask,request,json,jsonify
from socket import gethostname
app = Flask(__name__)
# Make the WSGI interface available at the top level.
wsgi_app = app.wsgi_app

# Routing the addition function	
@app.route("/add_value",methods=['POST'])
def add_value():
    jsonbody = request.json
    txt1 = jsonbody['txt1']
    txt2 = jsonbody['txt2']
    add = {'Addition is':str(txt1+txt2)}
    return jsonify(add)
	
# Routing the substraction function	
@app.route("/sub_value",methods=['POST'])
def sub_value():
	json = request.json
	txt1 = json['txt1']
	txt2 = json['txt2']
	sub = {'substraction is':str(txt1-txt2)}
	return jsonify(sub)
	
	
if __name__==("__main__"):
	app.run(host=gethostname())

Hi,

I think your process is fine. The problem is that the Camunda Connector sends a request with a chunked body (Transfer-Encoding: chunked). If I understand this flask issue (#367) correct there is currently no direct support for such requests in flask.

So either you have to use a web framework which can handle these types of requests. Or run your flask app in a server which can handle this. In the issue is cherrypy mentioned as a possible solution. Or maybe there is a way to get the apache http client, which is used by the Camunda Connector, to not send chunked requests.

Cheers,
Sebastian

Hi,

Apache HTTP Client will use chunked encoding, when the length of the request isn’t known. See this post on stack overflow. The solution seems to buffer the whole request in memory (so, not using an input stream to fill the body) together with using the HTTP 1.0 protocol.
Maybe Sebastian knows, you this is possible with the Camunda HTTP-connector or if you have to write custom code for that.

Cheers,
Christian

Hi,

I don’t think that you can achieve this without a custom connector. As you have to interact with the
underlying Apache HTTP Client.

Cheers,
Sebastian

Thanks for the response.

So, we have to write our custom connector for this problem.

Hi,

Can you please provide any example of writing custom connector for camunda.
I have to use the flask with python, So can you please suggest the best solution for camunda connector to call python(flask) rest API.

Is there any way to disable chunked data in camunda connector before sending request to python flask server.