How send file with parameters to soapui - file

I'm testing webservice request with soapUi and need to send parameters to request, stored in config file.
Parameters are:
Key - static parameter, for access to webservice
Parameters 1-4 - dynamic, can change in config file and send to web-service again.
All parameters both Key and Parameters 1-3 I need send to soapui request as config file using groovy script.
Request to web-service like:
<Header/>
<Body>
<request>
<accesskeytoservice>
<key>Key</key>
</accesskeytoservice>
<UseService>
<parameter1>Parameter1<parameter1>
<parameter2>Parameter2<parameter2>
<parameter3>Parameter3<parameter3>
</UseService>
</request>
</Body>
I had tried to store data in csv, txt and xml format and then read it to soapui request parsing data from file, but all tries still didn't work properly.
What format of config file is preferred in this case?

How are you opening and reading your config file? Using Groovy? If you have successfully done that part the rest is simpler. Define two variables and use
context.setProperty(name,value)
Loop until eof.

Related

Azure Logic App outputs XML all in single line

I'm trying to convert a CSV to XML, which works perfectly fine when I test the map file in Visual Studio as I made sure the XSLT1.0 contains indent="yes". But for some reason when I repeat the steps in my Azure Logic App everything gets exported to one line:
<?xml version="1.0" encoding="utf-8"?><enfinity xsi:schemaLocation="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex bc_pricing.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.fakewebsite.com/xml/ns/enfinity/6.5/core/impex-dt"><product-price-list id="DEMarkdown" priceType="ES_SalePrice" import-mode="UPDATE"><display-name>DE Markdown</display-name><description /><enabled>true</enabled><priority>1</priority><target-groups><customer-segments><customer-segment id="Everyone" repository-id="WhiteStuff-DE-Anonymous" /><customer-segment id="IG_RegisteredUsers" repository-id="WhiteStuff-DE-Anonymous" /></customer-segments></target-groups><product-price-list-entry sku="433493126" import-mode="REPLACE"><price-scale-table type-code="1" currency="EUR"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>44.95</value></fixed-price-entry></price-scale-entries></price-scale-table><price-scale-table type-code="1" currency="GBP"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>39.50</value></fixed-price-entry></price-scale-entries></price-scale-table></product-price-list-entry></product-price-list></enfinity>
I have 2 ways for this
WAY-1
You can use the XML Validation connector before the process which parses the content into the right format.
WAY-2
Just for viewing purposes, you can do a request-response method using Postman then use XML format in order to achieve your requirement.
For those interested, I've found a setting within the Logic App, simply select Apply XSLT output attributes and that's it, no validation needed either!

Logic App Function to remove file extension

I have a logic app in Azure. The trigger is to check when an email arrives into a specific folder in a mailbox. An email may contain 1 or more attachments.
Once triggered, I have an HTTP request that gets sent to a SOAP service. The idea is that I want to check if the filename exists at the SOAP Service.
Its all working perfectly, with the exception, when I reference the filename from the trigger, it includes the file extension. I need to somehow ignore the ".PDF" part of the filename
Below is the XML I post to the SOAP service. Lets say the filename is 12345.pdf, then I need /UniversalEvent/Event/ContextCollection/Context/Value to = "12345" and not "12345.pdf":
<UniversalEvent xmlns="http://www.cargowise.com/Schemas/Universal/2011/11" version="1.1">
<Event>
<DataContext>
<DataTargetCollection>
<DataTarget>
<Type>ForwardingShipment</Type>
</DataTarget>
</DataTargetCollection>
</DataContext>
<EventTime>#{utcNow()}</EventTime>
<EventType>Z77</EventType>
<EventReference>Requesting Shipment ID</EventReference>
<IsEstimate>false</IsEstimate>
<ContextCollection>
<Context>
<Type>HAWBNumber</Type>
<Value>#{items('For_each')?['name']}</Value>
</Context>
</ContextCollection>
</Event>
</UniversalEvent>
do you have any suggestions on what function to use to achieve this?
You can change the expression #{items('For_each')?['name']} in your xml to:
#{substring(items('For_each')?['name'], 0, indexOf(items('For_each')?['name'], '.'))}

Mule - Delete files with Files Connector

This is my main mule flow:
HTTP > Payload > File (Create) > Property (File Name) JMS
And that JMS calls to other flow that starts with JMS
JMS > JSON TO XML > File (Delete by file name)
Firstly, I create a file with the JSON message.
And finally, when JSON message is transformed to XML, I try to delete the file by name calling a property that tell me the name.
But the files doesn't delete. Its output this action by log:
Writing file to: C:\errors\91fa03a0-dd33-11e5-a0d9-408d5c4c1bf3.dat
How can I do to delete it?
I tried with the option autoDelete in the Connector Configuration but it doesn't delete.
<file:connector name="File1" outputPattern="#[message.inboundProperties.fileName]" autoDelete="true" streaming="false" validateConnections="true" doc:name="File"/>
You can't use this file outbound endpoint to delete a file.
If you would use something like S3 for example you can, but those connectors are 'operation-based'.
It's meant to write an new file or append data to an existing one.
The autoDelete option is for deleting the file once it has been read by a file inbound endpoint.
More info:
https://docs.mulesoft.com/mule-user-guide/v/3.7/file-transport-reference
If you want to delete and for your usecase you should use a piece of JAVA code and use methods from the File Class:
https://docs.oracle.com/javase/7/docs/api/java/io/File.html

Mule - how to get the name of the file created in an outbound endpoint

I have a Mule application that is writing a file in an outbound endpoint, with the config below:
<file:outbound-endpoint path="${Outbound}" outputPattern="outputFile_#[function:datestamp:yyyyMMddHHmmss].csv" doc:name="Output File"/>
Following this point in the flow I need to display a log message along the lines of "Successfully created file {filename}".
The issue I'm having is that I can't find a way of displaying the name of the file I have just created. I could put: Successfully created file outputFile_#[function:datestamp:yyyyMMddHHmmss].csv, but there is a chance that the datestamp may differ by one second.
Is there a way in Mule that I can display the name of the file I've just written?
UPDATE
Following the response from #til_b, I've achieved this using the following:
<set-variable value="outputFile_#[function:datestamp:yyyyMMddHHmmss].csv" variableName="Filename" doc:name="Variable"/>
<file:outbound-endpoint path="${Outbound}" outputPattern="#[variable:Filename]" doc:name="Output File"/>
<logger level="INFO" message="Successfully created file #[variable:Filename]" doc:name="Logger" />
I dont know about mule, but when i encounter such a problem while programming i store the generated filename in a variable, and then use that variable to actually create the file and display the message.
In Pseudocode:
var filename = #yyyymmddhhMMss.csv
create_file(filename)
log_message(filename + ' successfully created')

Generate and download file with jboss seam

I need to add an 'export' function to an existing web app using seam. The purpose is to export search results to a csv file. I have no problem generating a csv, but I do not know how the send the csv back to the user.
I do not want to store the csv on the server because that would be waisted storage space. How could I achieve this in jboss seam?
Use the Document Store Servlet provided by Seam.
Almost copying and pasting from the reference doc, declare the servlet in web.xml like this:
<servlet>
<servlet-name>Document Store Servlet</servlet-name>
<servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Document Store Servlet</servlet-name>
<url-pattern>/seam/docstore/*</url-pattern>
</servlet-mapping>
Then create a export.xhtml file with only <s:resource> tag:
<s:resource xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
data="#{myComponent.csvData}"
contentType="application/vnd.ms-excel"
fileName="#{myComponent.csvFileName}"/>
Generate link for downloading the file in your page with <s:download>:
<s:download src="/csv/export.xhtml">
<h:outputText value="Download CSV"/>
<f:param name="param1" value="somevalue"/>
<f:param name="param2" value="someOtherValue"/>
</s:download>
Finally, implement getCsvData() and getCsvFileName() methods in your component:
// could be byte[], File or InputStream
public InputStream getCsvData() {
// generate data to be downloaded
}
public String getCsvFileName() {
return "myfile.csv";
}
Note that <s:download> propagates conversation (unless you set propagation=none). If you propagate the conversation context probably you won't need to pass any parameter. For large data set it may be preferable to not propagate the conversation and pass parameter to select the data in a request scoped component.
There's a couple of ways:
1) Check the Seam docs for info on using Seam-Excel to programmatically generate your file and then write it out using a mime-type set for CSV - this is all detailed in the docs.
However, I could not get this to work in the latest version of Seam, as it requires a response object, which used to be available from the Seam context but now only returns null.
2) Code the CSV file you want as an Excel xhtml template (see the Seam docs and example projects) and simply render this as normal using an tag.
I do this regularly and it works well, bar the restriction that you cannot supply a filename.
HTH.

Resources