does wso2 esb xml transform support grovvy - wso2

I know that I can use xslt to transform xml, but it costs a lot.
I would like to know whether it is possible using grovvy or not.
Assume I have two xml schema, and transfer them into java file, build to class and deploy to esb.
And I transfer xml via groovy so that I can dynamically change the mapping without deployment java code.

WSO2 ESB supports Mediators implemented in a variety of scripting languages such as JavaScript, Groovy. (https://docs.wso2.org/display/ESB481/Script+Mediator)
To execute a Groovy script using the WSO2 ESB's script mediator follow below tutorial
http://heshans.blogspot.com/2011/05/executing-groovy-scripts-using-wso2-esb.html

This is a Groovy sample I wrote using WSO2 ESB Script mediator. This is for Json payload. However you can do the same for XML. Get payload using mc.getPayloadXML() method and use Groovy XmlSlurper class to parse xml to Groovy objects.

Related

combining two api json response using wso2 developer studio

I can't seem to find a way to combine two api json response by using wso developer studio. I'm still reading their documentation and i found that there is a mediator called aggregate mediator but i can't seem cant to find a way to combine the api calls and map it all while using the wso developer studio. So for example Google Contacts and Fullcontact api combines the response
In aggregate mediator, you can not aggregate responses coming from different services. When you are using aggregate mediator you have to use it with clone/iterate mediators. Those mediators will send identical clones/ chunks of message to different endpoints. Those responses will be gathered by aggregate mediator.
In your scenario, you have to use Service Chaining pattern in ESB. Please refer WSO2 documentation [1] and this blog post series [2] will help you to implement your scenario.
You can implement this pattern using developer studio. Just identify what are the components (Ex: Proxy) you need and implement them through Dev Studio.
[1] https://docs.wso2.com/display/ESB490/Service+Chaining+Example
[2] http://dakshithar.blogspot.com/2012/06/routing-and-service-chaining-with-wso2.html
It is difficult to recommend the mediators that you should use, without knowing exact use case. Scatter-Gather pattern with clone and aggregate mediators would be fine if your services are independent(one does not require other's output as input).
If they are dependent, invoke the first one using mediator and you may use a property mediator to remember the output. After the second call, you can combine them using a Payload Factory mediator or, if it is a complex integration, you may use XSLT mediator.

Mock ups in Mule Esb web services

I have some web service (CXF) on Mule Esb (3.4). At the current moment I try to find the simple way to set up web service response that I need for UAT. I read a lot of information in the internet and as I understood there is a special framework Munit for all types of testing. But, it seems, this framework is used for more complex things than I need. So, could anybody recommend me a simple way to force Mule Esb return predefined xml response. It will be fine if I create an xml response as xml document, upload it in any folder and Mule will send it as response when I call a web service. Thank you for any info for solving my task.
You could probably upload the example responses to the classpath and then, in your flows just load that file and set it as payload.
See this other stackoverflow question around how to accomplish this.
You could use 2 flows.
1 flow for production with the Webservice implementation and 1 flow for UAT testing which returns you just a predefined XML (for example via the http endpoint).
Put both files in a seperate file and make a mule-deploy.properties file for both UAT and Production where you include the corect flows respectivly.

defining REST, specifically JSON contract in WSO2 Developer Studio

I am new to WSO2 and don't know how to use the declaritive programming widgets to create the REST contract. My use case; I have a backend SOAP 1.2 Web Service that I want to wrap with a REST API in WSO2. I don't know what media to use to define the JSON data contract so it is avalable in the sequence flow. I want to be able to visually map from the JSON payload to the SOAP payload. I really wanted to have two declaritive objects that I drag onto the sequence pallet so I can map from the JSON to the SOAP XML.
Thanks much
You can use a XSLT mediator (Sample 440) or Script mediator (Sample 441) to do the JSON to SOAP mapping. But you will have to type in the XSLT template or the script content manually after adding the mediators through Developer Studio. I don't think you can visually map elements from JSON payload to SOAP.
Go through above samples or this webinar to learn how do the transformations.

Is it possible for Spring RESTful services to privde a WADL or something similar?

Situation:
We are planning to build a set of new services a long side a set of old SOAP (Spring, apache CXF) web services. Our customers are used to being able to use ?wsdl to get a wsdl describing a service and the content it will accept/return.
I'm looking at providing the new services via spring controllers and RESTful urls. However not all of a request can be handled via a RESTful url, so we still need to have a payload request and responses. I'm looking at use #RequestBody and #ResponseBody and spring's Message Converters to auto(magically) handle both XML and JSON content. The idea being to let spring do as much of the heaving lifting as possible.
The problem:
I'm trying to figure out if it's possible given the REST/Message converter concept, to be able to provide a description of a service and it's request/response data in a similar fashion to the ?wsdl request. I understand that there are WADL documents that can be generated by some systems, but they appear to be a proposel and not fully accepted yet.
Does anyone know if spring can generate WADLs or something else that I can use to allow clients to query the RESTful services data structures?
SpringMVC doesn't support WADL auto generation, mostly because it doesn't use the JSR-311 standard REST API.
I have create a blog entry with a simple WADL generation Controller in java :
Tuxgalaxy Blog Entry.
But Tomasz Nurkiewicz also provide a WADL generation Controller in scala :
nurkiewicz Blog Entry.
You could use CXF JAX-RS for your REST services since you're already using it for SOAP (you can even expose the same service as SOAP and REST with CXF), and CXF gives you the WADL that you want by adding ?_wadl&_type=xml
The following code will work with Spring REST 4x and its based on the suggested code by tuxgalaxy provided on below https://jira.spring.io/browse/SPR-8705
http://javattitude.com/2014/05/26/wadl-generator-for-spring-rest/

How to customize response structure when working with Axis2 REST web services?

I'm using Axis2 1.4.1 to expose RESTful web services. I need to return xml structure (or any other for example ATOM xml or RSS xml or JSON structure) of my choosing. Axis2 out of the box returns it's own default xml structure (which is SOAP like). The question is what is the right way to customize this.
Is it via Handlers? Is it via Data Binding? Is it via custom MessageFormatter? What is the way and how?
Thanks