I have several APIs behind a WSO2 instance, each with it's own context ("/api-1/", "/api-2/", ...)
I'd like to add this context string dynamically to an Http header (without hardcoding it on a per-API basis).
So, for example:
<sequence name="WSO2AM--Ext--In">
<header name="X-Script-Name"
scope="transport" expression="get-property('', '')"/>
</sequence>
Is there an expression that I can use to achieve this? Or should I resort to creating a per-API mediator to include it?
Edit:
I have tried using the url regex, expecting it to treat {context} as part of the uri variables, but it doesn't seem to do it:
<header name="X-Script-Name" scope="transport" expression="uri.var.context"/>
Did you define "uri.var.context" before? It is not inbuilt variable to be used.
You can read the "To" header and apply the string manipulation using xpath, so you can get the context.
Edit;
You can read API metadata(context,version etc..) from jwt token.Get the jwt token from transport header and manipulate it.
Related
According to the documentation
ForEach does not allow using Call , Send and Callout mediators in the sequence.
But it is possible to use a Call/Send/Callout mediator inside a ForEach mediator if you place it inside a sequence, and invoke this sequence inside of it, like in this example:
<!-- myProxy.xml -->
<for-each expression="//foo" >
<sequence>
<sequence key="myCallSequence"/>
</sequence>
</for-each>
<!-- myCallSequence.xml -->
<call>
<endpoint>
<address format="soap11" uri="http://my.uri.com"/>
</endpoint>
</call>
Which I observed could result in some very unexpected results, especially regarding the aggregated payload after the for each being mixed with the return of a callout.
I stumbled accross this while dealing with a situation where I had to split my original message and validate some data from the splitted parts with an external service, but still needed to do more processing with the original message if the validations where successfull.
Is this kind of configuration considered a bad practice? And if so, why?
ForEach mediator should only be used if you need to transform a payload in an iterative manner (for example, an array). ForEach mediator is not implemented to support calling back-ends. If you need to achieve this use case, use the Iterate mediator which allows you to call back-end. Please refer https://docs.wso2.com/display/EI611/Iterate+Mediator for more information.
I have a json.xsl file which needs an Access-Control-Allow-Origin header.
My attempt at getting this working was by adding
<http-headers>
<header name="Access-Control-Allow-Origin" value="*" />
</http-headers>
to the top of the "json.xsl" file, hoping you wouldn't have to set this globally, but despite it still parsing properly, it doesn't add the header.
Is this simply not possible, or am I using the wrong tags (or putting the tags in the wrong location?)
Use Icecast 2.4.2, it allows you to configure arbitrary headers. Both globally and per "mount". You can define a "mount" for a XSLT file to apply e.g. headers or authentication.
Also Icecast >2.4.1 has a working JSON API. (In 2.4.0 there are problems and it is NOT recommended to use!)
https://wiki.xiph.org/Icecast_Server/Installing_latest_version_(official_Xiph_repositories)
I have an old axis 1 webservice here that is deployed via a MyWebService.jws file. It was called by an URL like this:
http://localhost:8080/WebApp/service/MyWebService.jws?method=coolMethod
Now I want to replace the jws-file deployment method and use a WSDD file instead, however I would like to keep the URL for the webservice access the same.
Naively I though that I could just replace the service's name with 'MyWebService.jws' like this:
<service name="MyWebService.jws" provider="java:RPC">
<parameter name="allowedMethods" value="*" />
<parameter name="scope" value="request"/>
<parameter name="typeMappingVersion" value="1.1"/>
<parameter name="className" value="MyWebServiceClass" />
</service>
Sadly that does not work as expected, because Axis recognizes the .jws inside the name and handles it like a .jws-file deployment, which now, after the .jws files have been removed obviously leads to this error message:
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.io.FileNotFoundException: /service/MyWebService.jws</faultstring>
Is there a way to stop axis from interpreting a webservice name like 'MyWebService.jws' as a .jws-file?
Ok, answering my own question: this is not possible in Axis, interpreting service names that end with '.jws' as .jws-Files is hardcoded.
In the end, I build myself my own Axis version that uses a different default-ending, allowing me to deploy the webservices as needed.
In WSO2ESB, using the xslt mediator, I want to transform a webservice result. I do that using an xslt file. In this file, I want to do some lookups, to transform some values into something else.
In Oracle, you can use a dvm for that.
In plain xslt, it looks like the document('somefile.xml') function could do the trick, but WSO2ESB looks for the xml file on the filesystem, and the resources property on the xslt mediator does not translate document() contents into correct paths.
Then, I tried inputting the XML by reading it into a property in ESB, and then pass the property to the mediator. This also does not work, because the content of the XML is then
passed as one string value instead of a nodeset.
Am I doing something wrong - what is the correct way of doing this?
you can inject the content of your document 'somefile.xml' as a subtree inside the current message before invoking XSLT mediator :
Define a local entry named 'somefile' with the content of 'somefile.xml'
Use enrich mediator to inject it's content inside current message :
<enrich>
<source clone="true" xpath="get-property('somefile')"/>
<target type="body" action="child"/>
</enrich>
In your XSL transformation, use this content rather than refering to $somefile/xxx...
(and forget this content in the result)
By default, the XSLT mediator acts on the message body, so shouldn't be necessary to use the document function to load the XML seperately. For an example of the xslt mediator, see this link to the current wso2esb documentation.
If you want to replace a few values in your XML, you may want to try the enrich mediator. The enrich mediator can use Xpath expressions to select the source and target expressions for replacement.
I am using wso2esb4.8.0.I wish to write the data into .CSV file using wso2esb4.8.0
if file is empty i am able to write means Append but my issue is already has file just i need to add one more data column to that
m csv file is
mdata
======
john,us,24,monnaco
ahemad,uk,54,bresbane
rajulak,srilanks,35,dar
above my csv file look like but i need to write(ADD) data in next column like this'
Desire .CSV file is
mdata
==========
john,us,24,monnaco,man
ahemad,uk,54,bresbane,man
rajulak,srilanks,35,dar,man
like this i wish to write the data into existing row only
how would i achive this
i tried this but its adding in next row
actually that one column may come from my client as json data
i wsih to add into that .CSV file
i have done like this but no use my config is
<inSequence>
<log level="full"/>type="STRING"/>
<property name="transport.vfs.ReplyFileName" expression="mdata.csv" scope="transport" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///Y6/Desktop/MyOutputDirectory?transport.vfs.Append=true"/>
</endpoint>
</send>
</inSequence>
how would i achive my desire file format is there any way into esb or not
You can achive this by writing your own class mediator to write to .csv file as your desired format. VFS does not support the requirement of writing custom files in different formats. You can write a simple java code to achieve this . Please refer [1] for more info how to write a custom mediatorfor WSO2 ESB.
[1]. http://wso2.com/library/2898/
Thank You,
Dharshana.