【问题标题】:APIM Error: cURL DELETE command on an API returns a Runtime ErrorAPIM 错误:API 上的 cURL DELETE 命令返回运行时错误
【发布时间】:2014-09-09 16:19:13
【问题描述】:

我的 API 有一个 DSS 服务作为后端,并具有用于 GET、POST、PUT 和 DELETE 操作的相关资源。但是,当我对服务发出 DELETE 操作时,即使在后端成功发生,APIM 也会返回运行时错误:

curl -v -H "Authorization: Bearer 356bcb27f82c849e383d3765e0ccce" -X DELETE http://localhost:8280/fte/1.0/users/105/vacations/13
* Hostname was NOT found in DNS cache
*   Trying localhost...
* Connected localhost (localhost) port 8280 (#0)
> DELETE /fte/1.0/users/105/vacations/13 HTTP/1.1
> User-Agent: curl/7.36.0
> Host: localhost:8280
> Accept: */*
> Authorization: Bearer 356bcb27f82c849e383d3765e0ccce
>
< HTTP/1.1 202 Accepted
< Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type
< Content-Type: application/xml; charset=UTF-8
< Date: Tue, 09 Sep 2014 07:38:00 GMT
* Server WSO2-PassThrough-HTTP is not blacklisted
< Server: WSO2-PassThrough-HTTP
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
<am:fault xmlns:am="http://wso2.org/apimanager"><am:code>0</am:code><am:type>Status report</am:type><am:message>Runtime Error</am:message><am:description>Error while building message</am:description></am:fault>[

如何防止此类错误?我是否需要来自后端服务的输出消息,以便它不显示此运行时错误?

谢谢

【问题讨论】:

    标签: curl wso2 wso2esb wso2dss wso2-am


    【解决方案1】:

    发生这种情况是因为您的后端服务没有响应消息正文。相反,它只发送 HTTP 状态代码。 APIManager 尝试从该空有效负载构建消息。为了防止你可以打开你的 api 配置(repository/deploymnet/server/synapse-config/default/api) 对于 DELETE 操作,在发送到后端之前,通过设置 OUT_ONLY 属性使其成为单向消息。

    <property name="OUT_ONLY" value="true"/>
    

    确保您仅为 DELETE 操作设置该属性。如果其他操作返回任何响应正文,则此属性将影响它们。

    【讨论】:

    • 感谢您的回复,但根据我的 api 配置,我没有删除操作的特定设置这里是来自 api 的资源行` `,正如您所说,错误地放置该属性会影响其他操作的响应主体。有什么办法可以处理吗?
    • 在对 HTTP 方法的顺序检查中删除,然后设置 OUT_ONLY 属性(是的,这是您需要做的位自定义中介逻辑)您也可以为此使用自定义序列选项。请参考此文档:docs.wso2.com/display/AM170/Adding+Mediation+Extensions
    • 非常感谢!我也在考虑自定义中介,因为这是为删除操作设置属性的唯一方法。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 2015-10-18
    • 2021-02-26
    • 1970-01-01
    相关资源
    最近更新 更多