获取"响应代码404映射为失败"通过使用Mulesoft的web api

时间:2017-11-09 21:44:48

标签: mule anypoint-studio mule-esb

我尝试使用开源api,将响应代码404映射为失败。

{{1}}

和错误信息是

响应代码404映射为失败。 有效载荷:org.glassfish.grizzly.utils.BufferInputStream@12c30f42 元素:/ postTaxCollectionFlow / processors / 1 @ taxcollection_apisero:taxcollection_apisero.xml:23(Web服务) 元素XML:                         HTTP:要求建设者                                                                           

请帮我配置

5 个答案:

答案 0 :(得分:2)

导致404错误,因为您的http:request连接器正在构建错误的网址。

来自HTTP请求连接器配置的MuleSoft documentation

You need to provide a path and method for your requests, as well as reference 
a Connector Configuration global element. Note that the path field doesn’t 
define the full path, but rather the subpath, within the host and after the 
optional base path that can be specified in the Connector Configuration global element.

使用此逻辑,您尝试从中请求数据的代码中构建的网址为https://api.taxjar.com:443/v2/taxes/https://api.taxjar.com/v2/taxes

答案 1 :(得分:0)

尝试从Postman / RestClient中获取所需的URL,看看是否提供了有效的响应。

我已尝试使用已发布的虚拟数据复制您的流程。它似乎点击了

https://api.taxjar.com/v2/taxes/taxcollection”url

给出以下回复

{
"error": "Not Found",
"detail": "No such route 'POST /v2/taxes/taxcollection'",
"status": "404"
}

如果它适用于邮递员,它应该与Mule一起工作。如果它在邮递员中工作正常而不是mule.Post请求数据和url与你的骡子流(如果可能的话)。它将帮助我们找出根原因

答案 2 :(得分:0)

检查Webservice组件中的路径, 由于您已经指定了主机和端口,因此无需将路径指定为完整路径。请更改路径并检查响应。

答案 3 :(得分:0)

完全同意Jason Estevan的回答。 您的HTTP出站连接器的配置应如下所示:

<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="api.taxjar.com" port="443" doc:name="HTTP Request Configuration"/>

出站连接器应该是这样的:

<http:request config-ref="HTTP_Request_Configuration" path="v2/taxes" method="POST" doc:name="Web Service">
        <http:request-builder>
            <http:query-param paramName="Authorization" value="Token token=&quot;8dbc821e651fe0672c4032e65209b37c&quot;"/>
            <http:query-param paramName="Content-Type" value="application/json"/>
        </http:request-builder>
    </http:request>

在路径中唯一的路径应该来自主机名和&amp;港口。 因为你已经定义了主机名和连接器配置中的端口,不应该在路径中。

答案 4 :(得分:0)

检查同一端口上是否有另一台服务器(即使它听起来太奇怪了)。

在端口8082中使用Java Spring服务器并且在同一端口8082中使用MailSlurper时,我们遇到了同样的错误。使用curl调用API总是成功触发Spring应用程序中的断点:

curl -X POST -H "Content-Type: application/json" -D - -d '{}' http://localhost:8082/api/foobar

从Mule 3.8.1 / 3.9.0独立调用API导致可怕的&#34;响应代码404映射为失败&#34;。我们通过调用服务器root找到了解决方案:

curl -X GET -H "Content-Type: application/json" -D - -d '{}' http://localhost:8082

然后我们从MailSlurper实例得到了一个惊人的响应,该实例发回了它的首页html。之后,结束MailSlurper进程,更改其端口并重新启动是微不足道的。

编辑:

如果端口上没有服务器,则卷曲输出:

curl: (7) Failed to connect to localhost port 8082: Connection refused

如果您的服务器运行正常但根路径未配置为在GET上返回任何内容:

$ curl -X POST -H "Content-Type: application/json" -D - -d '{}' 
http://localhost:8082/
HTTP/1.1 404 Not Found
Date: Mon, 30 Apr 2018 07:41:41 GMT
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=iso-8859-1
Content-Length: 316
Server: Jetty(9.3.6.v20151106)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /. Reason:
<pre>    Not Found</pre></p>
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.6.v20151106</a><hr/>
</body>
</html>

如果服务器运行正常但API路径不正确:

$ curl -X POST -H "Content-Type: application/json" -D - -d '{}' http://localhost:8082/api/foobar
HTTP/1.1 404 Not Found
Date: Mon, 30 Apr 2018 07:42:57 GMT
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=iso-8859-1
Content-Length: 326
Server: Jetty(9.3.6.v20151106)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /api/foobar. Reason:
<pre>    Not Found</pre></p>
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.6.v20151106</a><hr/>

如果服务器运行正常并且找到了API路径:

$ curl -X POST -H "Content-Type: application/json" -D - -d '{}' http://localhost:8082/api/foobar
HTTP/1.1 200 OK
Date: Mon, 30 Apr 2018 07:50:30 GMT
Content-Type: text/plain;charset=iso-8859-1
Content-Length: 23
Server: Jetty(9.3.6.v20151106)