I'm trying to call a http-EndPoint with POST method in WSO2 Enterprise Integrator. This EndPoint gets a JSON object as input and return a JSON object as response.

Until now I've used various types of http-EndPoints in Enterprise Integrator without any problem but this particular EndPoint returns an error message which I'm not able to find any clue about it in google.

This is my api:

<resource methods="POST" uri-template="/userInfo">
    <inSequence>
        <payloadFactory media-type="json">
            <format>{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "$1", "auth_pass": "myPassword"},"method": "user.MethodName", "id": 0}
            </format>
            <args>
                <arg evaluator="json" expression="$.user"/>
            </args>
        </payloadFactory>
        <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
        <property name="FORCE_HTTP_1.0" scope="axis2" type="STRING" value="true"/>
        <send description="">
            <endpoint>
                <http method="post" uri-template="http://192.168.1.50:1237"/>
            </endpoint>
        </send>
    </inSequence>
    <outSequence>
        <send/>
    </outSequence>
    <faultSequence/>
</resource>

This is my error message in console:

[EI-Core] ERROR - TargetHandler HTTP protocol violation : Not a valid protocol version: <head> For : 192.168.1.50:1237

UPDATE

I enabled Wire Logs in WSO2 to investigate in depth about this issue. Here is log output:

[2018-01-15 09:30:46,621] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "POST  HTTP/1.0[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Expect: 100-continue[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Content-Type: application/json[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Content-Length: 196[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Host: 192.168.1.50:1237[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Connection: Keep-Alive[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "[\r][\n]"
[2018-01-15 09:30:46,622] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"},"method": "user.MethodName", "id": 0}"
[2018-01-15 09:30:46,623] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<head>[\n]"
[2018-01-15 09:30:46,623] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<title>Error response</title>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "</head>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<body>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<h1>Error response</h1>[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Error code 400.[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Message: Bad HTTP/0.9 request type ('POST').[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "<p>Error code explanation: 400 = Bad request syntax or unsupported method.[\n]"
[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "</body>[\n]"

Although wire log returned this response: Message: Bad HTTP/0.9 request type ('POST'), but I can send post requests to Endpoint directly without any problem.

Here is direct post request to endpoint:

curl -v -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237

And here is output result:

  • STATE: INIT => CONNECT handle 0x600057950; line 1423 (connection #-5000)
  • Rebuilt URL to: http://192.168.1.50:1237/
  • Added connection 0. The cache now contains 1 members
  • Trying 5.202.129.107...
  • TCP_NODELAY set
  • STATE: CONNECT => WAITCONNECT handle 0x600057950; line 1475 (connection #0)
  • Connected to 192.168.1.50 (192.168.1.50) port 1237 (#0)
  • STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x600057950; line 1592 (connection #0)
  • Marked for [keep alive]: HTTP default
  • STATE: SENDPROTOCONNECT => DO handle 0x600057950; line 1610 (connection #0)

    POST / HTTP/1.1 Host: http://192.168.1.50:1237 User-Agent: curl/7.56.1 Accept: / Content-Type: application/json Content-Length: 197

  • upload completely sent off: 197 out of 197 bytes
  • STATE: DO => DO_DONE handle 0x600057950; line 1689 (connection #0)
  • STATE: DO_DONE => WAITPERFORM handle 0x600057950; line 1814 (connection #0)
  • STATE: WAITPERFORM => PERFORM handle 0x600057950; line 1824 (connection #0)
  • HTTP 1.0, assume close after body
  • Marked for [closure]: HTTP/1.0 close after body < HTTP/1.0 200 OK < Server: BaseHTTP/0.3 Python/2.7.9 < Date: Sun, 14 Jan 2018 07:53:37 GMT < Content-type: application/json < Content-length: 2105 <
  • STATE: PERFORM => DONE handle 0x600057950; line 1993 (connection #0)
  • multi_done
  • Closing connection 0
  • The cache now contains 0 members
  • Expire cleared

When I compare headers from WSO2 to headers from curl I cant figure out what are differences. Why WSO2 request failed while curl request succeed?

1 upvote
  flag
Can you hit the backend directly with curl -IL and post the response? – Bee
upvote
  flag
@Bee Thank you for reply. I updated my question. – masoud keshavarz
upvote
  flag
Well, what I wanted you to do is to run that command with a real request (i.e. working url and valid payload) – Bee
upvote
  flag
@Bee Can you help me to do this Please? I've tried this: curl -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237 -IL But it respond: Warning: You can only select one HTTP request method! You asked for both POST Warning: (-d, --data) and HEAD (-I, --head). – masoud keshavarz
1 upvote
  flag
Can you run this and post the response headers you get? curl -v -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "params": {"auth_type": "ADMIN", "auth_name": "someName", "normal_username": "myUserName", "auth_pass": "myPassword", "remote_addr": "127.0.0.1"}, "method": "user.MethodName", "id": 0}' 192.168.1.50:1237 – Bee

2 Answers 11

Try adding this before the <send> mediator.

<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/> 
upvote
  flag
I thought it solved the problem. But unfortunately I still get this error message: 'Not a valid protocol version: <head> For : 192.168.1.50:1237' – masoud keshavarz
1 upvote
  flag
Enabled wire logs and invoke the API. then post your logs. lakshanigamage.blogspot.com/2015/03/… – Bee
upvote
  flag
Thanks. Enabling wire log was a huge help. I updated my question. – masoud keshavarz
up vote 0 down vote accepted

By comparing headers from WSO2 and curl I noticed this line in curl header Rebuilt URL to: http://192.168.1.50:1237/. Hence I changed this:

<endpoint>
     <http method="post" uri-template="http://192.168.1.50:1237"/>
</endpoint>

To this:

<endpoint>
     <http method="post" uri-template="http://192.168.1.50:1237/"/>
</endpoint>

Not the answer you're looking for? Browse other questions tagged or ask your own question.