Unable to send lenghty JSON string to ASP.NET HttpHandler using jquery ajax call (IIS 6) - json

BACKGROUND:
I have an Http handler which receives SIM/CDMA numbers ('8953502103000101242') in json string format from jQuery Ajax call using http POST method to activate them on server.
THE PROBLEM:
On Local Development Environment I can send up to 65K SIMS' Numbers (8953502103000101242 key/value pair in json string) BUT when I deploy to LIVE server then I faced the following problem.
If I send 2000 SIMS numbers separated by comma to Http handler then Http handlers receives http request successfully But when I send more than that (3000, 4000, 5000 SIM numbers in json string) then http request doesn’t reach to HttpHandler at server even after few hours.
If I send 5000 sim numbers in http POST using jquery then the total size request sent is 138.0 KB. and it should be passed to server because server maxRequestLength is 2048576. but it is not being sent to server when we deploy it on live server and it work fine on local development environment.
TRIED SOLUTION:
I tried to resolve the problem by editing httpRuntime configuration in web.config as follows
By using above httpRuntime configuration I noticed in Firefox firebug net state that It keeps waiting sending the request as executionTimeout="7200" but if executionTimeout="600" then it returns timeout error.
ITENDED SOLUTION:
I think if I try to sync above httpRuntime element in Machine.config file as well then it work fine.
REQUIRED SOLUIOTN
WHAT CAN THE BE PROBLEM AND HOW TO RESOLVE IT. PLEASE SUGGEST IN THIS REGARD. WAITING FOR A QUICK SOLUTION.
Jquery call to HttpHandler is as follows:
$.ajax({
type: "POST",
url: "../../HttpHandlers/PorthosCommonHandler.ashx",
data: { order: JSON.stringify(orderObject), method: "ValidateOrderInput", orgId: sCId, userId: uId, languageId: lId },
success: function(response) {
var orderResult = new dojo.data.ItemFileReadStore({
data: {
jsId: "jsorderResult",
id: "orderResult",
items: response.Data
}
});
});
UPDATE
I have diagnosed the problem. one problem was executionTimeout configuration in web.config. and the after making this change second problem was due to long operation time the request was being interrupted by internet (network communication). I made sure I have reliable internet connectivity and tested it again and it worked.
BUT Now i am facing another problem. My httphandler send request to a webservice and I am getting following exception in response.
The operation has timed out

I have fixed the problem.
one problem was executionTimeout configuration in web.config. and the after making this change second problem was due to long operation time the request was being interrupted by internet (network communication). I make sure I have reliable internet connectivity and tested it again.
configured the webserivces as follows.
<httpRuntime executionTimeout="7200" enable="true" maxRequestLength="2048576" useFullyQualifiedRedirectUrl="false" />
and
[WebMethod(Description = "Delete template",BufferResponse = false)]
Specifying "BufferResponse=false" indicates that .NET should begin sending the response to the client as soon as any part of the response becomes available, instead of waiting for the entire response to become available.

Related

GameMaker runner crashes when making HTTP requests

I recently got back into using GameMaker:Studio, and hoo boy have there been some massive updates since I last used it! In fact the last time I used it they only had Windows and HTML5 as export options...
Anyway, eager to try out some of the new stuff, I decided to take a shot at the native HTTP functions, since they looked very promising.
I did a test using http_post_string() to great effect, sending a JSON string to my server and getting a JSON string back. The returned string actually represented an object with a single property, "echo", which contained the HTTP request that had been made, just to see what GM:S was sending.
I didn't like that it sent Content-Type: application/x-www-form-urlencoded when it was quite clearly JSON, and I wanted the ability to set my own User Agent string so that the server could know which game was talking to it without having to pass an extra parameter.
So I re-created the same request using the lower-level http_request() function. Everything looked fine, so I tested it.
It crashed. Like, no error messages or anything, just a total crash and Windows had to force-close it.
So here I am with code that by all rights should work fine, but crashes when run...
///send_request(file,ds_map_data,callback_event_id)
var request = ds_map_create();
request[? "instance"] = id;
request[? "event"] = argument2;
if( !instance_exists(obj_ajax_callback)) {
instance_create(0,0,obj_ajax_callback);
}
var payload = json_encode(argument1);
var headers = ds_map_create();
headers[? "Content-Length"] = string_length(payload);
headers[? "Content-Type"] = "application/json";
headers[? "User-Agent"] = obj_ajax_callback.uastring;
var xhr = http_request("https://example.com/"+argument0,"POST",headers,payload);
with(obj_ajax_callback) {
active_callbacks[? xhr] = request;
}
ds_map_destroy(headers);
obj_ajax_callback is an object that maintains a ds_map of active requests, and in its HTTP event it listens for those requests' callbacks and reacts along the lines of with(request[? "instance"]) event_user(request[? "event"]) so that the calling object can handle the response. This hasn't changed from the fully working http_post_string() attempt.
Any idea what could be causing this crash?
The reason why this crashes is because you are sending the Content-Length header as a real instead of a string. If you change your line to
headers[? "Content-Length"] = string(string_length(payload));
It should work.

Jmeter posting json application

Hello I have got problem I have configured my Jmeter to test performance between play framework version 2.2 and 2.3 to check the speed of controllers but when I post something (here im creating account) in play console I see that account is creating but its not saving in my database, when I have done this same from another laptop by typing my IP Adress it saved it to database and worked good. I dont know where could be the problem cause configuration is the same.
In Jmaker in thread I have made
HTTP Head Manager and i added here
Name: Content-Type Value: application/json
I have made too HTTP Request
Server Adress: localhost Port:9000 Method: Post Content encoding: UTF-8
Path: api/accounts Implementation: HTTPClient 4 Portocol [http]: http
And in parameters I added
name:(nothing),
Value:{"username":"AccountTest1","password":"test6ccou49","email":"AccountTest1#dev.null"}
and I have turned only Include Equals
I added to Constant Timer and jp#gc Response Times over time from plugin which is making chart
I dont know why when I press Start: chart is building, in play console I see account creating but this is not saving to database.
I will be very thankful for every help.
Create a CSV file like below sample data:
AccountTest1,test6ccou49,AccountTest1#dev.null
AccountTest2,test6ccou50,AccountTest2#dev.null
AccountTest3,test6ccou51,AccountTest3#dev.null
..... so on
Add->Config Element->CSV Data Set Config
keep settings as mentioned below:
Filename: "Give complete file path with file name e.g. c:\folder1\folder2\file.csv"
File Encoding: "Leave Blank"
Variable Names: "user_name,pass_wd,e_mail"
Delimiter: ","
Allow Quoted Data: "false"
Recycle on EOF: "True"
Stop Thread on EOF: "false"
Sharing mode: "All threads"
Now Post body should look like
{"username":"${user_name}","password":"${pass_wd}","email":"${e_mail}"}
Hope this will help.
Try to use "Post Body" in the HTTP Sampler to post below values
{"username":"AccountTest1","password":"test6ccou49","email":"AccountTest1#dev.null"}
Hope this will help.
I have repaired it already, the problem was in Http Header :), I have got question, now I'm creating accounts by requesting
{"username":"AccountTest1","password":"test6ccou49","email":"AccountTest1#dev.null"}
But this create one account, I was testing some solutions on the Internet but them don't work also is here any way to make a lot of accounts in one time to test performance?
My create account function gets json object {xxx:yyy,bbb:ccc}

why DeferredResult ends on setResult() on trying to use SSE

i am trying to implement a Server Sent Events (SSE) webpage which is powered by Spring. My test code does the following:
Browser uses EventSource(url) to connect to server. Spring accepts the request with the following controller code:
#RequestMapping(value="myurl", method = RequestMethod.GET, produces = "text/event-stream")
#ResponseBody
public DeferredResult<String> subscribe() throws Exception {
final DeferredResult<String> deferredResult = new DeferredResult<>();
resultList.add(deferredResult);
deferredResult.onCompletion(() -> {
logTimer.info("deferedResult "+deferredResult+" completion");
resultList.remove(deferredResult);
});
return deferredResult;
}
So mainly it puts the DeferredResult in a List and register a completion callback so that i can remove this thing from the List in case of completion.
Now i have a timer method, that will periodically output current timestamp to all registered "browser" via their DeferredResults.
#Scheduled(fixedRate=10000)
public void processQueues() {
Date d = new Date();
log.info("outputting to "+ LoginController.resultList.size()+ " connections");
LoginController.resultList.forEach(deferredResult -> deferredResult.setResult("data: "+d.getTime()+"\n\n"));
}
The data is sent to the browser and the following client code works:
var source = new EventSource('/myurl');
source.addEventListener('message', function (e) {
console.log(e.data);
$("#content").append(e.data).append("<br>");
});
Now the problem:
The completion callback on the DeferredResult is called on every setResult() call in the timer thread. So for some reason the connection is closed after the setResult() call. SSE in the browser reconnects as per spec and then same thing again. So on client side i have a polling behavior, but i want an kept open request where i can push data on the same DeferredResult over and over again.
Do i miss something here? Is DeferredResult not capable of sending multiple results? i put in a 10 seconds delay in the timer thread to see if the request only terminates after setResult(). So in the browser the request is kept open until the timer pushes the data but then its closed.
Thanks for any hint on that. One more note: I added async-supported to all filters/servlets in tomcat.
Indeed DeferredResult can be set only once (notice that setResult returns a boolean). It completes processing with the full range of Spring MVC processing options, i.e. meaning that all you know about what happens during a Spring MVC request remains more or less the same, except for the asynchronously produced return value.
What you need for SSE is something more focused, i.e. write each value to the response using an HttpMessageConverter. I've created a ticket for that https://jira.spring.io/browse/SPR-12212.
Note that Spring's SockJS support does have an SSE transport which takes care of a few extras such as cross-domain requests with cookies (important for IE). It's also used on top of a WebSocket API and WebSocket-style messaging (even if WebSocket is not available on either the client or the server side) which fully abstracts the details of HTTP long polling.
As a workaround you can also write directly to the Servlet response using an HttpMessageConverter.

Error sending data to a HTTPS server with as3httpclientlib

I'm trying to send some data from flash to a server. I was doing it with a test server and everything was ok. But when I change to test it into a real server it send me an error: " got Alert! Type=22" So I searched about it and I discover that its because the real server runs on HTTPS and the test runs on HTTP. So, reading the documentation of the as3httpclienlib library that I am using, I found that there is a bug with some HTTPS servers and cause some errors and don't leave flash send more than 40kb of data, so that throws the error Type 22 -> Record overflow
This only happens with TLS Sockets so I think that the solution is change the TLSSocket to a SSLSocket.
This is the code that I use to send the data to the server:
var client:HttpClient = new HttpClient();
var uri:URI = new URI("http://www.snee.com/xml/crud/posttest.cgi");
var variables:Array = [{name:"fname", value:"FirstName1"}, {name:"lname", value: "LastName1"}];
client.listener.onData = function(event:HttpDataEvent):void {
// Notified with response content in event.bytes as it streams in
};
client.listener.onComplete = function(event:HttpResponseEvent):void {
// Notified when complete (after status and data)
};
client.postFormData(uri, variables);
How can I change this sockets?
Does anyone have an example?
Is this the solution of the problem?

How to get HTTP status code in HTTPService fault handler

I am calling a server method through HTTPService from client side. The server is a RestFul web service and it might respond with one of many HTTP error codes (say, 400 for one error, 404 for another and 409 for yet another). I have been trying to find out the way to determine what was the exact error code sent by the server. I have walked teh entire object tree for the FaultEvent populated in my fault handler, but no where does it tell me the error code. Is this missing functionality in Flex?
My code looks like this:
The HTTP Service declaration:
<mx:HTTPService id="myServerCall" url="myService" method="GET"
resultFormat="e4x" result="myServerCallCallBack(event)" fault="faultHandler(event)">
<mx:request>
<action>myServerCall</action>
<docId>{m_sDocId}</docId>
</mx:request>
</mx:HTTPService>
My fault handler code is like so:
private function faultHandler(event : FaultEvent):void
{
Alert.show(event.statusCode.toString() + " / " + event.fault.message.toString());
}
I might be missing something here, but:
event.statusCode
gives me the status code of the HTTP response.
So I can successfully do something like this in my fault handler function:
public function handleFault(faultEvent:FaultEvent):void
{
if (faultEvent.statusCode == 401)
{
Alert.show("Your session is no longer valid.", "", Alert.OK, this, loginFunc);
}
else
{
Alert.show("Failed with error code: " + faultEvent.statusCode as String);
}
}
Looks like you are out of luck: http://fantastic.wordpress.com/2007/12/26/flex-is-not-friendly-to-rest/
You may have to use ExternalInterface to get this handled in JS and then communicated to Flex.
The Flash Player needs help from the browser to be able to access the HTTP status code; therefore, this is not available on all platforms. For me, it failed with Flash Player 10.3.183.11 and Firefox 3.6.26, but worked with IE 8 on Windows 7.
The Adobe help for the FaultEvent.statusCode property hints at this, but unfortunately doesn't go into details:
this property provides access to the HTTP response status code (if available), otherwise the value is 0
So, if you absolutely need the status code, bad luck; if it's just to generate a better or friendlier error message for some frequent error conditions, it may be sufficient.
as3httpclient as posted by Ross is friendly to Rest, and provides you with the HTTP status code, as long as you're developing for AIR and not a browser-based app.
I could not get as3httpclient to work from the browser, even when making requests to the same origin. There's documentation stating you need to set up a socket policy file server to get this to work. Not scalable for our uses so I setup a Proxy web service on the same host running the flex app.
I use HTTPService to make the call to the proxy web service, which forwards the request to the destination, and the proxy web service returns the http status code and message body back to the HTTPService in xml.
Try using this instead of HTTPService:
http://code.google.com/p/as3httpclient/