Getting Response 404 while posting JSON payload to POST Rest API

烈酒焚心 提交于 2020-01-06 05:57:26

问题


I'm trying to post a JSON payload to a Public POST Rest API in MuleESB but I'm getting this error:

org.mule.module.http.internal.request.ResponseValidatorException: Response code 404 mapped as failure.

I'm able to call the API with JSON body via Postman Chrome App, but not via Postman Desktop App or MuleESB. I've Google-ing around in the past 2 days but still have no clue what I'm missing. Please enlighten me if you have a clue what caused this not to work.

This is the JSON payload:

{
  "username": "dummy",
  "email": "dummy@dummy.com",
  "firstName": "dummy",
  "lastName": "dummy"
}

Here's the snippet of my MuleESB code (I'm using 3.8.3):

        <http:request-config name="HTTP_Request_Configuration" host="api.domain.com" port="443" doc:name="HTTP Request Configuration" protocol="HTTPS" responseTimeout="180000" tlsContext-ref="TLS_TrustStore"/>
        <tls:context name="TLS_TrustStore" doc:name="TLS">
            <tls:trust-store path="cacerts.jks" password="pwd"/>
        </tls:context>
        ...
        <dw:transform-message doc:name="Transform Message" metadata:id="c77537ba-aaf3-4497-9f09-06792d1f7556">
        <dw:input-payload mimeType="application/java"/>
        <dw:input-variable doc:sample="sample_data\UserDefined.dwl" variableName="userData"/>
        <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    username: flowVars.username as :string,
    email: flowVars.email as :string,
    firstName: flowVars.firstName as :string,
    lastName: flowVars.lastName as :string
}]]></dw:set-payload>
        </dw:transform-message>
        <logger message="payload:#[payload]" level="INFO" doc:name="Logger"/>        
        <set-property propertyName="Content-Type" value="application/json" encoding="UTF-8" mimeType="application/json" doc:name="Property"/>        
        <until-successful maxRetries="3" doc:name="Until Successful" synchronous="true">
            <http:request config-ref="HTTP_Request_Configuration" path="/api/1/users" method="POST" doc:name="HTTP">
                <http:request-builder>
                    <http:header headerName="Authorization" value="abcdefg"/>
                </http:request-builder>
            </http:request>
        </until-successful>

回答1:


Thanks everyone who attempted to help. This article resolved my issue: https://support.mulesoft.com/s/article/ka434000000CbmzAAC/How-to-fix-Remotely-Closed-error-for-HTTP-POST-request



来源:https://stackoverflow.com/questions/45180001/getting-response-404-while-posting-json-payload-to-post-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!