how to skip the dynamic arguments when it is empty in payloadFactory wso2 esb as XML - wso2-esb

We are using WSO2 ESB, and we are using payloadFactory mediator to transform the message. we have entered into scenario where we need to ignore the payload arguments when it is empty or null. can any one help us achieve this?

You can try using filter mediator wherein you check the arguments in xpath, if arguments exist then you can call payload mediator with all the arguments, else you can call another payload which doesn't contain those arguments.
However according to me the best practice would be to use an xslt mediator where you put all your logic in the xslt, this would make your sequence small in length and more readable.

Related

How to convert Object to String in mule esb?

I am working with Mule ESB and our goal is to use dropbox as a end point connector means to store data to dropbox(from CSV/doc or any other data source). We are able to store data to drop box but data stored in the form of object and that is not in readable format so how to convert object to string so that it can be in readable format ?
Mule already has Object to String transformer to transform String from Object :- https://developer.mulesoft.com/docs/display/current/Transformers
What I think you're after is called object serialization, and you have many choices about how to do it in a way that people can read it.
Perhaps the oldest way in java (which is the language Mule is based on) is to implement a toString() method and format your object's data as you like. Of course, this means your message payload must be an instance of a class you can make changes to. If you choose this method, you can simply add an <object-to-string-transformer /> as Anirban suggested.
Some common ways people do this, especially with Mule ESB, is to use XML or JSON to represent the information in the object. Mule includes strong support of XML and JSON. Many times, you can simply add a <json:object-to-json-transformer /> to your flow, and the payload will be converted automatically. For this to work, your payload needs to be simple types such as Maps and Lists, or an instance of a class with JAXB mappings.
Your question is a bit confusing .
if you are asking about the transformation in mule add this in your XML file <object-to-string-transformer doc:name="Object to String"/> after the dropbox component.

Mule :Inbound connector consuming only if a business requirement is met

I am having this requirement in a mule service that it should consumes from an inbound connector(flow message source) only if a business condition holds true. I need to look into the database whether that condition holds and then only my inbound connector should start consuming.Each time it should check for that condition and consume only if condition is true. Suggest best way to achieve implementation in mule.
Although a message filter is theoretically correct, in practice this is often accomplished using the Database Connector with a SELECT query that determines which rows should be processed in its WHERE clause. You can place the query in a <poll></poll> element at the beginning of a flow to execute the query on a schedule, as illustrated in the second example here.
This is something difficult to say without looking into your flow what exactly you want to implement .. Generally if you want your inbound endpoint to consume and the flow to work , the best option is to put a message filter after the inbound endpoint which will check the condition and allow the message to pass to next processor..
Since here you want to check the condition from the Database, what you need is to put a DB component after the inbound endpoint which will fetch the value of the business condition from the DB and then you can put either the message filter or Choice router to pass the message payload to the next Mule component
This is tipically done using the message filter integration pattern.
This pattern is implemented in Mule as (and only as) Filters, other patterns that could do the trick, specially routers and detour, but the more consistent way of do it is with filters.
In the case of Mule, you have a number of filters however there is no sql query based filter out of the box. This said. You have a number of options:
a Filter in java, that you could instantiate as a spring bean injected with the datasource and then use as a custom filter with ar ref.
if this is meant to be reusable, implement as a DevKit module.
as a workaround, implement a sub-flow that leverages the database conector to fetch the query result and to then filter or not at the end of the flow with an expression filter.

validation against xsd and route invalid xml to rabbitmq in mule

I am trying to validate xml again xsd and route invalid one to rabbitmq in mule.
I found schema validation component in mule but it seems like it only filter invalid one and pass valid one to the next flow.
Does anyone know how capture invalid one and route to rabbitmq queue in mule?
Thank you in advance.
You can wrap the schema validation inside a message filter.
This will pass the messages on to a flow named DeadLetterQueueFlow:
<message-filter onUnaccepted="DeadLetterQueueFlow" throwOnUnaccepted="false">
<xml:schema-validation-filter/>
</message-filter>

Best way to handle static/constant values in Mule config

What is the best way to handle static/constant values in Mule config? I have a many flows that utilize expressions that need some static values. I was thinking of just creating a simple Java class to hold these and using MEL to access them. But is there a better way and possibly just using Mule config? Maybe set flowVars everytime for these values or use spring propety placeholders?
Store these values in a properties file and use them with ${ } placeholders in your expressions.
#jonlee I would use spring property placeholder. here is the reference doc

How do I add a SOAP template from XSD in soapUI when XML extension is in place?

I need to make a large number of SOAP test cases to automate the testing process of an application.
Currently, the architecture requires that a single "generic" SOAP method is invoked with an object of a generic type. Each "real" operation is defined by an element in the generic object and requires an object of an extended type to be used as input.
When I create the request template with soapUI, I only get the generic object elements, but I would like to add the empty template for a specific XSD type that is defined in my current schema to be used.
If I use xsi:type then soapUI correctly says that my markup is not valid against the schema (missing required elements), but I can't manage to get a ready-to-fill XML template.
Can you help me?
Example
genericRequest is made of
<genericRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
</genericRequest>
sumReuqest (extending genericRequest) for a "sum" operation is made of
<sumRequest>
<methodName>specificMethodName</methodName>
<authenticationID>ABCDEF</authenticationID>
<addend>5</addend>
<addend>3</addend>
</sumRequest>
I would ultimately like soapUI to fill a SOAP template with empty addend item (of course I work with lots of elements, and they are structured too!!)
In this case you need to create two resources in soaupUI one for generic request and other for operation request, I know right now its pain to create each resource for each operation, but soapUI is developed like that or if you think any of the parameters listed : http://www.soapui.org/REST-Testing/understanding-rest-parameters.html could help, you could define parameters as one of the above.
you could try using QUERY or MATRIX style parameters in your resource.