How to run the request multiple times and save the response to a single file in SOAPUI? - request

I'm developing an app in c# to communicate with SOAPUI.
I have a specific Test Case which called TERMEKADAT TestCase, I need to call this TestCase more time than 1 and save the data to file(all responses data to ONE file).
In the c# app I can call the test case using command line and I can storage the response, but i can do it one time(if i do this more times, the dump file will overwritten, so the latest datas are gone).
Can i somehow storage all requests data in ONE file?
Can SOAPUI append the responses in one file?
I need to storage more responses in one file.

You could do it like this in a Groovy Script Test Step in your test case:
import com.eviware.soapui.support.XmlHolder
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def resp = new XmlHolder(context.response) //get the response object
def respXml = resp.getXml() //get the XML string from the response
def respFile = new File("/your/dir/yourFile.txt")
respFile.append(respXml)

Related

Avoiding using save() function twice

I want to use external API for my django application, which sends image to the server and receives back some LaTeX.
My model looks like this:
class Snip(models.Model):
snip = models.FileField(upload_to="snips/") #stored image
latex = models.TextField(default = '') #received text from API
The image has to be stored/saved so URL might be included in JSON sent to the API. But that implies newly uploaded image has to be saved in newly created Snip object and after receiving the requested text back saved again.
My view looks like this:
if file:
temp_snip = Snip() #creating newe object
temp_snip.snip = file
temp_snip.save() #saving image to the database (required for getting image URL)
temp_snip.setLatex() #some magic :)
temp_snip.save() #saving the magic (second field in the model).
My question is:
Is there any simple solution to avoid using save() function twice?

How to read a list of objects from a file in Dart/Flutter

I am developing a Flutter App, and I wish to save a list of objects (Contacts) to the app directory.
As suggested in the Cookbook, I use the path_provider package and the File class of Dart.
Getting to write the objects was easy (I think - I didn't get any error). Here is the code I used for writing the list:
Future<void> writeContact(List<Contact> contacts) async {
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/contacts.txt');
// Write the file
IOSink sink = file.openWrite(mode: FileMode.write);
sink.write(contacts);
sink.close();
}
The question is - how to I read this file and populate the List of Contacts?
Thanks, Gal.

Apache Camel: create and return file in response on the fly

I have a Camel route that should return a file in the response, which is created based on the request data. While this works fine with the following (greatly simplified) route, the problem is that I need to first create an actual file on the server that I can then add to the exchange body.
As I don't want these file piling up on the disk, I would prefer to either not create them at all or delete them directly from the same route.
The only way around this I currently see is to have a regular cleanup job that deletes these temporary files.
Any suggestions on how to solve this in a better way?
from("cxfrs://...")
.process(exchange -> {
File file = new File("out.pdf");
// write data to new FileOutputStream(file);
exchange.getIn().setBody(file);
})
The response content type is application/octet-stream.

Returning multiple items with Servlet

Good day, I'm working on a Servlet that must return a PDF file and the message log for the processing done with that file.
So far I'm passing a boolean which I evaluate and return either the log or the file, depending on the user selection, as follows:
//If user Checked the Download PDF
if (isDownload) {
byte[] oContent = lel;
response.setContentType("application/pdf");
response.addHeader("Content-disposition", "attachment;filename=test.pdf");
out = response.getOutputStream();
out.write(oContent);
} //If user Unchecked Download PDF and only wants to see logs
else {
System.out.println("idCompany: "+company);
System.out.println("code: "+code);
System.out.println("date: "+dateValid);
System.out.println("account: "+acct);
System.out.println("documentType: "+type);
String result = readFile("/home/gianksp/Desktop/Documentos/Logs/log.txt");
System.setOut(System.out);
// Get the printwriter object from response to write the required json object to the output stream
PrintWriter outl = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object
outl.print(result);
outl.flush();
}
Is there an efficient way to return both items at the same time?
Thank you very much
HTTP protocol doesn't allow you to send more than one HTTP response per one HTTP request. With this restriction in mind you can think of the following alternatives:
Let client fire two HTTP requests, for example by specifyingonclick event handler, or, if you returned HTML page in the first response, you could fire another request on window.load or page.ready;
Provide your for an opportunity of choosing what he'd like to download and act in a servlet accordingly: if he chose PDF - return PDF; if he chose text - return text and if he chose both - pack them in an archive and return it.
Note that the first variant is both clumsy and not user friendly and as far as I'm concerned should be avoided at all costs. A page where user controls what he gets is a much better alternative.
You could wrap them in a DTO object or place them in the session to reference from a JSP.

How to pass a google mapreduce parameter to done_callback

I'm having trouble setting a parameter when kicking off a mapreduce via start_map so I can access it in done_callback. Numerous things I've read imply that it's possible, but somehow I've not got the earth-moon-stars properly aligned. Ultimately, what I'm trying to accomplish is to delete the temporary blob I created for the mapreduce job.
Here's how I kick it off:
mrID = control.start_map(
"Find friends",
"findfriendshandler.findFriendHandler",
"mapreduce.input_readers.BlobstoreLineInputReader",
{"blob_keys": blobKey},
shard_count=7,
mapreduce_parameters={'done_callback': '/fnfrdone','blobKey': blobKey})
In done_callback, the context object isn't available:
class FindFriendsDoneHandler(webapp.RequestHandler):
def post(self):
ctx = context.get()
if ctx is not None:
params = ctx.mapreduce_spec.mapper.params
try:
blobKey = params['blobKey']
logging.info(['BLOBKEY ' + blobKey])
except KeyError:
logging.info('blobKey key not found in params')
else:
logging.info('context.get did not work') #THIS IS WHAT GETS OUTPUT
Thanks!
EDIT: It seems like there may be more than one MR library, so I wanted to include my various imports:
from mapreduce import control
from mapreduce import operation as op
from mapreduce import context
from mapreduce import model
Below is the code I used in my done_callback handler to retrieve my blobKey user parameter:
class FindFriendsDoneHandler(webapp.RequestHandler):
mrID = self.request.headers['Mapreduce-Id']
try:
mapreduceState = MapreduceState.get_by_key_name(mrID)
mrSpec = mapreduceState.mapreduce_spec
jsonSpec = mrSpec.to_json()
jsonParams = jsonSpec['params']
blobKey = jsonParams['blobKey']
blobInfo = BlobInfo.get(blobKey)
blobInfo.delete()
logging.info('Temp blob deleted successfully for mapreduce:' + mrID)
except:
logging.warning('Unable to delete temp blob for mapreduce:' + mrID)
This uses the mapreduce ID passed into done callback via the header to retrieve the mapreduce state model object from the mapreduce state table. The model stores any user params sent via start_map in a mapreduce_spec property which is in json format.
Note that MR, itself, actually stores the blob_key elsewhere in mapreduce_spec.
Thanks again to #Nick for pointing me to the model.py source file.
I'd love to hear if there's a simpler way to get at MR user params...
Context is only available to mappers/reducers - it's largely concerned with things that don't make sense outside the context of one. As you can see from the source, however, the "Mapreduce-Id" header is set, from which you can get the ID of the mapreduce job.
You shouldn't have to do your own cleanup, though - mapreduce has a handler that does it for you.

Resources