Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a09280

Browse files
author
zhourenjian
committed
Improving Simple Pipe/Compound Pipe stability.
Improving SimpleSerializable and SimpleRPCRunnable, supporting smaller serialized string
1 parent181eda3 commit0a09280

File tree

11 files changed

+213
-57
lines changed

11 files changed

+213
-57
lines changed

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/CompoundPipeRequest.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ static void pipeFailed(CompoundPipeRunnable pipe) {
4141
if (pipe.pipes[i] !=null) {
4242
pipe.pipes[i].pipeFailed();
4343
}
44-
pipe.pipes[i] =null;
44+
//pipe.pipes[i] = null;
4545
}
46-
unregisterPipe(pipe.id);
46+
pipe.setupFailedRetries =0;
47+
pipe.status =0;
48+
pipe.lastSetupRetried =0;
49+
// unregisterPipe(pipe.id);
4750
}
4851
}
4952

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/CompoundPipeRunnable.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static String nextSessionKey() {
2626
longlastSetupRetried;
2727

2828
publicCompoundPipeRunnable() {
29-
pipes =newCompoundPipeSession[100];
29+
pipes =newCompoundPipeSession[4];
3030
status =0;// starting
3131
setupFailedRetries =0;
3232
lastSetupRetried =0;
@@ -60,6 +60,16 @@ public boolean pipeDestroy() {
6060
returntrue;
6161
}
6262

63+
@Override
64+
publicvoidpipeInit() {
65+
super.pipeInit();
66+
for (inti =0;i <pipes.length;i++) {
67+
if (pipes[i] !=null) {
68+
pipes[i].pipeInit();
69+
}
70+
}
71+
}
72+
6373
@Override
6474
publicbooleanpipeSetup() {
6575
returntrue;
@@ -129,7 +139,7 @@ public void weave(CompoundPipeSession pipe) {
129139
}
130140
}
131141
if (!added) {
132-
CompoundPipeSession[]newPipes =newCompoundPipeSession[pipes.length +100];
142+
CompoundPipeSession[]newPipes =newCompoundPipeSession[pipes.length +4];
133143
System.arraycopy(pipes,0,newPipes,0,pipes.length);
134144
newPipes[pipes.length] =pipe;
135145
}

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/CompoundPipeSession.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ public void pipeCreated() {
3939
publicbooleanpipeDestroy() {
4040
if (!super.pipeDestroy())returnfalse;
4141

42-
PipeSessionClosedEventevt =newPipeSessionClosedEvent();
43-
evt.session =session;
44-
pipeThrough(evt);
42+
/**
43+
* @j2sNative
44+
*/
45+
{
46+
PipeSessionClosedEventevt =newPipeSessionClosedEvent();
47+
evt.session =session;
48+
pipeThrough(evt);
49+
}
4550

4651
SimplePipeRunnablepipe =SimplePipeHelper.getPipe(pipeKey);
4752
if (pipeinstanceofCompoundPipeRunnable) {
@@ -53,6 +58,7 @@ public boolean pipeDestroy() {
5358

5459
@Override
5560
publicvoidpipeFailed() {
61+
super.pipeFailed();
5662
SimplePipeRunnablepipe =SimplePipeHelper.getPipe(pipeKey);
5763
if (pipeinstanceofCompoundPipeRunnable) {
5864
CompoundPipeRunnablecp = (CompoundPipeRunnable)pipe;

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHelper.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author zhou renjian
2424
*/
25-
classSimplePipeHelper {
25+
publicclassSimplePipeHelper {
2626

2727
staticinterfaceIPipeThrough {
2828
publicvoidhelpThrough(SimplePipeRunnablepipe,SimpleSerializable[]objs);
@@ -225,4 +225,13 @@ static boolean waitAMomentForClosing(final SimplePipeRunnable runnable) {
225225
return !runnable.isPipeLive();
226226
}
227227

228+
@J2SIgnore
229+
publicstaticvoidhelpClosing(SimplePipeRunnablepipe) {
230+
if (pipe.closer !=null) {
231+
pipe.closer.helpClosing(pipe);
232+
}else {
233+
pipe.pipeClosed();
234+
}
235+
}
236+
228237
}

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHttpServlet.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
236236
longnow =newDate().getTime();
237237
if ((lastPipeDataWritten == -1 &&now -beforeLoop >=pipeQueryTimeout)
238238
|| (lastPipeDataWritten >0
239-
&&now -lastPipeDataWritten >=pipeQueryTimeout)) {
239+
&&now -lastPipeDataWritten >=pipeQueryTimeout
240+
&&SimplePipeRequest.PIPE_TYPE_CONTINUUM.equals(type))) {
240241
output(writer,type,key,SimplePipeRequest.PIPE_STATUS_OK);
241242
lastPipeDataWritten =newDate().getTime();
242243
}

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeRequest.java‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,16 @@ private static void pipeRequest(final SimplePipeRunnable runnable) {
282282
*
283283
* @j2sNative
284284
* ajaxOut = runnable.ajaxOut;
285+
* if (ajaxOut.wrapped != true) {
285286
* runnable.ajaxOut = (function (aO, r) {
286287
* return function () {
287288
* aO.apply (r, []);
289+
* r.ajaxOut = aO;
288290
* net.sf.j2s.ajax.SimplePipeRequest.ajaxPipe (r);
289291
* };
290-
* }) (ajaxOut, runnable);
292+
* }) (ajaxOut, runnable);
293+
* runnable.ajaxOut.wrapped = true;
294+
* }
291295
*/ {if (ajaxOut ==null)ajaxOut =null;/* no warning */ }
292296
if (checkXSS(url,serialize,runnable)) {
293297
// Already send out pipe request in XSS mode. Just return here.
@@ -888,6 +892,10 @@ public void run() {
888892
if (runnable != null) {
889893
if (runnable.queryEnded && runnable.queryFailedRetries < 3) {
890894
runnable.queryEnded = false;
895+
if (runnable.received == runnable.lastPipeDataReceived
896+
&& runnable.retries == runnable.queryFailedRetries) {
897+
runnable.queryFailedRetries++; // response must not be empty
898+
}
891899
pipeFun (runnable);
892900
}
893901
var spr = net.sf.j2s.ajax.SimplePipeRequest;
@@ -896,6 +904,8 @@ public void run() {
896904
if (last == -1) {
897905
last = created;
898906
}
907+
runnable.retries = runnable.queryFailedRetries;
908+
runnable.received = runnable.lastPipeDataReceived;
899909
if (runnable.queryFailedRetries >= 3
900910
|| now - last > 2 * spr.pipeLiveNotifyInterval) {
901911
runnable.pipeAlive = false;
@@ -1032,13 +1042,25 @@ public void run() {
10321042
} else {
10331043
request.open (method, url, true, null, null);
10341044
}
1035-
request.setRequestHeader ("User-Agent",
1036-
"Java2Script-Pacemaker/2.0.0 (+http://j2s.sourceforge.net)");
1045+
try {
1046+
request.setRequestHeader ("User-Agent",
1047+
"Java2Script-Pacemaker/2.0.0 (+http://j2s.sourceforge.net)");
1048+
} catch (e) {
1049+
log ("Setting 'User-Agent' header error : " + e);
1050+
}
10371051
if (method != null && method.toLowerCase () == "post") {
1038-
request.setRequestHeader ("Content-type",
1039-
"application/x-www-form-urlencoded");
1052+
try {
1053+
request.setRequestHeader ("Content-type",
1054+
"application/x-www-form-urlencoded");
1055+
} catch (e) {
1056+
log ("Setting 'Content-type' header error : " + e);
1057+
}
10401058
if (request.overrideMimeType) {
1041-
request.setRequestHeader ("Connection", "close");
1059+
try {
1060+
// request.setRequestHeader ("Connection", "close");
1061+
} catch (e) {
1062+
log ("Setting 'Connection' header error : " + e);
1063+
}
10421064
}
10431065
}
10441066
request.send(data);
@@ -1082,6 +1104,7 @@ public void run() {
10821104
p.xhrHandle = null;
10831105
document.domain = p.parentDomain;
10841106
runnable.queryEnded = true;
1107+
runnable.queryFailedRetries++; // Failed
10851108
}
10861109
}
10871110
var now = new Date ().getTime ();

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeRunnable.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public abstract class SimplePipeRunnable extends SimpleRPCRunnable {
2929

3030
publicbooleanpipeAlive;
3131

32+
@J2SIgnore
3233
SimplePipeHelper.IPipeThroughhelper;// For Java server side
3334

35+
@J2SIgnore
3436
SimplePipeHelper.IPipeClosingcloser;// For Java server side
3537

3638
privatebooleandestroyed;
@@ -129,6 +131,7 @@ public void pipeCreated() {
129131
publicvoidpipeFailed() {
130132
// to be override
131133
// notify that pipe is not created correctly.
134+
pipeDestroy();
132135
}
133136

134137
/**
@@ -138,6 +141,7 @@ public void pipeFailed() {
138141
publicvoidpipeLost() {
139142
// to be override
140143
// notify that pipe is lost. Maybe trying to reconnect the pipe
144+
pipeDestroy();
141145
}
142146

143147
/**
@@ -148,6 +152,7 @@ public void pipeLost() {
148152
publicvoidpipeClosed() {
149153
// to be override
150154
// notify that pipe is closed by server.
155+
pipeDestroy();
151156
}
152157

153158
/**

‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleRPCRequest.java‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ protected static boolean checkXSS(String url, String serialize, SimpleRPCRunnabl
281281
} else {
282282
contents[0] = content;
283283
}
284-
g.idSet["x" + rnd] = contents;
284+
if (contents.length > 1) {
285+
g.idSet["x" + rnd] = contents;
286+
}
285287
// Only send the first request, later server return "continue", and client will get
286288
// the session id and continue later requests.
287289
net.sf.j2s.ajax.SimpleRPCRequest.callByScript(rnd, contents.length, 0, contents[0]);
@@ -301,6 +303,9 @@ protected static boolean checkXSS(String url, String serialize, SimpleRPCRunnabl
301303
var isOpera = (userAgent.indexOf ("opera") != -1);
302304
var isIE = (userAgent.indexOf ("msie") != -1) && !isOpera;
303305
if (isIE) {
306+
if (scriptObj.onreadystatechange == null) {
307+
return false; // already cleaned up
308+
}
304309
var done = false;
305310
var state = "" + scriptObj.readyState;
306311
if (state == "loaded" || state == "complete") {
@@ -309,6 +314,9 @@ protected static boolean checkXSS(String url, String serialize, SimpleRPCRunnabl
309314
}
310315
return done;
311316
} else {
317+
if (scriptObj.onerror == null) {
318+
return false; // already cleaned up
319+
}
312320
scriptObj.onerror = null;
313321
scriptObj.onload = null;
314322
return true;
@@ -330,15 +338,24 @@ protected static boolean checkXSS(String url, String serialize, SimpleRPCRunnabl
330338
script.type = "text/javascript";
331339
script.src = url + "?jzn=" + rnd + "&jzp=" + length
332340
+ "&jzc=" + (i + 1) + "&jzz=" + content;
333-
var fun = function () {
334-
if (window["net"] != null && !net.sf.j2s.ajax.SimpleRPCRequest.cleanUp(this)) {
335-
return; // IE, not completed yet
336-
}
337-
var idx = this.src.indexOf ("jzn=");
338-
var rid = this.src.substring (idx + 4, this.src.indexOf ("&", idx));
339-
net.sf.j2s.ajax.SimpleRPCRequest.xssNotify (rid, null);
340-
document.getElementsByTagName ("HEAD")[0].removeChild (this);
341-
};
341+
var fun = (function (oScript) {
342+
return function () {
343+
var g = net.sf.j2s.ajax.SimpleRPCRequest;
344+
var hKey = "h" + rnd;
345+
if (g.idSet[hKey] != null) {
346+
window.clearTimeout (g.idSet[hKey]);
347+
delete g.idSet[hKey];
348+
}
349+
if (window["net"] != null && !net.sf.j2s.ajax.SimpleRPCRequest.cleanUp(oScript)) {
350+
return; // IE, not completed yet
351+
}
352+
var src = oScript.src;
353+
var idx = src.indexOf ("jzn=");
354+
var rid = src.substring (idx + 4, src.indexOf ("&", idx));
355+
net.sf.j2s.ajax.SimpleRPCRequest.xssNotify (rid, null);
356+
document.getElementsByTagName ("HEAD")[0].removeChild (oScript);
357+
};
358+
}) (script);
342359
var userAgent = navigator.userAgent.toLowerCase ();
343360
var isOpera = (userAgent.indexOf ("opera") != -1);
344361
var isIE = (userAgent.indexOf ("msie") != -1) && !isOpera;
@@ -350,6 +367,7 @@ protected static boolean checkXSS(String url, String serialize, SimpleRPCRunnabl
350367
}
351368
var head = document.getElementsByTagName ("HEAD")[0];
352369
head.appendChild (script);
370+
g.idSet["h" + rnd] = window.setTimeout (fun, 20000); // 20s timeout
353371
*/
354372
nativestaticvoidcallByScript(Stringrnd,Stringlength,Stringi,Stringcontent);
355373

@@ -390,18 +408,16 @@ static void xssNotify(String nameID, String response, String session) {
390408
}
391409
var k = "x" + nameID;
392410
var xcontent = g.idSet[k];
411+
// TODO: The following codes should be modified to send out requests one by one.
393412
if (xcontent != null) {
394-
//The following codes may be modified to send out requests one by one.
395-
if (xcontent != null) {
396-
for (var i = 0; i < xcontent.length; i++) {
397-
if (xcontent[i] != null) {
398-
g.callByScript(nameID, xcontent.length, i, xcontent[i]);
399-
xcontent[i] = null;
400-
}
401-
}
402-
g.idSet[k] = null;
403-
delete g.idSet[k];
404-
}
413+
for (var i = 0; i < xcontent.length; i++) {
414+
if (xcontent[i] != null) {
415+
g.callByScript(nameID, xcontent.length, i, xcontent[i]);
416+
xcontent[i] = null;
417+
}
418+
}
419+
g.idSet[k] = null;
420+
delete g.idSet[k];
405421
}
406422
*/ {}
407423
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp