In the 2.6.0 version of the Api Manager from WSO2, I was using custom sequence to log every flux with API Name, resources, applications, type of token etc... in Input and Output Seq
<log level="custom">
<property expression="fn:concat('[V2][API][',$ctx:api.ut.application.name,'][',$ctx:API_NAME,'][',$ctx:AM_KEY_TYPE,'][',$ctx:REST_SUB_REQUEST_PATH,'][',$ctx:api.ut.userId,'][',$ctx:EXECUTION_TIME_KAFKA,'][',$ctx:SYNAPSE_REST_API_VERSION,'][NOCOMMENT]')" name="LOG2PARSE"/>
</log>
Since 3.2.0, I am not able anymore to use the "$ctx:API_NAME" property.
Do you have any idea what is the right property to retrieve the API Name ? If I can, I do not want to use custom property to get the name.
Also, I can't find in the documentation which are the generics properties.
Do you have any idea ?
Thank you !
For API Name you can use the following.
$ctx:api.ut.api
Some of the other properties can be found here - https://github.com/wso2/carbon-apimgt/blob/master/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/APIMgtGatewayConstants.java#L24
Related
I am trying to get all transport headers used when calling a specific API and log that for debugging, since we do not know what the name of the headers will be I want to log them all.
I know this can be done via a class mediator as well as by enabling wire logs but I am looking for an option to achieve this without having to do either of those.
I have tried using script mediator and then using: mc.getProperty("org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS") to fetch them from message context but it just returns null.
Any suggestions?
You are trying to get a property with the name "org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS" from the default Context, hence it's returning null. You can't really access TRANSPORT_HEADERS from the Axis2Context within a ScriptMediator. Your best option is to write a class mediator.
Use get-property from the transport layer.
Only you need to know the name of the variables.
<log level="headers" category="INFO">
<property name="inicio" value="------ begin -------"/>
<property name="X_Teste_FOS" expression="get-property('transport','X-Test-FOS')"/>
<property name="inicio" value="------ end -------"/>
</log>
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.
I switched from Apigee to WSO2 2.1 but on piece of functionality is missing.
When my Oauth users make API calls, I want to add an additional Header
to the backend request. E.g.: "X-Customer-Name: CUST_NAME
I have the Java code to lookup "CUST_NAME" in ElasticSearch based on
the user's consumer key & secret. How would I integrate that code into
WSO2 to be able to lookup the values and send the extra X-Customer-Name header to my backend?
Java classes can be integrated / used in WSO2 mediations using <class/> mediator.
To achieve this, the custom java class can extend AbstractMediator class and can implement the logic in the mediate method.
Create a new insequence, like the following and invoke the custom class, this way the custom property can be set to the message context.
<sequence name="TokenExchange" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<class description="" name="com.customer.CustomerName"/>
<property expression="get-property('Customer-Name','custName')" name="cs" scope="default" type="STRING"/>
</sequence>
Use this newly built inSequence into your API In-Flow message mediation flow and pass the appropriate properties to the backend.
I have successfully deployed a WSO2 API Manager. I am already using mediation flows for setting Header information, but now I am adding an API that requires a key to be set as an URL parameter. However I would like this to be added in the background so that the end-users don't have to worry about this key.
How can this be done in a Message Mediation Policy/Flow? Obviously the other parameters that are already present should stay untouched.
Thanks in advance
Hope you can access the key inside the synapse context. Then you can assign the key value to the uri.var object as below.
<property name="uri.var.key" expression="get-property('userParames.key')"/>
Now you can simply construct the endpoint as,
<endpoint>
<http uri-template="https://{uri.var.hostname}:{uri.var.portnum}/abc/{uri.var.key}"/>
</endpoint>
My WSO2 ESB proxy service references an endpoint which is located at different URLs in various environments - DEV, TEST, PROD. According to the WSO2 documentation, I need to store the endpoint definition in the Governance Registry and modify the URL in endpoint XML file in each environment. That might work fine for the organizations with 1 or 2 proxies, but becomes a significant overhead for a 10+ proxies.
Another scenario is when I need to read certain environment-specific properties in my ESB sequence.
Is there a way to define a bunch of properties in the external *.properties file and then read them within the ESB and Registry definitions?
You can access system properties inside ESB sequences/proxy services using the script mediator as follows;
<script language="js">mc.setProperty("file.separator",java.lang.System.getProperty("file.separator"));</script>
<log level="custom">
<property name="file.separator" expression="get-property('file.separator')"/>
</log>
Here "file.separator" property is set as the property in the message context inside the script mediator and it can be used in subsequent mediators.
You also can access properties defined in a file in ESB registry. For example if you have a file in configuration registry (test.xml) with the following content,
<a>Helloo<b>World</b></a>
The text element "World" in <b> can be accessed using property mediator as follows,
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
<log level="custom">
<property name="test.b" expression="$ctx:test//b"/>
</log>
here is a blog post on how to access registry resources from a classmeditor1. You can access any resources as mentioned in the post and do modifications.
Likewise you can keep the external properties file and read that from the classmeditor and set all properties in synapse message context using class meditaor.