Mule: HTTP connector failing due to string payload - mule

I am trying to make a rest call via the http connector. I build the payload as a string, then when I am trying to send it to the client, I am getting the following error:
org.mule.api.MessagingException: Error sending HTTP request. Message payload is of type: String
the string looks as follows:
{
"firstName": "Nathan4",
"lastName": "Tregillus",
"email": "ntregillus#solarcity.com"
}
at this time I am just confused. is there only one type of body I can send?

Since you do not show your config I would suspect that there is some problems your mule instance and the service you're consuming, or the remote endpoint is having trouble generating the response. So you can check your config:
Methods (POST or Get)
Path
config-ref
name

Related

Spring Integration DSL access error body in error handling flow

I’m not able to access the error body in my spring integration error handling flow
Message received from external system
Status: 400 Bad Request
Response body:
{
“title”: “record already exists”, “errorCode”: -1
}
Tried to access the response body but unable to do so
msg.getPayload().getCause(), (MesaagingException)msg.getPayload().getRootCause() doesn’t work either. Only able to retrieve the status.

Accessing POST REST API in mulesoft

I am trying to consume RESTAPI in MULE, endpoint I am trying to access is type POST. How can I set JSON payload while sending request ?
By default, the body of an HTTP request from Mule is the payload of the message. You can use the Transform Message component, or the Set Payload component to set the payload before the HTTP request.

AWS: Amazon API Gateway Unknown Endpoint Error upon Testing Deployed API

We have an API that we would like to try connecting with the Amazon API Gateway. I've been trying some very basic calls, but to no avail. For example, if we don't pass any authentication data in the query strings during the GET call using Postman:
GET https://<host>/<resource>
Then I correctly receive an error message:
{
"error": "Invalid authentication key",
"errorcode": 0
}
In the Gateway I have the following settings for the method:
Method Request
No Authorization, API Key not required
Some query string parameters which are not being set in either Postman or the API Gateway call
No request headers
no request models
Integration Request
HTTP Proxy Integration type, GET
Endpoint URl is the same URL I call using Postman above
No parameter, header or body mappings
Integration Response
Single 200 OK passthrough
Method response
Various HTTP Statuses
Response model as per our API's Swagger definition
All other methods have mock integration. Calling the method via Postman at our backend domain works as intended (i.e. gives the error message above).
Calling the deployed API Gateway method, however, results in:
"message": "Unknown endpoint error." if done using the Method Test in the API Gateway
"message": "Internal server error", if called from the browser or Postman.
Has anyone experienced this issue before?
EDIT: I just noticed that one of the response headers that are set when using Postman or Browser is:
X-Cache: Error from cloudfront
The docs says that this errror is set if the origin server returns an expired certificate, an invalid certificate or a self-signed certificate, or if the origin server returns the certificate chain in the wrong order, but our certificate is valid and I cannot note and problems with the certificate chain...

Unable to Pull Message off Queue

Let me explain my configuration:
ActiveMQ 5.12.0
AnyPoint Studio 5.2.1
Mule 3.6.1
Flow of application:
I am using FunctionalTestCase to post and retrieve a message from queue.
MuleClient client = muleContext.getClient();
String productAsJson = "{\"name\":\"Widget\", \"price\":9.99, \"weight\":1.0, \"sku\":\"abcd-12345\"}";
client.dispatch("http://localhost:8081/products", productAsJson, null);
MuleMessage result = client.request("jms://products", RECEIVE_TIMEOUT);
What is happening is the message is getting posted but when I try to retrieve it, I get the string "{NullPayLoad}".
After stepping back through the flow, I have discovered the message payload, when using the Mule Client, is not making the queue. While looking through the admin console for ActiveMQ, I discovered the message details is "{NullPayload}". When I check using the Advance Risk Client, the JSON message is getting posted correctly.
Any suggestions would be greatly appreciated.
Russ
It's NullPayload when using the MuleClient because by default the http operation will be GET and wont be expecting a body to parse.
The MuleClient is more suited to working with Mule transport infrastructure such as the JMS transport or the old http transport. I don't think it plays nice with the new http listener module.
Normally with the transports you can set the method via a property but that doesnt seem to work with the http:listener:
MuleMessage message = getTestMuleMessage();
message.setPayload(productAsJson);
message.setProperty("http.method", "POST", PropertyScope.INBOUND);
client.send("http://localhost:8089/products", message);
I would suggest using a standard HTTP client such as Apache HTTP client etc. and set the method to POST/PUT or whatever method you need to use that expects a body.

Spring Integration: How to send response packet to client in case of exception using error-channel?

I am using Spring Integration in my project.
Endpoints used in application are in-bound gateway, header based router, transformer, spliter, service activator.
In case of success flow(not any exception), in-bound gateway reply-channel getting desired response and client gets that response which is fine but in case of any exception, I want to send customized error response which is not working as per my requirement.
I am using error-channel to accomplish above requirement but not succeeding in that.
Please find my configuration of in-bound gateway, error channel etc.
I have not use any chain in configuration.
<int-http:inbound-gateway id="inboundGateway"
supported-methods="GET, POST" request-channel="requestChannel"
path="/services/tylv/{requestParam}" reply-channel="responseChannel"
error-channel="errorChannel">
</int-http:inbound-gateway>
<int:transformer ref="errorHandler"
input-channel="errorChannel" method="generateErrorResponse"
output-channel="responseChannel" />
<bean id="errorHandler"
class="com.csam.wsc.enabling.integration.transformer.ErrorHandler" />
In case of exception , com.csam.wsc.enabling.integration.transformer.ErrorHandler.generateErrorResponse(ErrorMessage) successfully called.This API handle exceptions, generate Error Response Packet but it is not being sent to client, just only HTTP Status Code 200 sent.
Ideally it should be sent because transformer's output-channel is reply-channel of inbound-gateway which is already sending response packet along with status code 200 in case of success (no any exception).
I think in case of error-channel , in-bound gateway reply-channel is not working, but I am not sure.
Please help me in configuring error-channel.
You should store the message's headers before the error reaches the error channel and then you should create a new message with the stored headers and route that new message to response channel.
MessageBuilder.fromMessage(errorResponseMessage).copyHeadersIfAbsent(storedHeaders).build();