Apache camel and <groovy> </groovy> - groovy

I want to modify file with groovy using:
<from uri="file:/data/inbox?delete=true" />
<transform>
<groovy>
body = body[1..3]
</groovy>
</transform>
<to uri="file:/data/outbox"/>
I get an error:
groovy.lang.MissingMethodException: No signature of method:
org.apache.camel.component.file.GenericFile.getAt() is applicable for
argument types: (groovy.lang.IntRange) values: [1..3]
What am I doing wrong?

Yes the input is file based and you attempt to use a groovy function that works on a list to grab the 1st to 3rd elements. You cannot do that. If you want to grab only the first 3 lines of a file, then you need to convert the message first to a list etc, or use the splitter eip to split the file line by line and group them together in a list which you can then afterwards do the groovy script

Related

Use custom parameters in JSON Layout [Log4j 2]

I'm confused about the meaning of property substitution, lookups and layout parameters in Log4j 2. The documentation mentions that JSON layout supports custom fields. However it doesn't seem to support conversion patterns like %d{ISO8601}, %m, %l and the like. it does however support Lookups.
Thus when I define in the xml:
<JsonLayout complete="false" compact="false">
<KeyValuePair key="#timestamp" value="%d{ISO8601}" />
<KeyValuePair key="message" value="%message" />
<KeyValuePair key="process.thread.name" value="%tn" />
</JsonLayout >
As output I simply get the strings %d{ISO8601}, %message... instead of the values.
What I'm trying to achieve is a JSON layout where I can include parameters similar to Pattern Layout where I simply write <pattern>%d %p %C{1.} [%t] %m%n</pattern> to get what I want. Or, alternatively, should I use the Pattern layout and stitch together a string in JSON Format, making use of the Pattern Layout's JSON encoding %enc{%m}{JSON}?
The GelfLayout currently supports a messagePattern attribute that will format just the message field in the JSON using the patternLayout. I have planned to add this to the JSONLayout as well but have not done it yet. There is a new JsonTemplateLayout that is in the final stages of being merged into Log4j 2 that will also support this. You could either work from the current pull request to get the Layout or wait for the Log4j 2.14.0 release when likely both options will be available.

In MSBuild, how to split a string on endlines?

Other questions (MSBUILD Splitting text file into lines) mention implementation-specific alternatives, but none seem to directly address how to split a simple string property into an item group based on endlines.
How can you do this? Attempts that didn't work:
<ItemGroup>
<SplitLines Include="$(SourceString.Split('\r\n'))" />
</ItemGroup>: (splits on 'r' or 'n')
<ItemGroup>
<SplitLines Include="$(SourceString.Split('%0A%0D'))" />
</ItemGroup>: (doesn't split at all)
In case you're curious: SourceString is the output of an Exec command that needs splitting, so ReadLinesFromFile isn't an option. It can't output to an intermediary file because file systems are slow and this needs to be used by build processes that care about file operations.
Using property functions is the way to go and you can search for sulutions using e.g. 'C# split string lines' in your search engine of choice, then translate the answer. This comes up with this SO question and the Regex.Split method is the easiest to implement:
<ItemGroup>
<SplitLines Include="$([System.Text.RegularExpressions.Regex]::Split(`$(SourceString)`, `\r\n|\r|\n`))" />
</ItemGroup>

Why int-ftp:outbound-gateway payload is not List<java.io.File>?

According to http://docs.spring.io/spring-integration/reference/html/ftp.html#ftp-outbound-gateway the mget payload is a List of files
mget retrieves multiple remote files based on a pattern and supports the following option:
...
The message payload resulting from an mget operation is a ListFile> object - a List of File objects, each representing a retrieved file.
I have the following configuration
<int-ftp:outbound-gateway
session-factory="ftpSesionFactory"
request-channel="request-channel"
reply-channel="reply-channel"
auto-create-directory="true"
local-directory="${local-directory}"
command="mget"
command-options="-stream"
expression="payload">
<int-ftp:request-handler-advice-chain>
<int:retry-advice />
</int-ftp:request-handler-advice-chain>
</int-ftp:outbound-gateway>
<int-file:splitter input-channel="reply-channel" output-channel="logger"/>
But the payload is a List<FTPFile> and the splitter doesn't work. Is this a bug? How can I obtain the downloaded Listjava.io.File> in the payload (as the documentation says)?.
The workaround is using another component to read the file from the local directory, described at how to get file with int-ftp:outbound-gateway and remove from server if exists?.
I'm using spring-integration 4.2.5 and commons-net-2.0.
What makes you believe it's List<FTPFile?
This test shows it's a List<java.io.File>.
The ls command returns either a list of String or FTPFile, depending on the -1 option.
Finally, -stream is not supported on mget, only get.
Also, you don't want a file splitter there - that reads each file - you need a regular <int:splitter/> to split the List<File> into separate files; then the file splitter will read the file lines.

SOAPUI: run test-step with property from txt file, setting property to Property from txt

I use SOAPUI free version.
I have txt file like
1
2
3
I have test step, which should be run 1st time with 1, second with 2 etc...
Question: Can I somehow set that 1, then 2, then 3 as Property to property file?
And same question to xls, if text is not suitable...
I suppose you've a SOAP test step called for example "myRequest" which contains something like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<yourRequest>
<someValue>${#TestCase#myProperty}</someValue>
</yourRequest>
</soapenv:Body>
</soapenv:Envelope>
And you want to run this test step from groovy as many times than lines are in your file, using it content as a property in the request.
So in the groovy script you can use something like:
// define your file
def file = new File("C:/temp/yourFile.txt")
// for each line
file.eachLine { line ->
// put the property for your request
testRunner.testCase.setPropertyValue("myProperty",line)
// execute your request
testRunner.runTestStepByName( "myRequest")
log.info "execute request for line: " + line
}
You can do the same, specifying the property at other level distinct of TestCase ( TestSuite level, Project level...) this is only a possible way to do so :).
You can do it also from .xls however then maybe you need to add some libraries to deal with your .xls (like apache-poi) to SOAPUI\bin and change a bit of how groovy code to read it. I think that with .txt your goal is easy to achieve.
Hope this helps,

Parsing Tableau xml does not preserve original file

I try to work programmatically on Tableau desktop file (which are just xml file in spite of their .twb extension). I have many problem with lxml which doesn't preserve original content. To facilitate the explanation, imagine you have a test.xml file which contain the following text:
<column caption='Choix Découpage' name='[Aujourd&apos;Hui Parameter (copy 2)]'>
<member name='Nb d&apos;annulations' default-format='n#,##0.00" annulations";-#,##0.00" annulations"' />
<run>
:</run>
<calculation formula='iif([FAC_TYPE] = &apos;Avoir&apos; , [Calculation_1378101492427309057], null)' />
<alias key='"Billetterie Ferroviaire"' value='Train ticketing' />
</column>
Now let's parse it:
tree = etree.parse('test.xml')
root = tree.getroot()
print(etree.tostring(root,pretty_print=True,).decode("utf-8"))
When you run the code we can notice:
' becomes "
é becomes é Edit: resolved for this part
&apos; becomes '
How could i preserve the original ? (It would help me a lot when i try to check the diff with git in spite of showing all the useless change that are operated automatically)
Edit: I notice an other problem, when i run the folowing code:
[node.attrib['key'] for node in root.xpath("//alias")]
I got the result: ['"Billetterie Ferroviaire"'] and I am now unable to query with xpath if i am looking for the node whose attribute "key" is the original "Billetterie Ferroviaire" (root.xpath('//[#key="Billetterie Ferroviaire"]) doesn't work)

Resources