Send file attachment as base64Binary in SoapUI - soap

There is an element, which is defined as base64Binary in WSDL. I attached file with ContentID ref1 and added it to SOAP request as follows:
<docBytes><xop:Include href="cid:ref1" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></docBytes>
I got following error message when I try to send it:
cvc-type.3.1.2: Element 'docBytes' is a simple type, so it must have
no element information item [children]
It is working, when I paste a base64 encoded string between tags.

That is correct, I have services where a PDF is sent, and I stored the doc as base64 byte array in a property like this:
def docContent = new File("path/to/file")
def encodedDoc = docContent.bytes.encodeBase64().toString()
testRunner.testCase.setPropertyValue("encodedDoc", encodedDoc)
Then use it with:
<docBytes>${#TestCase#encodedDoc}</docBytes>
in the request.

Related

Soap message encoded in base64 binary data multiple files

Recently I got a new project to work on a SOAP service and to Get and Post messages to a ASP.NET service based on xml.
The issue is that I managed to make the soap request and get the message.
The message looks like this:
UEsDBBQAAAAIAAdUe06+NXE0kR4AADLSAQALAAAAUHJvZHVzZS54bWzUXW1z48YN5k/h5EMnmbMsvomSpmkzFCXbjERJoSTb52/p9dq5mbxN2svczy/........
The message is Base64 Binary on RFC 4648 with multiple xml documents on it.
How I can construct this documents from the code in php?
The documents encrypted in this request are 3 xml files.
I managed to get them from an online decryptor called freeformatter with download function.
If I try to decode the result I get something like:
PKT{N�5q4�2�Produse.xml�]ms��
�O��C'��,����i3%یDI�$��o��ڹ��M����/�,��|vL�O�$�/�xv,,�u�s>9?;?....
Is there a solution for this?
I'm new to SOAP so I don't understand too much of it.
Thank you but i mannged to solve it.
I gonna post here the sollution so everyone who facing the same issue, get the response.
The first thing you need to do when you have an .zip file in a base64 binary string is to catch the response to a txt file.
Let's say the response from soap it's called ' $response ' and we need to catch this to an file. We do like this :
$response = $client -> _getLastResponse();
$fille = "response.xml";
fille_put_contents($fille,$response);
Now we got the response to an xml file.
The next thing to do is to get the response from xml values.
Lets say our value is <ResponseFromServer> .
`$b64 = "b64.txt";
$dom = new DomDocument();
$dom = load("response.xml");
$data = $dom->getElementByTagName("ResponseFromServer");
$catchb64 = $data;
fille_put_content($b64,$catchb64);`
Now we got the clean Base64 Binary string in one fille.
The next thing we need is to create the document ( in this case is a .zip fille)
`$input_fille = "response.txt"; // the fille with clean base64 binary data on it
$output_fille = "result.zip"; //the fille we need to create on system with the
documents decrypted
$content = fille_get_contents($input_fille); // Reading the content of input fille
$binary = base64_decode($content); // Decoding to binary
fille_put_contents($output_fille,$binary); // Writing to fille the vallues`
We dont need the ZipArchive() function, because is allready a zip archive, all we need to do is to create a empty document and after to send the binary data to it.
Cheer's and goodluck!

How do I send a JSON body as part of multipart/form-data with Paw?

I have a REST request that accepts multipart/form-data. This request is already working with an Angular front-end. It expects both an array of files in a parameter called files[] and a JSON body in a parameter with the name body. In Paw, it seems like I can get the multipart files to be recognized by my endpoint but the body doesn't appear to be the correct content type (application/json). Is there any way to specify the content type for each part of a multipart POST in Paw?
Details:
The error message I'm getting on the server-side is:
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
The config for the body in Paw is:

How do output for tRESTClient

I read some param from JSON file and for each param i should send request.
That when i true move output to any element i get errors:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
statusCode cannot be resolved or is not a field
string cannot be resolved or is not a field
body cannot be resolved or is not a field
The method getHeaders() is undefined for the type Response
at pricing.pricing_0_1.Pricing.tFileInputJSON_1Process(Pricing.java:3334)
at pricing.pricing_0_1.Pricing.tREST_1Process(Pricing.java:1783)
at pricing.pricing_0_1.Pricing.runJobInTOS(Pricing.java:4634)
at pricing.pricing_0_1.Pricing.main(Pricing.java:4366)
I had the same error messages (also having JSON files as input and output) and I found that the solution is to leave the Input, Response and Error Schema with the structures they initially had in tRESTClient.
The Input Schema contains body and string. Here you can either use tXMLMap to define the body structure (this didn't work for me) or send the JSON file as a string with tMap directly into the tRESTClient.
The Response has the schema statusCode, body and string. Again, just retrieving the string with a tMap and tLogRow will get you the output of tRestClient.
I hope this helps.
Include the statusCode variable in the JSON
I too got the same error, what I came across is since trestclient is expecting the schema inputs in form of stausCode , body and String.
Whereas the input is fed as key and value pair of schema. So we are getting error as enter image description here
So I used a tconvertType and converted the outgoing row from tconverttype as stausCode , body and String, and it started working.
enter image description here
and all the errors went away.
Thanks,

POSTa Request with rest assured api using XML Payload

I am in need of one requirement.I want to POST a request using Rest Assured API using XML payload,I did not get any where how to set the body using XML. any one please tell me how I can achieve this.
I have one table customers with 5 fileds,name,id,address,email and phone number.My URL to post the request is something like
"http://com.myproject.app:8080/MyApp/SchmaName/customers".Please any one help me out.Thanks in advance
The above should work, here it is again in a slightly different version with your example...
Response response = given().
contentType("application/xml").
body(myXML).
when().
post("http://com.myproject.app:8080/MyApp/SchmaName/customers");
myXML would be the xml you want to send (5 fields; name,id,address,email and phone number). After that you can pull the result from response.
You can just post in the request body as a String, InputStream, byte[] or a Java object (that will be serialized to XML using JAXB). For example:
String myXML = ..
given().contentType(ContentType.XML).body(myXML).when().post("/x").then(). ..

Scalatra -- byte array/image stream in request body

There's tons of documentation on Internet how to send a file stream in HTTP POST request in other languages, but not in Scalatra.
To the topic: I'd like to send an image as byte array or as a file stream (sorry for sloppy terminology, I'm an absolute newbie) via Scalatra post(). I already have backend Java functions that take byte array, convert it back to .jpg image and store it on the server. What I'm unclear on is the exact syntax how to do this in Scalatra.
That's what my post request looks like:
val imageInBytes = ... //obtain image in bytes
post("/images", ("image" -> imageInBytes))
However, Eclipse says that overloaded method post cannot be applied to (String, (String, Array[Byte]))
On the server side:
post("/images"){
contentType = "image/jpeg" //for displaying the image
val imInBytes = params("image") //obtain data from request body
//do something with it.
}
Any help would be greatly appreciated!
you would need to base64 url encode the image bytes then you can get it from the params bag.
You can also post a raw image to an endpoint and then read the inputStream.