0
votes

I'm trying to consume to the open source api getting the response code 404 mapped as failure.

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="api.taxjar.com" port="443" basePath="v2/taxes" doc:name="HTTP Request Configuration"/>
<flow name="postTaxCollectionFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/taxcollection" allowedMethods="POST" doc:name="HTTP"/>
    <dw:transform-message doc:name="Transform Message" metadata:id="2789cbd2-5ca6-46c2-856f-67ba2bdfa6dd">
        <dw:input-payload mimeType="application/json"/>
        <dw:set-payload>
            <![CDATA[%dw 1.0
            %output application/json
            ---
            payload
            ]]></dw:set-payload>
    </dw:transform-message>
    <http:request config-ref="HTTP_Request_Configuration" path="https://api.taxjar.com/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>
    <byte-array-to-object-transformer doc:name="Byte Array to Object"/>
    <json:object-to-json-transformer doc:name="Object to JSON"/>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

and error message is

Response code 404 mapped as failure. Payload : org.glassfish.grizzly.utils.BufferInputStream@12c30f42 Element : /postTaxCollectionFlow/processors/1 @ taxcollection_apisero:taxcollection_apisero.xml:23 (Web Service) Element XML : http:request-builder

please help me out to configure it

5

5 Answers

2
votes

The 404 error is caused because your http:request connector is constructing an incorrect url.

From the MuleSoft documentation on the HTTP Request Connector configurations:

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.

Using this logic the url being constructed in your code that you are trying to request data from is https://api.taxjar.com:443/v2/taxes/https://api.taxjar.com/v2/taxes

0
votes

Try to hit the required URL from Postman/RestClient and see if that gives a valid response.

I have tried replicating your flow with some dummy data posted.It seems it hits

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

which is giving below response

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

If it works in postman it should work with Mule.In case if it works fine in postman and not in mule.Post the request data and url with your mule flow(if possible).It will help us to figure out root cause

0
votes

Check the path in the Webservice component, Since you have already specified the host and port need not give the path as complete. Please change the path and check response.

0
votes

Totally agree with Jason Estevan's answer. Your HTTP outbound connector's configuration should be like this:

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

And outbound connector should be like this:

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

In path only path of hte URL should come which is after host name & port. As you are already defining host name & port in connector config., that should not be there in path.

0
votes

Check if you have another server on the same port (even if it sounds too strange to be possible).

We got the same error when having Java Spring server in port 8082 and MailSlurper also in same port 8082. Calling API with curl always succeeded triggering a breakpoint in Spring application:

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

Calling the API from Mule 3.8.1 / 3.9.0 standalone caused the dreaded "Response code 404 mapped as failure". We found the solution by calling server root like this:

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

Then we got a surprising response from the MailSlurper instance, which sent back its front page html. After that it was trivial to end MailSlurper process, change its port and restart.

EDIT:

If there are no servers on the port then curl outputs:

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

If your server is running OK but the root path is not configured to return anything on 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>

If the server is running OK but the API path is incorrect:

$ 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/>

If the server is running OK and the API path is found:

$ 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)