How can i use the Mule Studio data mapper for producing output generated from a complex XSD schema ? - mule

I want to post a message to a SOAP webservice with MULE Enterprise edition.
For creating the Request object i am using a data mapper with the
input a POJO and for
the output i selected XML , and from example XML schema i added my own XSD.
Because there are a lot of elements in the xsd, i selected the root element from the list provided.
Then i am dragging the fields from input to the corresponding values i want in the output.
(i also tried to map just one field, to be sure that i keep the minimum the probability for error).
And now the problem:
when the flow is accessed, the following WARN is shown and the data-mapper fails
*[XML WRITER:EXT_XML_WRITER0] - Invalid mapping (With port binded to root element, result might contain multiple root elements. Such XML is not well-formed. To avoid that, set 'Records per file' or 'Max number of records' component attribute to '1'.)*
Where can i set this kind of options in the data mapper ?
And also i want the root element to be only one, i don't need a foreach for the root element, i just need to fill the contents of it. Can i specify this anywhere in the data mapper ?
Thanks.

Mule EE DataMapper uses CloverETL for data transformations, and this annoying warning concerns CloverETL settings. I don't know if you can advise CloverETL to use a specific configuration file in the context of Mule DataMapper, but you can always edit the mapping file generated by Mule with a text editor. Just find your root Node entry in the mapping file and add recordsPerFile="1" attribute.
The problem with this is that Mule may overwrite your manual edits if you use the graphical editor, though.

Check out the Anypoint Studio May 2014. Mule now includes a new Web Service Connector for posting messages to a SOAP web service using just a WSDL. Studio will read the XML Schema from the WSDL and automatically create the metadata for DataMapper for you. See http://www.mulesoft.org/documentation/display/current/Web+Service+Consumer for more details.

Related

How to switch between different properties files based on request at runtime?

Currently I read properties file by defining a global element like;
> <configuration-properties doc:name="Local Configuration Properties"
> doc:id="899a4f41-f036-4262-8cf2-3b0062dbd740"
> file="config\local_app.properties" />
But this is not enough for me
when try to deal different clients dynamically.
Usecase
I need to pick right configuration file when request comes in. That is, for different clients I have different properties file.( their credentials and all different). When request is received from listener, i'll check with clientid header and based on that value, i'll pick right configuration file. My properties files are added to different location.(Doing deployment through openshift.) Not within mule app. So, we don't need to redeploy the application each time, when our application supports new client.
So, in this case, how to define ? and how to pick right properties file?
eg:
clientid =google, i have properties file defined for google-app.properties.
clientid=yahoo, i have properties file defined for yahoo-app.properties.
clientid=? I'll add properties file ?-app.properties later
Properties files are read deployment time. That means that if you change the values, you to redeploy the application to read the new ones. System properties need a restart of the Mule Runtime instance to be set. And Runtime Manager properties need a restart of the application. In any case the application will restart. Properties can not be used as you want.
There is no way to use configuration properties dynamically like that. What you could do is to create a module using Mule SDK that read properties files and returns the resulting set of properties, so you can assign the result to a variable, and use the values as variables. You will need to find a way to update the values. Maybe set a flow with a scheduler to read the values with a fixed frequency.

AEM OSGi Configuration Multified Property with two or more fields

Currently, we are able to use #Property(unbounded=PropertyUnbounded.ARRAY) to create a property in OSGi Configuration with Multiple-Values.
Is it possible to create a property in OSGi Configuration that behaves same as that of multifield functionality of AEM authoring dialogs? On click of Add button, the property field with all its-sub fields gets increased. So that we can add multiple entries of key/value pair.
[
{
"path":"/content/demo/page1",
"date":"20-12-2018",
"language":"english"
},
{
"path":"/content/demo/page2",
"date":"23-10-2019",
"language":"french"
}
]
The same key/value pair to be configured using OSGi Configuration and fetched as required.
The felix console allows you to add multi-value properties. however, they are typically a single field value. Meaning, you cannot create the complex data structure in your question. However, I have seen implementations that allowed you to enter an ordered CSV. For example, you could have a multivalued String OSGI property where each property is of the format:
<path>,<date>,<language>
your first entry then becomes:
/content/demo/page1,20-12-2018,english
Or, you could even enter the whole JSON as a string value, then parse it when you need it. But that becomes ugly to enter very quickly.
You can use the above with any serializable data structure, but the more complex it gets, the harder it is to enter in a single input field.
Another option would be to create a page with a component that has a multifield and just point your OSGI config to the path of that page/component, then in your OSGI service, lookup that path and extract the configuration.

Mule Multiple flows loading shared properties file

I have a mule application comprising of 10 mule XML files. Some of these XML files need to use same property from commong prperties (config.properties) file.
(1) Should ALL the flows that need use a given property load the properties file containing that property using --
<context:property-placeholder location="config.properties" />
(2) OR should only one of the XML file add property-placeholder?
(3) If option (2) is right, then does the order of mentioning the xml files as config.resources in mule-deploy.properties play any role?
Please shed some light on this.
You only need it once, and it does not matter where you put it.
You only need one property file and you can setup this for 3 environments liks DEV,QA and PROD and setop property to pick right file.
There is a lot of documentation that shows users different ways to read a properties file in Mule flows.
Here are three approaches on how you can do this:
Reading a properties file using ${Key} expression
Reading a properties file using ![p[‘Key’]] expression
Reading a properties file using p() function from DataWeave
If you deploy multiple applications through a Shared Resources structure, don’t set anything in the properties files, as there might potentially be conflicts between the various apps that share a domain. Instead, set environment variables over the scope of the deployed app, its domain, and other apps under that domain.
As explained in Shared Resources, in Studio you can create these variables through the Environment tab of the Run Configurations menu, reachable via the drop-down menu next to the Play button.

Create api using mulesoft studio

How can i create a simple api using mulesoft stodio? I am using the MySql Database and trying to create REST apis and following this tutorial.
http://www.mulesoft.org/documentation/display/current/Creating+an+API+for+a+MySQL+Database
But facing the error
Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: ArrayList
You have something wrong with your DataMapper definitions, probably a mismatch between the data coming from MySql and the data types for the fields in your DataMapper. Check your data types, the complete error message in Mule Studio, and the output of the Logger between the MySql component and DataMapper if you have a configuration similar to the example in the tutorial.
i was in assumption that the data mapper source data does not match with the payload it received.
according to error , the data-mapper input is of some format you defined but the received input is of array-list.
I am getting the 404 response on the link that you had mentioned in your question.
Your error is not related to what you were asking about How to create Rest API in mule.
As per concern about creating Rest API mule offers two ways:
Using the Rest Component (Recommended when you have rest specification defined in java using the jersey or apache-axis)
ApiKit Router with RAML (Higly recommended by mulesoft community)
As per your concern about error.
you might have not properly mapped the input fields of datamapper with the outbound messages from DB connector.
DB Connector always returns the response as ArrayList that need to be caste into any collection like Map or Array.
I recommend kindly use data sense feature of mulesoft DB connector that will automatically map the input fields of data mapper.
if possible share your flow.
Hope this helps.
Check the inbound properties of data mapper. output of DB query should not be in unknown format. If it is unknown format, then there is something wrong with your query output.
If you are looking for API creation, then check out the below link.
https://docs.mulesoft.com/anypoint-platform-for-apis/walkthrough-design-existing
check the document how to create API
https://docs.mulesoft.com/anypoint-platform-for-apis/
and regarding the DataMapper error just check the input data type to the output data type you are mapping. just cross check the input format to output format.
I suggest to use data weave now . Data mapper is obsolete . Define metadata for your HTTP end by giving some sample JSON and with database you will automatically get metadata extracted by data sense. Now you can use drag and drop for mapping your fields and it will transform input to requited output. you can also look data weave expression generated and now you can change that easily to tweak that.

How to set http headers in dotCMS

I'm trying to create a XML data feed with dotCMS. I can easily output the correct XML document structure in a .dot "page", but the http headers sent to the client are still saying that my page contains "text/html". How can I change them to "text/xml" or "application/xml"?
Apparently there's no way to do it using the administration console. The only way I found is to add this line of (velocity) code
$response.setHeader("Content-Type", "application/xml")
to the top of the page template.
Your solution is the easiest. However there are other options that are a bit more work, but that would prevent you from having to use velocity to do the XML generation, which is more robust most of the time.
DotCMS uses xstream to generate XML files (and vise versa). You could write a generic plugin to use this as well.
An JSONContentServlet exists in dotCMS that takes a query and generates json or xml (depending on your parameters). It is not mapped on a servlet by default, but that is easy to add.