Mule Cache Scope Error com.hazelcast.nio.serialization.HazelcastSerializationException - mule

I am using Mule Cache scope to save JSON data (converted to string) retrieved from a REST call. All works fine locally but when deployed to the server which is clustered I get this error.
com.hazelcast.nio.serialization.HazelcastSerializationException: java.io.NotSerializableException: com.rabbitmq.client.impl.ChannelN
Not sure why it is trying to serialize rabbitmq channelN.

When cache scope includes any Rest calls (i.e HTTP Request configurations) , make sure you have Dataweave or Byte array to String or Object to String to make it as consumable payload. Because HTTP request configuration output will be "grizzly Bufferinputstream" which is not consumable payload and its not serializable

Related

Fetch Request body in webclient when using Mono zip to identify which request fails

I am using webclient to call 3 different external APIs in parallel using Mono zip. Now, if any error occurs in any of the API call, I have handled it through a common exception handler using ExchangeFilterFunction. Now, I want to know which particular request fails(out of 3 external API calls) ? Is there any way I can identify that? I also want to append the 'input request body' with the exception response I got from the API call. Can I fetch the request body for which the API Fails (in filter itself)?
In the ExchangeFilterFunction you have access to the request. You could "decorate" your request with some identifier and then use it to resolve the client.
You could add some request header to identify the client.
To keep it internal, you could use request attributes of the WebClient and then read it from the request object
webClient.get()
.uri("...")
.attributes((attributes) -> attributes.put("internal_client_id", clientId))

WSO2 EI - how to handle malformed JSON requests in API

I have created an API in WSO2 EI.
API is expecting the requests to be send as JSON.
If it is a malformed JSON which is sent, then I should be able to receive it and make appropriate changes to make it a proper JSON.
Any help is much appreciated.
As we are using json-eval($.) to get the message to property, it is not working for me. What else i could try instead of json-eval to get the message as string.
WSO2 EI has the property force.json.message.validation, which can be used to validate incoming JSON payload. Please refer doc to configure this property in 'passthru-http.properties' file.
Once the property is configured, if there is a malformed JSON payload in the request, the mediation flow will be directed to the fault/error sequence. So, you can define the mediation logic to make appropriate changes to the malformed content within the fault sequence of your API.

Getting SOAP request as POJO in Mule

In our project we expose a number of web-services that were generated from a wsdl. After generating them, I can see that the requests and responses are mapped to POJOs and when I am making the response, I just set a new POJO. This works really nice. However, I have a problem with the request. When we receive the request I expected that the payload will be a POJO mapping the parameters from the request. The payload becomes actually an array of objects. I can access the values but this is not very comfortable. You can take a look at the picture.
I can see that the under "Variables" in the method it is correctly matched to the POJO we would like to have. Is there some setting that I am missing somewhere so that we can get the payload to be mapped to correct POJO type?
Re-run the WSDL to Java codegen but this time with wrapper style disabled, see: https://cxf.apache.org/docs/wsdl-to-java.html#WSDLtoJava-wrapperstyle

Receive a http post in BizTalk orchestration

I have a wcf restful service that accepts http posts.
I am trying to send this to an orchestration with a rcv message set as XmlDocument. (Since no subscribers where found when set to system.string)
The message is received in the orchestration but the xmldocument is invalid so its not possible to do anything with the data(Im sending a string in the http post). (When I attempt it I get an error that the data at the root level is invalid).
How can I get the http post string into my orchestration? Do I need to add a custom pipelinecomponent that adds xml tags to the string to make it a valid XmlDocument?
My solution:
Created a flat file schema where the string in the http post is added to one line. Added a pipeline with a flat file dissasembler with the schema. Use xpath in orchestration to retrieve the string.

Mule parsing Incoming REST request

I have a REST client that is preparing payload in JSON format and invoking a REST service. My job is to create the REST service in Mule. I need some information on how I can map the incoming Payload to a java object so that I can invoke the REST service component class and get the values passed in the JSON object. Does the payload after HTTP inbound endpoint already contain the JSON values sent by the client? In which case a simple JSON to Object mapper would map it as Hashmap?
You will most likely need to create a custom transformer for this use case if you have a special use case.
See: http://www.mulesoft.org/documentation/display/current/Creating+Custom+Transformer+Class
If you get sent JSON you can convert it into a custom class like this:
<json:json-to-object-transformer name="jsonToFruitCollection" returnClass="
org.mule.module.json.transformers.FruitCollection"/>
Alternatively You can also use ObjectMapper and can probably use a bean to map your JSON directly to your Java object in your Java class.
You can also use <json:json-to-object-transformer/> directly after your Http inbound endpoint, parse and get each element value in your Mule flow and store in variables. Then these variables can be passed into your Java class where you can map these to your Java object easily.
Both the approach will work fine