Http Connector Post Method With Content-Type application/x-www-form-urlencoded

Hello, I am trying to call a local service with given options:

<camunda:connector>
      <camunda:inputOutput>
        <camunda:inputParameter name="url">http://localhost:5001</camunda:inputParameter>
        <camunda:inputParameter name="method">POST</camunda:inputParameter>
        <camunda:inputParameter name="headers">
          <camunda:map>
            <camunda:entry key="Content-Type">application/x-www-form-urlencoded</camunda:entry>
          </camunda:map>
        </camunda:inputParameter>
        <camunda:inputParameter name="payload">tweet=test</camunda:inputParameter>
        <camunda:outputParameter name="Output">
          <camunda:script scriptFormat="Javascript" resource="parseX.js" />
        </camunda:outputParameter>
      </camunda:inputOutput>
      <camunda:connectorId>http-connector</camunda:connectorId>
    </camunda:connector>

I tried many variations for the payload, like:
<camunda:inputParameter name=“payload”>“tweet=test”</camunda:inputParameter>
<camunda:inputParameter name=“payload”>tweet%3Dtest</camunda:inputParameter>
<camunda:inputParameter name=“payload”>“tweet%3Dtest”</camunda:inputParameter>

With all the service can not get parameter “tweet”. But when I try the call the service via “Postman” application I get response.

POST  HTTP/1.1
Host: localhost:5001
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: e0f5c22c-9872-e363-e0b0-9aa4ff77edad

tweet=I+like

Here is pom.xml of the project

<properties>
    <camunda.version>7.7.0</camunda.version>
    <spring.version>3.1.2.RELEASE</spring.version>
</properties>

<!-- import Camunda BOM to ensure correct versions of Camunda projects -->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.camunda.bpm</groupId>
            <artifactId>camunda-bom</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>${camunda.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.7.6</version>
    </dependency>

    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine</artifactId>
    </dependency>

    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine-plugin-connect</artifactId>
    </dependency>

    <dependency>
        <groupId>org.camunda.connect</groupId>
        <artifactId>camunda-connect-http-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine-plugin-spin</artifactId>
    </dependency>

    <dependency>
        <groupId>org.camunda.spin</groupId>
        <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
    </dependency>

    <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-engine-spring</artifactId>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.171</version>
    </dependency>

    <!-- redirect slf4j logging to jdk logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.12</version>
    </dependency>




    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>

Could you please help me with this?

Can take a look at this working example of Twilio (uses x-www-form-urlencoded)

also as a recent alternative take a look at: Replacing Http-Connector with Jsoup usage

Thanks. I already saw that SMS example. Even I tried like below, it didn’t work. As I mentioned before it is working with Postman.

var data = {
"tweet": "testabc"

};

smsContent = Object.keys(data).map(function(k) {
return encodeURIComponent(k) + ‘=’ + encodeURIComponent(data[k])
}).join(’&’);

smsContent;

Service gives error as no arg.

Can you route your request to something like RequestBin and compare with the Postman request. And then show screenshots of the two requests in the RequestBin page (or just link to it)

Sure.

Okay and now you need to do the same thing but with your camunda request

The below one belongs to Camunda request actually. I send the request via Postman and the response was ok. In bpmn I put the requestBin url instead of localhost. Upper one is postman request to local host. So the below one is Camunda request to requestBin.

I want to see the Request Bin Requests from Postman and from Camunda.

I see. So this is RequestBin request from Postman:

In the previous message RequestBin request was from Camunda.

As I see only headers are different. Would that be the problem?

So next thing i would want to see is what your local service is receiving. You said the local service is saying argument is missing? Can you have the local service print out the received request? And then show the postman vs camunda requests.

The service is running in a docker container and it is coded with python. Is there a way to listen that localhost port to receive incoming request? I searched on web but couldn’t find a solution. OS is Ubuntu 16.04

Did you write the python app?

No unfortunately, that’s why I have no idea about it.

The error you are getting is from your Python application? Sounds like you are not using the correct url for the Camunda->Python connection. Can you post screenshot of the errors you are getting

I’m just calling the same url, localhost:5001. Yes I’m getting the error from python service, when I call it from camunda. It says at least you should send 1 “tweet” object in post. But the strange point is as you saw via RequestBin, both postman and camunda have the same body “tweet=hate”. I can’t figure out the missing point with camunda request.

Could it be that it fails because the Camunda request misses an Accept header?

I tried also with <camunda:entry key="accept">*/*</camunda:entry> but didn’t help. And realized that w3 says “If no Accept header field is present, then it is assumed that the client accepts all media types.” :\

Hmm, you could try once more with exactly the headers the working postman request uses (e.g. consider upper and lower case) just to ensure that it is not an issue with a sloppy service implementation. Or the other way round, make the Camunda request with exactly the same headers in Postman.

I think it is related to this ticket: https://app.camunda.com/jira/browse/CAM-8194,

I am gonna try to use camunda 7.8.0. Let’s see the results then