WSO2 不是有效的协议版本:<head> 对于

WSO2 Not a valid protocol version: <head> For

我正在尝试在 WSO2 Enterprise Integrator 中使用 POST 方法调用 http-EndPoint 方法。这个端点得到一个 JSON object 作为输入和 return 一个 JSON object 作为响应。

到目前为止,我在 Enterprise Integrator 中使用了各种类型的 http-EndPoints,没有任何问题,但是这个特定的 EndPoint returns 是一条错误消息,我找不到任何线索它在 google.

这是我的 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": "", "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>

这是我在控制台中的错误消息:

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

更新

enabled Wire Logs in WSO2深入调查这个问题。这是日志输出:

[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]"

虽然 wire log returned 此响应:Message: Bad HTTP/0.9 request type ('POST'),但我可以毫无问题地直接向 Endpoint 发送 post 请求。

这是对端点的直接 post 请求:

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

这里是输出结果:

  • 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

  • 上传完全发送:197 字节中有 197 个
  • 状态:DO => DO_DONE句柄 0x600057950;第 1689 行(连接 #0)
  • 状态:DO_DONE => WAITPERFORM 句柄 0x600057950;第 1814 行(连接 #0)
  • 状态:WAITPERFORM => PERFORM句柄0x600057950;第 1824 行(连接 #0)
  • HTTP 1.0,假设在 body
  • 之后关闭
  • 标记为 [关闭]:HTTP/1.0 在 body < HTTP/1.0 之后关闭 < HTTP/1.0 200 OK < 服务器:BaseHTTP/0.3 Python/2 .7.9 < 日期:2018 年 1 月 14 日,星期日 07:53:37 格林威治标准时间 < Content-type: application/json < Content-length: 2105 <
  • 状态:执行 => 完成句柄 0x600057950; 1993 行(连接 #0)
  • multi_done
  • 正在关闭连接 0
  • 缓存现在包含 0 个成员
  • 过期清除

当我比较 WSO2 的 headers 和 curl 的 headers 时,我无法弄清楚有什么区别。为什么 WSO2 请求失败而 curl 请求成功?

尝试在 <send> 调解器之前添加它。

<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/> 

通过比较来自 WSO2 和 curl 的 headers,我注意到 curl header Rebuilt URL to: http://192.168.1.50:1237/ 中的这一行。因此我改变了这个:

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

为此:

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

将以下属性添加到序列中:

  • FORCE_HTTP_CONTENT_LENGTH
  • COPY_CONTENT_LENGTH_FROM_INCOMING

这样问题就解决了,但原因不明。

来自您的电报:

[2018-01-15 09:30:46,624] [EI-Core] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "

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 >> "

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 >> "[\n]"

注意:HTTP 0.9 官方规范只包含一种请求方法:GET。 您正在使用 HTTP 0.9

不支持的 post

For more information about HTTP 0.9, refer to the original W3C HTTP specification.