How to read data from properties file in wso2 esb - wso2

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

Related

WSO2 IS Custom authenticator with property files

I am creating a custom authenticator in WSO2 IS 5.11 and I need to create some property files in server, i.e, repository/conf/myproperties.properties to load them from the custom authenticator. I always get "access denied". How can I set this property files in the server and read them properly in the custom authenticator?
Cheers
If you want to load the properties from a new properties file, add the file into the preferred location of IS and write the logic to read your file and load the properties into a data holder during the OSGi service activation.
That file reading and storing logic need to be invoked in the activate(ComponentContext ctxt) method mentioned in step 3 of
https://is.docs.wso2.com/en/latest/develop/writing-a-custom-local-authenticator/#configurations.
As an alternative option you can use the <is-home>/repository/conf/identity/application-authentication.xml file to store your custom authenticators properties. The following configs need to be applied in to
<is-home>/repository/conf/deployment.toml file.
(NOTE: <cutom_alias>, should be replaced)
[authentication.authenticator.<cutom_alias>]
name = "<CustomeAuthenticatorName>"
enable = true
[authentication.authenticator.<cutom_alias>.parameters]
param1 = "value1"
param2 = "value2"
That file reading logic already implemented and you can retrieve the params by getAuthenticatorConfig() method in AbstractApplicationAuthenticator class.getAuthenticatorConfig().getParameterMap(); can be used to load the defined parameters. (eg:
https://github.com/wso2-extensions/identity-local-auth-basicauth/blob/6b6ae8d452397f26f948a870e72e8086b46669c9/components/org.wso2.carbon.identity.application.authenticator.basicauth/src/main/java/org/wso2/carbon/identity/application/authenticator/basicauth/BasicAuthenticator.java#L203)

Removeing http_access_yyyy_mm_dd.log file in wso2 API Manager

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.

WSO2APIM: Where to put XSLT file for XSLT Mediator

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="*" />

WSO2 ESB read from a file

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

how to update the files saved in registry

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