skiplines in smooks mediator not working in wso2 ei [duplicate] - wso2

I am using smooks mediator to convert csv file to json using VFS. We have an option to skip header row while using the CSV connector/module. How do I skip the first row of headers while processing the file in WSO2 Integration studio using smooks?

In your Smooks configurtion add the following option.
skiplines="1"
Full Smooks Config
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.5.xsd">
<csv:reader fields="name,age,address" separator="," quote="'" skipLines="1" />
</smooks-resource-list>

Related

[WSO2][ESB] Could not build deploy CAR file with PROPERTY mediator

There seems to be an error while trying to build a REST API.
My REST API has a custom mediator:
<class name="my.com.tm.myipcs.custom.mediator.ValidateHeader">
<property name="source" expression="get-property('source')"/>
</class>
Yet when I save it, the Developer Studio shows an error as below:
Unknown synapse configuration tag:
At line 18,
I am using Eclipse Mars. and the WSO2 ESB Server 5.0.0 is my server.
Can some one suggest a workaround or better a solution.
Thanks in advance.

In wso2 esb how to read endpoint from a file

In wso2 esb what is the best practice for Endpoint maintenance. From some article I got to know that we can read from file So, if this the best approach how achieve this one.
In a scenario where the endpoint is saved as a file within the carbon registry (You can even upload the file via management console or can use WSO2 EI Tooling to create an endpoint template), we can read the content of the endpoint as follows.
Add the endpoint registry resource.
Log the endpoint content using the following synapse configuration. (Can even retrieve specific attributes within the endpoint using their xpath expressions)
<log level="custom">
<property name="Endpoint Content:" expression="$ctx:endpointFile//*"/>
<property name="Endpoint URL:" expression="$ctx:endpointFile//*[local-name() = 'address'][1]/#uri"/>
</log>
You can see the logged endpoint content as below.
There are 3 ways to Endpoint Maintenance.
Using ESB Tooling
From Command Line
Using a Script
More details can be found in WSO2 Documentation.

Adding a header to a XML message in Synapse

Using Synapse 2.1, I am trying to transform an XML message with no header into a SOAP message with a header containing credentials to consume a web service. Something like this:
Synapse incoming message:
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
...TAGS...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Synapse outgoing message:
<SOAP-ENV:Envelope>
<SOAP-ENV:Header>
<yta:Authentication>
<yta:UserName>srnm</yta:UserName>
<yta:Password>psswrd</yta:Password>
</yta:Authentication>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
...TAGS...
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How could I configure Synapse to do it? I am successfully using a transform file to update the body of the message, but not to add a header to the output.
I tried using the header and property mediators in the configuration file, but I am not sure what is the way to go. Reading about the header mediator it says "At the moment set header only supports simple valued headers". Could this be the case?
Thanks
For the record, I ended up using a script mediator with an inline javascript script in the configuration file using the addHeader method. See below:
<script language="js">
<![CDATA[
var user = mc.getPayloadXML()..*::UserName.toString();
var psswd = mc.getPayloadXML()..*::Password.toString();
mc.addHeader(false, <yta:Authentication xmlns:yta="yta:namespace url"><yta:UserName>{user}</yta:UserName><yta:Password>{psswd}</yta:Password></yta:Authentication>);
]]>
</script>
You can use XSLT mediator to manipulate it. So add an XSLT transformation with required headers and it would add required headers. Or use Script mediator / Class mediator where you can manipulate message.
Please refer followings which will be useful.
http://wso2.org/forum/thread/10794
http://wso2.org/forum/thread/10843
If this xml structure is not needed.
you can use Http Headers you can use properties as below.
http://blog.thilinamb.com/2011/04/how-to-access-web-service-using-http.html
Looks like you want to secure the service. The easiest then, is to use username-token security. Go to the services dashboard in WSO2 ESB for your proxy service and secure it, using UT. Also see http://docs.wso2.org/wiki/display/ESB460/Sample+200%3A+Using+WS-Security+with+policy+attachments+for+proxy+services for a security sample

WSO2 ESB custom properties for Smooks mediator

I need to use some configuration settings to transform message with Smooks mediator. For example I want to inject a base URL into attribute value of outgoing xml during transformation.
In Java I'd do it by adding beans to ExecutionContext. Looking at SmooksMediator code I do not see this. Can I do it somehow or I should extend and recompile SmooksMediator to supply properties form MessageContext?
For the input as the Smooks mediator we can feed only one stream from the ESB. So if you want to transform a message by injecting a property, you can't achieve it with the smooks mediator.
Use XSLT mediator for this [1]. When configuring the XSLT mediator you can define properties to be passed into the transformation.
ex:
<xslt key="orderTransformer">
<property expression="get-property('name')" name="name"/>
<property expression="get-property('email')" name="email"/>
</xslt>
Then inside the XSLT you can define the two properties as below,
<xsl:param name="email"/>
<xsl:param name="name"/>
and use them appropraitely as $email and $name in templates.
<ns1:email>
<xsl:value-of select="$email"/>
</ns1:email>
<ns1:name>
<xsl:value-of select="$name"/>
</ns1:name>
[1] http://docs.wso2.org/wiki/display/ESB460/XSLT+Mediator
The whole configuration details of Smooks mediator can be found from [1].
Else you can go for a custom mediator to perform your exact task. Detail on custom mediator can be found from [2].
[1]. http://wso2.org/library/tutorials/2011/06/perform-data-mapping-smooks-editor-wso2-carbon-studio
[2]. http://maninda.blogspot.com/2012/11/writing-custom-mediator-for-wso2-esb.html
Thank you,
Dharshana

WSO2 ESB - How to build soapenv:Body for remote service call

I have the WSDL file of the remote web service I need to call from a proxy service in the WSO2 ESB and would like to know if I need to construct the soap:Body's elements manually through XSLT/Enrich or there is a way to generate the soapenv:Body's contains from the WSDL and maybe replace '?' for the values.
For example, if you've used soapUI before you'll know that when you import a WSDL file in a project a soapenv:Envelope gets generated automatically with all the XML elements and question marks for their values. Same goes for the TryIt tool in the WSO2 ESB.
Here is an example of an auto-generated soapenv:Envelope in soapUI after importing WSDL:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="http://abc.com/">
<soapenv:Header/>
<soapenv:Body>
<abc:RegisterCandidate>
<abc:NameFirst>?</abc:NameFirst>
<abc:NameMiddle>?</abc:NameMiddle>
<abc:NameLast>?</abc:NameLast>
<abc:PhoneHome>?</abc:PhoneHome>
<abc:EmailAddress>?</abc:EmailAddress>
<abc:Address1>?</abc:Address1>
<abc:Address2>?</abc:Address2>
<abc:City>?</abc:City>
<abc:State>?</abc:State>
<abc:ZipCode>?</abc:ZipCode>
<abc:Country>?</abc:Country>
</abc:RegisterCandidate>
</soapenv:Body>
</soapenv:Envelope>
Is this possible in the Proxy Service through any of the mediators available to read a WSDL and generate soapenv:Body with its XML tags (in the code above it would be abc:RegisterCandidate with its children)? I've done it with the use of the XSL templates, but it's manual and not very elegant.
I've found a few articles/blogs online about writing proxy services in the WSO2 ESB that call remote web services and what the developers were doing in there was to insert the XML elements needed in the soapenv:Body with the use of XSL templates to have the correct/full SOAP message that is then sent (send mediator) to the remote web service server.
Thank you.
There is no way to generate the soap body from the remote service's wsdl as in your requirement. But there is an easier way than using xslt. That is to use the payload factory mediator. You can define the payload and assign values using xpath as shown in the sample.