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
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 have one problem with API Manager.
I don't want to have logs of requests and responses in API Manager, because those log files are so big and I encounter files with 20G. I tried to comment Catalina access file, which is in repositoy/conf/tomcat/catalina-server.xml:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${carbon.home}/repository/logs"
prefix="http_access_"
suffix=".log"
pattern="combined"/>
Unfortunately, after commenting the above code, only http_access_.log file didn't created, but http_access_yyyy_mm_dd.log was created and requests saved in it. I tried to change directory of above file, too. Only file http_access_.log saved in new directory, and http_access_yyyy_mm_dd.log is still created in the ${carbon.home}/repository/logs directory.
How can change configuration of http_access_yyyy_mm_dd.log in wso2 API Manager?
According to the Apache Documentation,
The name of the file is composed by concatenation of the configured
prefix, timestamp and suffix
You can simply comment out the code snippet which you have mentioned which can be found in <PRODUCT_HOME>\repository\conf\tomcat\catalina-server.xml.
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs" prefix="http_access_" suffix=".log"b pattern="combined"/>
In simple comment the above code snippet in the mentioned file path and restart the WSO2 APIM server.
I am using the Postman Collection Runner to automate a series of API calls. On one of these API calls I need to submit a binary file as the body of a POST. When setting up the Collection Runner I see how to select a file, but I can't figure out how to attach that file to the body of the POST request in the "Pre-request Script".
Is it possible in a "Pre-request Script" to load a binary file into the "data" object?
Currently postman collection runner doesn't support file uploads.
You will have to use newman to execute your Automation Test Suite(collection).
Have a look at this answer:
Postman - POST request with file upload
I have been struggling with Jenkins lately, and I'm stuck because I wanna send some parameters through HTTP Post, and I know how to do it, but the thing is that I am saving a Http request response to a file in my workspace, and then I want to use that file, read it and send the text I saved previously to a new HTTP Request, does anyone have any idea how can I achieve this?
Thanks in advance!!!
Install copy artifacts from another project plugin ( copy artifacts) add in build steps store the file in your workspace then you can run a shell script to read the desired content from that file .
if curl would work, that would be a simple way to send a file's contents as your POST body. see this answer.
Jenkins can work with Jmeter and Jmeter is great tool for handling request and response see tutorial
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