XmlHttpRequest not reporting server side progress - xmlhttprequest

I have a client server application. The server side is completely in java. The client side has a few lines of html and the rest in plain javascript (I don't use ajax or jquery etc).
The client receives user inputs through an input box and when the user clicks a button, the client sends a POST request to the server using XmlHtpRequest. The server then runs a process that can take several minutes. The server periodically (every 5 seconds) sends a progress update message with HTTP status code 202 and with content "Processing.... completed 5 / 100". The numbers 5 and 100 are a sample. Instead of 100, it is the actual final counter of the process and instead of 5 it is the current counter indicating the progress. When the server finishes the processing it sends a 200 OK with the final output as the content. I have an output text area where I want to display the progress message during the processing and later the final output is also placed in the same output text area.
My client side javascript code is:
<script>
var xhr = new XmlHttpRequest();
function sendCommandToServer() {
window.xhr.onreadystatechange = getServerResponse;
window.xhr.open("POST", (document.domain + "/" + "executeCommand"), true);
window.xhr.send("arguments and data for the command");
}
</script>
<script>
function getServerResponse() {
if(window.xhr.status === 202) {
myTextArea.value = window.xhr.responseText;
window.xhr.onreadystatechange = getServerResponse;
return;
}
if(window.xhr.status === 200) {
myTextArea.value = window.xhr.responseText;
return;
}
alert("processing error");
}
</script>
The server correctly gets the command and runs the process and finishes and produces the output. It also correctly sends the progress messages. But my client side javascript does not get all of them. I am able to get the 1st progress message from the server - something like - "Processing .... 5 / 100" - but after that I am not able to get further calls to getServerResponse() to continue updating the progress as and when the server sends messages. If I modify the server side to avoid sending progress and send only the final output result, it works correctly and I get the final output result displayed at the client. I run this on IE10 and Chrome, with the same behavior. Can xmlHttpRequest() be used for this use-case? Am I doing something wrong? Any help will be appreciated. Thanks.

I'm new to this myself and trying to work out a method of achieving something similar.
I think the 202 status code is the only response you will get, ie the server will send a single response when it has accepted the job (202), or a 200 response when it has completed.
Source:
http://100pulse.com/http-statuscode/202.jsp

Related

What is the order of HTTP responses, data, and error, and are they guaranteed to be in that order?

I am debugging/testing the part of my app that sends an HTTP POST, with a file to upload, to a 3rd party server and need to be sure of the order of the info that server sends back.
Below is a very trimmed down sample of how I handle what is returned by the server.
At this moment, am debugging for files sent that exceed the LimitRequestBody size set in Apache. Yes, I do check file size in my app before sending, but am trying to debug for anything possible, i.e. malicious bot sending data outside of my app.
What I can't seem to find online is the lifecycle of what a server will send back in terms of the response, data, and error, and need to be sure I will get them back in this order:
Response
Data
and if there's an error:
Error (and then nothing else)
uploadSession.dataTask(with: upFile.toUrl!)
{ (data, response, error) in
if let response = response {
upLoadInvClass.upResp(resp: response)
}
if let error = error {
upLoadInvClass.upErr(error: error)
}
if let data = data {
upLoadInvClass.upData(data: data)
}
}.resume()

How to troubleshoot issues related to requests and responses from ws loaded in SM

I am working on an integration between Microfocus Service Manager and Remedy. In order to troubleshoot issues related to requests and responses from SM to Remedy is needed to print or send that information to a log. I have tried using a debug -RTM:3 flag in my testing port configuration, but unfortunately there is a lot of information in my log since it writes every step performed by the tool. After that, I set the -debughttp flag in my port, but it only writes inputs/outputs from external resources.
Here is what I have done:
Load Remedy customer's endpoint with WSDL2JS utility.
Invoke the endpoint with a SL.
Perform a request to the endpoint.
Get an undefined response.
Check logs written by -RTM and -debughttp without success.
Is there any way to check what’s happening with my requests or with my customer’s reponses?
You can get the content of your requests and responses using the sl created by WSDL2JS only adding a piece of code within it.
For your requests, look for this part of the code (about line 129):
this.resultXML = doSOAPRequest( this.location, soapOp.SOAPAction, result.xml,
this.user, this.password,
this.connectTimeOut, this.sendTimeOut, this.recvTimeOut,
this.attachments, this.acceptfastinfoset );
Add the following code below:
//Print your request
print(result.xml)
//Send your xml request to a internal log called integration_debug.log in your app server
writeFile("../logs/integration_debug.log","a","\n");
writeFile("../logs/integration_debug.log","a","######### REQUEST INFO XML######\n");
writeFile("../logs/integration_debug.log","a",system.functions.tod()
+ "\n"
+ result.xml
+ "\n"
+ "\n");
For your customer’s responses, look for this part of the code:
if ( soapOp.responseObj == "null" ) // one-way MEP ?
{
return null;
}
var resultObj = new Object();
resultObj.responseObj = soapOp.responseObj;
Add the following code below:
//Print your customer response
print(this.resultXML.getDocumentElement())
//Send your xml response to a internal log called integration_debug.log in your app server
writeFile("../logs/integration_debug.log","a","\n");
writeFile("../logs/integration_debug.log","a","######### RESPONSE INFO XML#######\n");
writeFile("../logs/integration_debug.log","a",system.functions.tod()
+ "\n"
+ this.resultXML.getDocumentElement()
+ "\n"
+ "\n");
As a reference you can check the following picture to identify where inserting your code:
Hopefully, that can be helpful for your troubleshooting.

sending the same request multiple times in a raw. some return with status code 204 and some are ok

I'm sending a post request to the same url multiple times in a row. Some of the requests return 200 status code and some return 204 saying no content. the request updates some content in a mongo database. I don't know if this is relevant. What could cause this problem?
My index.js:
app.post('/updatetrialsession',authenticateJWT ,(req,res)=>{
User.findOne({username:req.user.username}).then(user=>{
var trialIdx=user.examTrials.findIndex(it=>it.trialId===req.body.trialId)
var questionIdx=req.body.questionIdx
if(trialIdx!==-1){
user.examTrials[trialIdx].questions[questionIdx]=req.body.question
user.examTrials[trialIdx].currentQuestion=questionIdx+1
user.examTrials[trialIdx].countDown=req.body.countDown
user.examTrials[trialIdx].numOfSolved=req.body.numOfSolved
var filter={
'username':user.username
}
var update={
$set:{
'examTrials':user.examTrials
}
}
User.findOneAndUpdate(filter,update).then(user=>{
console.log('updated')
res.json({
status:"success"
})
})
}
})
})
Note: all requests go to this url "/epdatetrialsession".
when there's a 20 sec gap between each request everything works just fine. but when the server get flooded with say a request every 2 seconds or so, some return with 204 status code
I have had the same issue once. In my experience, When sending multiple number of requests to the server within a very short period of time, sometimes the server fails to answer all of them. Depends on the server capability. Did you try to check this by, sending the request for only the ones which returns 204 one at a time and see whether they still returns a 204? If so, the server has responded correctly even when sending the requests in a row. But if the server return a content with 200 when sending one at a time, then the issue might be with the server when handling multiple requests at a time.

Visual Studio Load Test keeps sending request

I started using Visual Studio load test a few days ago. I am calling a URL and get the average response time results. My problem is I want the test tool send 1 user 1 request. But the test tool sends 1 request every 5 secs. How can I limit the number of total request. I want to connect my code to an MDB file which has 2000 records. And I want 1 user to send these 2000 records one by one.
My current code is as below. Please help.
Best regards
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request;
if (true)
{
request = new WebTestRequest("http://192.168.1.36:8888/webgis_net/wms.ashx?NCWS=OGM&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=30.4181109599491,40.4702930755111,30.4195710292824,40.4717531448444&SRS=EPSG:4326&WIDTH=256&HEIGHT=256&LAYERS=Uydu,ILCELER,ILLER,MAHALLE_HAT,CASN,ORMAN,ORMAN_HAT,B2,B2_HAT,ZIRAAT,ZIRAAT_HAT,SU,SU_HAT,NOKTA,OSN&FORMAT=image/png");
request.Method = "GET";
request.Timeout = 180;
yield return request;
}
}
When you create your new Load Test do the following in the New Load Test Wizard:
In the Load Pattern tab check the Constant Load option and set the User Count = 1
In the Test Mix Model tab check the Bases on the number of tests option
In the Test Mix tab add only the Web Test you want
In the Run Settings tab check the Test Iterations option and set the Test Iterations = 2000
With this way, only one virtual user will be created and the Tests (2000) will be one after the other but not concurrently

Problem with WCF Response - getting multiple responses

I am using Silverlight, WCF combination.
Currently, I am facing one problem with service response.
I am using request response service type.
I have 100 Items and i am going to call 100 services to fetch it's properties.
foreach (ItemDto item in items)
{
ServiceCall();
ServiceSendCount++;
}
private void OnServiceCallCompleted(.....)
{
ServiceReceiveCount++;
}
If i am sending 5 service calls then it returns with 5*5 = 25 responses.
same with as i am sending 10 service calls then it returns with 10*10 = 100 responses.
I am not able to figure out what was the problem....
Can anyone please shed some light on this?
Update:
Please find herewith the service call method.
I agree that each and every time i am sending OnServiceCallCompleted ..
foreach (ItemDto item in items)
{
itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);
ServiceSendCount++;
}
private void OnServiceCallCompleted(.....)
{
ServiceReceiveCount++;
/* here contains my logic to process the response
If it cames mulriple time then my logic will down
*/
}
Can you please let me know the solution for same. As the change in the service is not possible right now.
But it will create the problem of response time.
Suppose i am going to send the request for 100 items at a time.
In My first approch, i will get the first 100 responses with correct data in withing 5-10 sec.
ItemPropertyService itemPropertyService = new ItemPropertyService();
foreach (ItemDto item in items)
{
itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);
ServiceSendCount++;
}
(Problem as i discussed it is going to send me 100 X 100 responses which leads to the timeout)
In Second Approch, (As per u have suggested)
foreach (ItemDto item in items)
{
ItemPropertyService itemPropertyService = new ItemPropertyService();
itemPropertyService.GetItemProperties([parameters] , OnServiceCallCompleted);
ServiceSendCount++;
}
I am getting same responses as of request, but it will take time near about 2 min.
Actually, I am not able to figure out the problem of time consuming.
As our requests are very huge it will really going to take time.
Do you know about this that how to solve this problem?
I am just near to solve my problem.
Can't tell from the code as you didn't show the ServiceCall() function but numbers suggest you are reusing the same proxy object and adding the OnServiceCallCompleted event handler every time you make a request. If you add the same event handler multiple times it is going to fire multiple times and the completed event handler is per proxy object not per request.
Try creating a new proxy object for each request and seeing if you still get multiple responses.