issue testing async web service in SoapUI - java

I'm running a multi-threaded load test using SoapUI open source edition. I'm testing an asynchronous web-service. I send requests to the service via SoapUI, these requests are queued for later execution, and the web service sends notification responses later.
I'm using a MockService to capture these notification responses. I now need a way of mapping each response back to the request that SoapUI originally sent out so that the latency from request to response can be tracked. To do this, I was going to define a ConcurrentHashMap. The test step that sends a request would update the hashmap with the request id and current time. When my MockService receives a notification response it would access the hashmap to get the start time of that request id.
The problem I'm facing is that I would need to declare the hashmap in a scope where all the threads access the same hashmap and the MockService also has access to it.
If I declare my hashmap in a groovy test step, then each thread when executing the test step would create its own copy of it, which is not what I want.
My question is whether there is a way in SoapUI to declare my hashmap at a "global" scope so that all the test threads (and my MockService) can access the same hashmap instance?
I tried declaring it in the setup script of the TestSuite and adding it to the TestSuite context but that doesn't seem to be working.
Can someone help with this?

Related

Is Spring Rest Controllers Singleton?

I have a sample Spring Rest application.
I have several clients accessing an API in the Spring Rest application. The API checks whether a job has started or not against the MSSQL DB that we use.
If the Job status in DB is in started status, it will pick the record and update its status to inprogress and return the details of the Job as the response to the API and based on that the client will do some processing.
We have observed that, more than one client is picking up the same Job which is in started status and updates it to inprogress and pass the response to the client. So, it ends up like the same job is being processed by multiple clients.
We tried to resolve this by adding a synchronized block and enclosed the DB call that picks the record in started state and update it to inprogress. The DB call resides in the service layer. But still the duplicate issue is there.
If the controller and the subsequent layers like service and DAO layers are singleton then, when multiple API calls hit the web app, the synchronized block of code should be executed by one request at a time. But that is not what we see practically.
Could someone please help to resolve this issue?
Actually Rest Controllers are Thread Safe it means it is capable of handling each HTTP requests unique. Also when you try to access the Rest Controller it creates a separate session id in browser you can also check that using developer console. Here you are trying to access same DB and change the status as inprogress, so there is a chance for the next api to fetch details of the previous session.. so try to modify the Rest API without modifying status in DB every time or you can do something like, if the DB is accessed by one API then the other API should not be able to access DB until the first connection is closed. Hope this can work for you.

Long running we request, UI gets timed out by the time response is ready

I have one angular app and one spring boot app, there is one request goes from UI to spring boot with some 100-200 objects even more, for each of these objects another back end system is called within a loop.
something like..
list.parallelStream().forEach(e->{
//code using rest template for backend.
// add the responses to an array list.
// i can send all these objects to backend at one shot because they have some limitations and dont support it currently.
});
This takes a lot of time to complete and by the time all the request is completed the UI gets timed out.
I tried using executer framework, forkjoin or parallel but this is not enough. because browser wait for 30-60 sec.
I want to switch to anyc process where i submit request to spring boot, from UI I should be able to check the status of the request after time interval. i tried concepts like DeferredResult, #Async, completeable future and StreamingResponseBody. is there any way to handle these long running request???
Some of these concepts works but when the input size increase they also fail to work properly. how do i manage to get the status of my request and use some progress bar etc to show even user.
or any better approch?
For me it sounds like you want to stream data.
Perhaps spring's reactive stack is something you want to look at:
Building a Reactive RESTful Web Service
Video Tutorial using Kotlin
With this your angular app should be able to display or react very finished processing of an individual item as they happen.
Hope that helps.

OTRS invoker remote webservice not running resend request again

I configured invoker to make webservice request when ticket is changed or updated.
it working fine.
If the ticket changed and the remote webservice is not running than it will wait till timeout happen and after that it wont make another request.
Now one requirement i got is when ticket is changed the invoker will make a call to remote host url, if that remote webservice is not running than after timeout happens i have to make another request to webservice till remote webservice gets the request.
how can i configure the invoker to resend the request to the remote webservice.
I have worked with the Generic Interface for quite some time and in my experience you can't configure it to behave like this.
You can however create your own solution:
You could add a dynamic field for all tickets of type checkbox, let's call it WebserviceUnavailable and set it to False/Invalid by default. In your invoker the first thing you do is set that dynamic field WebserviceUnavailable to True. Then you do your processing and prepare your data for the Generic Interface as usual. In the code for the response you set the dynamic field WebserviceUnavailable to False if your processing went well.
Then you can write another script that gets called periodically (using a Cronjob for example). In this script you search for all tickets that have the Webserviceunavailable dynamic field with the value True. For each of those tickets you call your webservice again.

RUN code after sending SOAP response in java

My web service get a SOAP request from user. After doing all the stuff in service could I send back the user response and then run some code ?
Actually I want to log the output of my service. If I run the code that logs the output and if that logging service fails, I could not send back any response due to that error.
IS there a way that I send user response of my service and then run logging service after that ?
I tried close method of SOAP handler but it runs before my service has returned response.
Essentially you need to find a callback (http://cleancodedevelopment-qualityseal.blogspot.co.uk/2012/10/understanding-callbacks-with-java.html) you can hook into after the http response has been accepted back from the server.
See here for a similar question: SOAP web service callback architecture? that was answered.
You should use callback function to sure that responsing is finished
Use try-catch to control the errors in your code. For your case you can control if your logging service fails or not and send the response to user.
Exceptions try
If you want to use something more complex you can use an async approach using queues or events.
in JEE you can use "#Asynchronous" annotation for the method that need to log. It will run asynchronously, so it will not block the return of the webservice.
If you need the result of that method, you will need manage to store the reference of the Future, for example in a singleton, then get the esult in a second Webservice call.

Handling Post Requests

yesterday i started brainstorm for a project of mine and I'm not sure if its the correct approach.
On my website I'm having an (kind of an order form) which sends a post to a target URL, which works with a simple curl php script. The target is an external service (where I have no access no rights, nothing). I only know that I will get a POST with further processed data back from the service, which I have to save into my DB.
in steps:
Users fills out the (order) form and posts data to an external url on my website.
data gets externally handled and after finishing that resents a post.
read incoming post data.
save data into DB.
Success page on my website.
My thoughts were to handle the incoming data with a servlet (spring maven project) but I'm not sure if this is a correct approach. Is there a better why to do this. Or is the first step with the php scripts wrong. thx for any help.
A simplest workflow could be
1. Forward the initial (Order form with values) request to a servlet
2. Invoke a post request using java to an external url inside this servlet (Using Apache http client, or libraries such as HTMLUnit)
3. Once you get the incoming response in your servlet, you can update your database.
If you are using spring, the controller could forward initial request to a business class which will handle this post processing and delegate the database update to respective DAO.
There are a number of suitable ways to handle this, and the decision is largely a matter of preference and what you're familiar with. Spring can handle this sort of job quite well.
Note: Maven is a build system for Java and some other JVM languages. I recommend using it, but it's not part of Spring; what you're probably looking for is Spring MVC.

Categories

Resources