Mule calling rest api fails with " Response code 404 mapped as failure. " - http

I am trying to consume a rest api via mulesoft but from postman when i invoke the mule endpoint it gives the following error "Response code 404 mapped as failure."
<http:request-config name="HTTP_Request_Configuration" host="xxxxx" port="80" doc:name="HTTP Request Configuration" basePath="/xxx/Members"/>
<http:request config-ref="HTTP_Request_Configuration" path="/{mID}/Members" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-param paramName="mID" value="#[flowVars.memID]"/>
</http:request-builder>
</http:request>

The error message you are getting in Mule indicates that the REST API you are calling from Mule is returning a 404. This means that you are requesting a resource that doesn't exist.
Check your config and the service you are consuming to make sure they match. From your code above the URL that Mule will be requesting is:
http://xxxxx:80/xxx/Members/{mID}/Members
This is built up from the host, port and base path of the HTTP config along with the path of the HTTP Request component.
Not having any knowledge of the API you are trying to consume I can't tell you what it should be in your specific case. If you have documentation that describes the service you should be able to adjust your mule configuration to match it.
Hope that helps.
Johnson.

Related

400 Bad request while consuming a rest service with POST method?

I'm getting http requestor connection problem with POST:request a bad request even though I'm configuring properly. I'm sending json payload in the body and Bearer token in headers parameters with content type, I can evaluate the token and payload properly but still getting as a bad request when I tried to hit the direct URL as well, and I tried the trigger in postman with the same token generated in mule where I'm getting the success response but while using the same service within mule getting as bad request, I'm using http connector plugin version 1.7.1 in pom.xml.. Is there any problem with the dependency? can anyone help me with this?
If you are successful doing the request in postman then the HTTP request in your Mule application has to need some adjustments to make it match the postman request. Compare them carefully to make them match.

AWS API Gateway: Add header if response is Unauthorized

I setup an API Gateway in AWS that uses custom authorizers to implement an OAuth2 flow. It works fine. When the user is not authorized they get a 401 Authorized response. That is correct as well, but I would like to add a header that gives the client the endpoint where it can get the token. Something like AuthorizeUrl: url
How can I add this header to my response?
Unfortunately this isn't possible but it's on our backlog. I know it doesn't really make sense when the client gets a 401 but you can't tell them how to authorize.
I don't have an ETA to provide but I'll add a +1 to the feature request.
AWS added this functionality last year.
Refer to this
To do it manually:
Go to 'Response Headers' in API Gateway Console.
Choose Unauthorized (401)
Below 'Response Headers' add AuthorizeUrl and url
Save and deploy API to some stage.
To add this to Cloudformation, refer to this similar answer.
You can also add this to swagger, by adding this snippet(yaml):
x-amazon-apigateway-gateway-responses:
UNAUTHORIZED:
statusCode: 401
responseParameters:
gatewayresponse.header.AuthorizeUrl:"url"
responseTemplates:
application/json: "{\"message\":$context.error.messageString}"
In the API Gateway console go to the "Method Response" interface. You can add HTTP Status 401. In "Response Headers" add your custom "AuthorizeUrl" header. Then in the "Integration Response" interface you can add the value you'd like for that header.

Mediation sequence for DELETE method in wso2 not working

I have a SOAP web service for delete action, with endpoint URL
http://some-ip-address:my-port/bank/websrv/delcus
And can be invoked only by POST method.
I have published this API and added DELETE resource for invoking this service.
So the URL becomes
https://my-apim-endpoint/public/customer/{customer-id}
And I added mediation sequence for DELETE action. So whenever this API is invoked, it will go through the mediation sequence and send POST request to the endpoint
http://some-ip-address:my-port/bank/websrv/delcus
But when I invoke the API, the endpoint URL is getting replaced with the following URL.
Here is how the send mediator looks like,
<send>
<endpoint>
<http method="post" uri-template="http://some-ip-address:my-port/bank/websrv/delcus"/>
</endpoint>
</send>
http://some-ip-address:my-port/bank/websrv/100000023
Instead of
http://some-ip-address:my-port/bank/websrv/delcus
And giving me error response. Please anyone can help?
When you use http type endpoint, the resource path get appended to the endpoint url. for example say you have an endpoint http://test.com/path and if you have defined a /resource/{id} resource, then the request will be sent to http://test.com/path/resource/{id} kind of a url. That is the default behavior.
To call a SOAP service instead of using http type endpoint, you can use use address endpoint type. when you create endpoint with address type, you can define whether it is a soap11 or soap12. (format option in advanced options section in the implement tab). this will send a soap payload to http://test.com/path. (you do not have to build soap headers etc. only message body) .

Custom HTTP method at Mule HTTP point

I use Mule as REST API <-> AMQP.
And I have to send custom Request Method: "PRINT", but I'm receiving:
Status Code: 400 Bad Request
The request could not be understood by the server due to malformed syntax.
Do you have any ideas how I can add custom HTTP method to Mule?
Unfortunately, because of this validateMessage() method here Mule rejects any method not listed here :(
I guess you need to open a bug with MuleSoft, asking for the capacity to configure extra methods, and in the meantime create a patch for the transport.

Default HTTP method for outbound endpoint in MULE ESB

What is the default HTTP method that an outbound endpoint in MULE uses? For example, if I have the following endpoint:
<https:outbound-endpoint exchange-pattern="request-response"
address="https://api.example.com/makeCall">
Will the message be sent with a GET or POST?
Since the method property of an HTTP/HTTPS outbound endpoint is not required, there is no default property set by Mule - according to the Mule documentation.
However, this blog post suggests that the default method for an outbound endpoint, like the one in your example, is POST. Since this blog post isn't official, I can't guarantee it's reliability. Hope this helps!

Resources