Ant load property file and pass value as arg when exec java file - file

How can I load a value from a property file and pass it as arg when I want to execute a java file?
The content the file of aa.properties:
home_path=C:/myhome/apps
The ant:
<target name="tst">
<property file="aa.properties"/>
<property name="homepath" value="${home_path}/"/>
<java classpathref="clspath" classname="com.mytest.myapp" fork="true">
<arg value="${homepath}"/>
</java>
</target>

you pass it like any other argument to the java task via nested arg values or arg line
Note that vmargs like f.e. -Dwhatever=foobar are passed as jvmarg to the java task
f.e. your propertyfile aa.properties looks like :
vmarg.foo=-Dsomevalue=whatever
arg.key=value
arg.foo=bar
...
ant then
<target name="tst">
<property file="aa.properties"/>
<property name="homepath" value="${home_path}/"/>
<java classpathref="clspath" classname="com.mytest.myapp" fork="true">
<jvmarg value="${vmarg.foo}"/>
<arg value="${homepath}"/>
<arg value="${arg.key}"/>
<arg value="${arg.foo}"/>
...
</java>
</target>

Related

WSO2 iterative get-property from vfs file

I'm using WSO2 with the VFS. I need to take the incoming file, fileinput.xml and log the id fields together. The VFS is enabled and functional and when I move my fileinput.xml into my test_in folder it appropriately gets handled and put into test_out or test_failure correctly. I've read a lot of online documentation but have been unable to wrap my head around how to do the following.
My Question is
How do I get a property from my fileinput.xml ?
How do I iterate over the ids and concatenate them together in a log?
fileinput.xml
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<customers>
<customer>
<id>testid1</id>
<prop1>a</prop1>
<prop2>b</prop2>
<customer/>
<customer>
<id>testid2</id>
<prop1>3</prop1>
<prop2>4</prop2>
<customer/>
</customers>
</soapenv:Body>
</soapenv:Envelope>
My wso2 proxy file
<?xml version="1.0" encoding="UTF-8"?>
<proxy
xmlns="http://ws.apache.org/ns/synapse" name="FileProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">file:///Users/myuser/test_in</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Users/myusertest_out</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///Users/myuser/test_failure</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.ContentType">text/xml</parameter>
<inSequence>
<log category="WARN" level="full">
<property name="MESSAGE" value="In Sequence"/>
</log>
<clone>
<target sequence="fileWriteSequence"/>
</clone>
</inSequence>
</target>
<outSequence>
<log category="WARN" level="full">
<property name="MESSAGE" value="Out Sequence"/>
</log>
<send/>
</outSequence>
</proxy>
My fileWriteSequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="fileWriteSequence">
<log level="full">
<property name="sequence" value="fileWriteSequence"/>
</log>
<property name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="FileEpr">
<address uri="vfs:file:///Users/myuser/test_out"/>
</endpoint>
</send>
</sequence>
You can use the iterate mediator to iterate over 'id' element and use a property in the operation scope to concatenate all the id values. Refer this

How to do database transaction rollback in wso2 esb or wso2 dss

I am inserting into three tables using Box_caring feature, insertion happening properly but if some error comes in between while inserting into tables its not roll backing the data.
I'm looking for a solution to the following challenge:Have a set of related tables. They are related by primary/foreign key relations and need to update/insert objects in the related tables. Insert/update happening inside iterator mediator. what happens when one of the updates/insert fails? Will all the inserted/updated objects rolled back?.
Please give any ideas or links or code snippet to make it work.
Note: Am using wso2 esb-4.8.1, wso2 dss-3.2.2 and MSSQL database
Gone through below links:
http://charithaka.blogspot.in/2014/02/common-mistakes-to-avoid-in-wso2-esb-1.html
How we can ROLLBACK the Transaction in WSO2DSS or WSO2ESB
Thanks in advance
Here you have to implement Distributed XA transactions. Could you please refer to the article [1] which will guide you through this.
[1]https://docs.wso2.com/display/ESB490/Sample+657%3A+Distributed+Transaction+Management
When you are using box_carring feature, you have to maintain same session across all the operation calls. Otherwise, it will evaluates as separated calls and will not be atomic. Here is a sample synapse config that can be used to maintain the same session.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ESBService"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<transaction action="new"/>
<property name="id" expression="json-eval($.id)"/>
<property name="userName" expression="json-eval($.userName)"/>
<property name="firstName" expression="json-eval($.firstName)"/>
<property name="lastName" expression="json-eval($.lastName)"/>
<property name="address" expression="json-eval($.address)"/>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="FirstBody"/>
</enrich>
<property name="messageType" value="application/xml" scope="axis2"/>
<header name="Action" value="urn:begin_boxcar"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:begin_boxcar/>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<call>
<endpoint>
<address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/>
</endpoint>
</call>
<property name="setCookieHeader" expression="$trp:Set-Cookie"/>
<property name="Cookie"
expression="get-property('setCookieHeader')"
scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<p:insert_employee xmlns:p="http://ws.wso2.org/dataservice">
<xs:UserId xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:UserId>
<xs:userName xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:userName>
<xs:firstName xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:firstName>
<xs:lastName xmlns:xs="http://ws.wso2.org/dataservice">$4</xs:lastName>
</p:insert_employee>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('id')"/>
<arg evaluator="xml" expression="get-property('userName')"/>
<arg evaluator="xml" expression="get-property('firstName')"/>
<arg evaluator="xml" expression="get-property('lastName')"/>
</args>
</payloadFactory>
<property name="Content-Encoding" scope="transport" action="remove"/>
<property name="Cookie"
expression="get-property('setCookieHeader')"
scope="transport"/>
<call>
<endpoint>
<address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/>
</endpoint>
</call>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:end_boxcar/>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<property name="Content-Encoding" scope="transport" action="remove"/>
<property name="Cookie"
expression="get-property('setCookieHeader')"
scope="transport"/>
<call>
<endpoint>
<address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/>
</endpoint>
</call>
<respond/>
</inSequence>
<faultSequence>
<log>
<property name="END" value="****ROLLBACK****"/>
</log>
<transaction action="rollback"/>
<respond/>
</faultSequence>
</target>
</proxy>
However, you can use request_box feature, where you do not have to maintain the session across operations.
Thanks

create a new file from payload in wso2

I am new to wso2 and working on a few POCs where i have to create a file at some location , i have looked into all vfs examples where there is always a file processed and written to a new location.
What i want to achieve is write a new file to a directory by the content i receive in a sequence.
For my requirement process i have exposed a REST service and it calls this sequence.
The sequence configuration is as follows.
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="FileWriteSequence">
<clone>
<target>
<sequence>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="transport.vfs.ReplyFileName" value="myOutputFile.txt" scope="transport" type="STRING"/>
<send>
<endpoint name="FileEpr">
<address uri="vfs:file://D:/Tools"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
This sequence creates a file from the latest message from the REST resource but the file name is always the project name.
Whatever i try it doesnt change.
I have tried giving other proxy parameters shown below as property above my sequence as well .Instead of paramters i passed them above the property <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
Namely :-
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file://D:/Tools</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file://D:/backup</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
Still no progress.
Can anyone help me here?
Regards,
Rahul.
In case anyone wants to know i have made a workaround for this i called a proxy service from my rest resource and it worked .
In my resource i called endpoint like this
<send>
<endpoint key="FileProxyEndPt"/>
</send>
Then i created a proxy service as follows
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileWriteProxy"
transports="http https vfs" startOnLoad="true" trace="enable">
<target>
<inSequence>
<clone>
<target sequence="FileWriteSequence" />
</clone>
</inSequence>
<outSequence />
<faultSequence />
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file://D:/Tools</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file://D:/backup</parameter>
<parameter name="transport.vfs.ContentType">text/plain; charset=ISO-8859-1</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
This way it worked it but never worked exactly in a resource.So had to take a longer route , hope somebody provides a solution which can be implemented directly.

wso2 esb to download/get a local file

I have some static files (some are HTML, some are images and some are pure data files - like .csv or .xls etc) that I want to share through the ESB. I can make that happen if I run a separate HTTP server that will receive the request for these through ESB. Instead, I like to handle it in ESB itself. Based on the incoming request URL (say HTTP GET request - http://myesb.com:8280/getstatus.html ), I like to pull these static files from the local server's folders.
I tried the VFS method and it looks like has built in "refresh" mechanism that I don't want. I want to "GET" these data only when the clients are requesting for it.
In short, I like to have a simple mapping done like this:
http://myesb.com:8280/getstatus.html will fetch the contents of /var/myapp/status/appstatus.html file.
Update
I did the following sequence - don't know how to make it work :(
<sequence xmlns="http://ws.apache.org/ns/synapse" name="app1status">
<in>
<log level="custom">
<property name="Reached app1status page - in" value="app1 Status"/>
<property name="transport.vfs.ContentType" value="text/html"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="TRPURL:" expression="get-property('From')"/>
</log>
<property name="transport.vfs.FileURI" value="vfs:file:///opt/platform/traffic/app1status1.html" scope="transport" type="STRING"/>
<property name="HTTP_METHOD" value="GET"/>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"/>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
</in>
<out>
<log level="custom">
<property name="::::::Out:::::Reached app1status" value=" From OUT"/>
<property name="messageType" value="text/html"/>
<property name="ContentType" value="text/html"/>
</log>
<send/>
</out>
</sequence>
Note the following in the <in> mediator:
<property name="transport.vfs.FileURI" value="vfs:file:///opt/platform/traffic/app1status1.html" scope="transport" type="STRING"/>
My intent is to get the content of the file appstatus1.html retrieved and send back as the response. But I am not able to get the contents retrieved and added to the "RESPONSE"
Let me know how it can be done.
Thanks for your time.
Define a RESTAPI and based on GET/PUT pull or post data to your server.

Ant: Find the path of a file in a directory

I want to find the path of a file in a directory (similar to unix 'find' command or the 'which' command, but I need it to work platform-independent) and save it as a property.
Tried to use the whichresource ant task, but it doesn't do the trick (I think it's only good for looking inside jar files).
I would prefer if it would be pure ant and not to write my own task or use a 3rd-party extension.
Notice that there might be several instances of a file by that name in the path - I want it to only return the first instance (or at least I want to be able to choose only one).
Any suggestions?
One possibility is to use the first resource selector. For example to find a file called a.jar somewhere under directory jars:
<first id="first">
<fileset dir="jars" includes="**/a.jar" />
</first>
<echo message="${toString:first}" />
If there are no matching files nothing will be echoed, otherwise you'll get the path to the first match.
Here is an example which selects the first matching file. The logic is as follows:
find all matches using a fileset.
using pathconvert, store the result in a property, separating each matching file with line separator.
use a head filter to match the first matching file.
The functionality is encapsulated in a macrodef for reusability.
<project default="test">
<target name="test">
<find dir="test" name="*" property="match.1"/>
<echo message="found: ${match.1}"/>
<find dir="test" name="*.html" property="match.2"/>
<echo message="found: ${match.2}"/>
</target>
<macrodef name="find">
<attribute name="dir"/>
<attribute name="name"/>
<attribute name="property"/>
<sequential>
<pathconvert property="#{property}.matches" pathsep="${line.separator}">
<fileset dir="#{dir}">
<include name="#{name}"/>
</fileset>
</pathconvert>
<loadresource property="#{property}">
<string value="${#{property}.matches}"/>
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadresource>
</sequential>
</macrodef>
</project>
I created a macro based on martin-clayton's answer.
sample project with macro and a property file that is read from the found file
<?xml version="1.0" encoding="utf-8"?>
<project name="test properties file read" default="info">
<macrodef name="searchfile">
<attribute name="file" />
<attribute name="path" default="custom,." />
<attribute name="name" />
<sequential>
<first id="#{name}">
<multirootfileset basedirs="#{path}" includes="#{file}" erroronmissingdir="false" />
</first>
<property name="#{name}" value="${toString:#{name}}" />
</sequential>
</macrodef>
<searchfile name="custom.properties.file" file="config.properties" />
<property file="${custom.properties.file}" />
<target name="info" >
<echo>
origin ${config.origin}
</echo>
</target>

Resources