I have saved an xml file in Configuration registry /_system/config/test.xml. My xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<ServiceDefinition>
<Source1001>Endpoint1</Source1001>
<Source1002>Endpoint2</Source1002>
</ServiceDefinition>
Now can i create a proxy to update the contents of the above xml file by use of sequence or class mediator? If i pass new endpoint= Endpoint3 and Node = Source1001 in the request of the proxy. then for the node Source1001 i should be able to see the changed endpoint as Endpoint3
Looking forward to your answers. Thanks in advance.
No built-in mediator can do this. You can write a class mediator to read the xml placed in registry, then save it after editing. You have to get the reference to registry service via osgi at the class mediator for that.
FYI. you can get the input from message context and find the values to replace.
This [1] post explains about creating class mediator to read from registry resource. Hope this will be helpful during your task.
[1] http://vvratha.blogspot.com/2013/02/accessing-registry-resources-from-class.html
You can use the following code segment within a class mediator or you can do the same with script mediator as well.
mc.getConfiguration().getRegistry().updateResource(
resourcePath, mc.getProperty("myProperty").toString().getBytes());
You can find more details on how to use either one of those mediators here
Related
I created one file test.properties in the //wso2esb-4.9.0/repository/conf folder.
In this test.properties files I created on properties given below
testData=welcome
Now, I want to read that testData value in the proxy files in WSO2.
Here is a proxy code to get the value:
<property name="irisprop" expression="get-property('registry','conf:/iris.properties#tokenvalue')" scope="default"/>
The get-property('registry','') will fetch the values stored in the registry 1. You can refer to the documentation on 2, [3] to further clarification regarding the registry. You can use the carbon console to browse and add the registry resources.
You will not be able to read a file content directly with the property mediator. But if your use case is to use the file system to store data, you will need to use the VFS transport or the file connector. Please refer to the documentation [4], [5] to further clarify this.
1-https://docs.wso2.com/display/EI6xx/Property+Mediator#PropertyMediator-Example4:ReadingafilestoredintheRegistry
2-https://docs.wso2.com/display/ESB490/Working+with+the+Registry
[3]-https://docs.wso2.com/display/ESB490/Managing+Registry+Content
[4]-https://docs.wso2.com/display/EI6xx/VFS+Transport
[5]-https://docs.wso2.com/display/ESBCONNECTORS/File+Connector
I want to use XSLT mediator in my custom sequence to transform message for an API. I have create XSLT file name "transform.xslt" and use following syntax in my sequences.
<xslt key="transform.xslt" source="*" />
My problem is, I don't know where to put the XSLT file. Do I have to put under synapse directory or have to import to carbon repository, or is there any other configuration ?
From WSO2ESB it seems there have to be some configuration in API definition but in case of WSO2 API Manager it is automatically generated and I don't want to edit the generated file.
Thank you very much.
You can upload XSLT file as a registry resource and refer that in the XSLT mediator.
1) Save XSLT file in local registry
- Log on to the APIM Management Console.
- Click on "Browse" in the left "Registry" menu
- Expand the "system" tree node and then click on the "config"
- Then click on the "Add Resource" option
- Upload the "transform.xslt" file and give the name as "transform"
- Click on the "Add" button.
You can refer uploaded xslt file in your XSLT mediator like below.
<xslt key="conf:/transform.xslt" source="*" />
I want to add a new child node to an XML request I'm proxying through to WSO2 DSS using an API.
The request I receive is in the following format:
<contacts>
<firstName>Bob</firstName>
<lastName>Brown</lastName>
</contacts>
I need to add an "id" node to this request that I can retrieve from a URI variable.
<contacts>
<id>1</id>
<firstName>Bob</firstName>
<lastName>Brown</firstName>
</contacts>
I've tried using the "enrich" mediator, but this seems to just wrap the ID node around the first name and last name nodes.
So I've resorted to using a script mediator to modify the request. This is what I'd like to do:
//Get XML Request from message context
var request= mc.getPayloadXML();
//Create a child node using standard E4X notation
var child = <id>1</id>;
//Append this XML to the request
request.appendChild(child);
//Replace the payload
mc.setPayloadXML(request);
Every time I try to submit this code, the WSO2 ESB API UI says that everything is cool. But when I check the underlying XML configuration, it is not cool. Where I defined "id" node is now just blank, as if it was filtered without my knowledge!
It would be great if I could add this element using a script mediator, but I'm open to other solutions.
This was actually a pretty easy fix. Just use a CDATA section to have the XML parser ignore your code.
<![CDATA[ //YOUR CODE WITH XML INLINE// ]]>
Note that for some reason the WSO2 ESB XML Editor and UI will remove the CDATA section the next time you open your sequence for editing. I generally just copy out the XML configuration to a text file and paste it back into the configuration whenever it needs to be updated.
Not a perfect solution, but it'll get you over the line.
I need to perform below two task.
First read the content of a file and append those content to response message of service using WSO2 ESB.
Second - I need to read a file from a source directory without moving or deleting that file from source directory.
Can anybody suggest possible way to perform above operations.
You can use VFS transport?
And
the sample http://docs.wso2.org/pages/viewpage.action?pageId=26838852
I have created class mediator to do on demand read from a file and its successfully working.
First create a class mediator project - a java class that reads the file content and add those to synapse-config body.
Put that jar file in ESB_HOME/repository/component/lib
restart server and now that class will be available in ESB. :)
Below are the reference tutorials.
http://rajikak.blogspot.in/2010/03/writing-class-mediator-for-wso2-esb-300.html
http://www.nuwanbando.com/2013/06/reading-an-xml-file-into-wso2-esb-transform-it-and-expose-it-as-an-api/#more-1009
http://docs.wso2.org/display/ESB470/Places+for+Putting+Custom+Mediators
I am trying to forward a customized string which i have in my class mediator to the client who have invoked the process and i'm unable to figure out how that is done.
So please help me to solve the issue.
you need to set your string to the payload message. Then this can send as the response. Please have a look at here[1]
[1] http://wso2.org/library/knowledge-base/generating-simple-response-using-wso2-enterprise-service-bus
Class mediator can modify the message and append custom data into the message. This sample shows how to add a string to the message using a class mediator.