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

Commitaf5e705

Browse files
author
zhourenjian
committed
Refactor codes.
Upgrade SimpleRPC from 1.0.0 to 1.0.1, the format of SimpleSerializable is modified a little.Attention: v 1.0.1 is not compatible with v 1.0.0
1 parentb5b1679 commitaf5e705

File tree

5 files changed

+226
-145
lines changed

5 files changed

+226
-145
lines changed

‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleFieldFilter.java‎renamed to ‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleFilter.java‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,28 @@
1212
packagenet.sf.j2s.ajax;
1313

1414
/**
15+
* This interface is used in the Java side to decide whether a given field
16+
* should be serialized or not.
17+
*
18+
* Usually, fields with modifier of public or protected among types of number
19+
* type, string type, array type will be serialized by default. But when a
20+
* SimpleFieldFilter is specified, some of the fields may not be serialized
21+
* again. For example, when a SimpleRPCRunnable instance is passed in through
22+
* HTTP connection, and some fields are modified before this instance is
23+
* back to client side. But it is no need to serialize all fields but only
24+
* those modified fields.
25+
*
1526
* @author zhou renjian
1627
*
1728
* 2007-06-10
1829
*/
19-
publicinterfaceSimpleFieldFilter {
30+
publicinterfaceSimpleFilter {
2031

2132
/**
2233
* Filter the fields to be serialized or not.
2334
* @param field
2435
* @return true for to be ignored and false for to be serialzed
2536
*/
26-
publicbooleanfilter(Stringfield);
37+
publicbooleanaccept(Stringfield);
2738

2839
}

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

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
importjava.io.IOException;
1616
importjava.io.InputStream;
1717
importjava.io.PrintWriter;
18-
importjava.lang.reflect.Constructor;
1918
importjava.lang.reflect.Field;
20-
importjava.lang.reflect.InvocationTargetException;
2119
importjava.lang.reflect.Modifier;
2220
importjava.net.URLDecoder;
2321
importjava.util.Arrays;
@@ -102,48 +100,13 @@ protected long maxXSSRequestLatency() {
102100
* specified class name is invalid, null will be returned.
103101
*/
104102
protectedSimpleRPCRunnablegetRunnableByRequest(Stringrequest) {
105-
if (request ==null)returnnull;
106-
intlength =request.length();
107-
if (length <=7 || !request.startsWith("WLL"))returnnull;
108-
intindex =request.indexOf('#');
109-
if (index == -1)returnnull;
110-
StringclazzName =request.substring(6,index);
111-
if (!validateRunnable(clazzName))returnnull;
112-
returncreateRunnableInstance(clazzName);
113-
}
114-
115-
/**
116-
* Create SimpleRPCRunnable instance by given class name. May be inherited to
117-
* do more jobs before starting to deserialize request and running the main job.
118-
*
119-
* @param clazzName full class name of inherited SimpleRPCRunnable class
120-
* @return instance of given class name, null may be returned.
121-
*/
122-
protectedSimpleRPCRunnablecreateRunnableInstance(StringclazzName) {
123-
try {
124-
ClassrunnableClass =Class.forName(clazzName);
125-
if (runnableClass !=null) {
126-
// SimpleRPCRunnale should always has default constructor
127-
Constructorconstructor =runnableClass.getConstructor(newClass[0]);
128-
Objectobj =constructor.newInstance(newObject[0]);
129-
if (obj !=null &&objinstanceofSimpleRPCRunnable) {
130-
return (SimpleRPCRunnable)obj;
131-
}
103+
SimpleSerializableinstance =SimpleSerializable.parseInstance(request,newSimpleFilter() {
104+
publicbooleanaccept(StringclazzName) {
105+
returnvalidateRunnable(clazzName);
132106
}
133-
}catch (SecurityExceptione) {
134-
e.printStackTrace();
135-
}catch (IllegalArgumentExceptione) {
136-
e.printStackTrace();
137-
}catch (ClassNotFoundExceptione) {
138-
e.printStackTrace();
139-
}catch (NoSuchMethodExceptione) {
140-
e.printStackTrace();
141-
}catch (InstantiationExceptione) {
142-
e.printStackTrace();
143-
}catch (IllegalAccessExceptione) {
144-
e.printStackTrace();
145-
}catch (InvocationTargetExceptione) {
146-
e.printStackTrace();
107+
});
108+
if (instanceinstanceofSimpleRPCRunnable) {
109+
return (SimpleRPCRunnable)instance;
147110
}
148111
returnnull;
149112
}
@@ -264,7 +227,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
264227
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
265228
return;
266229
}
267-
resp.setContentType("text/plain");
230+
resp.setHeader("Pragma","no-cache");
231+
resp.setHeader("Cache-Control","no-cache");
232+
resp.setDateHeader("Expires",0);
233+
resp.setContentType("text/plain;charset=utf-8");
268234
//resp.setCharacterEncoding("utf-8");
269235
PrintWriterwriter =resp.getWriter();
270236
runnable.deserialize(request);
@@ -276,16 +242,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
276242
}
277243
runnable.ajaxRun();
278244
finalString[]diffs =compareDiffs(runnable,clonedRunnable);
279-
Stringserialize =runnable.serialize(newSimpleFieldFilter() {
245+
Stringserialize =runnable.serialize(newSimpleFilter() {
280246

281-
publicbooleanfilter(Stringfield) {
247+
publicbooleanaccept(Stringfield) {
282248
if (diffs ==null ||diffs.length ==0)returntrue;
283249
for (inti =0;i <diffs.length;i++) {
284250
if (diffs[i].equals(field)) {
285-
returnfalse;
251+
returntrue;
286252
}
287253
}
288-
returntrue;
254+
returnfalse;
289255
}
290256

291257
});
@@ -343,20 +309,24 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
343309
}
344310
runnable.ajaxRun();
345311
finalString[]diffs =compareDiffs(runnable,clonedRunnable);
346-
Stringserialize =runnable.serialize(newSimpleFieldFilter() {
312+
Stringserialize =runnable.serialize(newSimpleFilter() {
347313

348-
publicbooleanfilter(Stringfield) {
314+
publicbooleanaccept(Stringfield) {
349315
if (diffs ==null ||diffs.length ==0)returntrue;
350316
for (inti =0;i <diffs.length;i++) {
351317
if (diffs[i].equals(field)) {
352-
returnfalse;
318+
returntrue;
353319
}
354320
}
355-
returntrue;
321+
returnfalse;
356322
}
357323

358324
});
359325

326+
resp.setHeader("Pragma","no-cache");
327+
resp.setHeader("Cache-Control","no-cache");
328+
resp.setDateHeader("Expires",0);
329+
360330
if (isScriptReuest) {// cross site script response
361331
resp.setContentType("text/javascript");
362332
//resp.setCharacterEncoding("utf-8");
@@ -539,7 +509,6 @@ protected String[] compareDiffs(SimpleRPCRunnable runnable1, SimpleRPCRunnable r
539509
}catch (IllegalAccessExceptione) {
540510
//e.printStackTrace();
541511
}
542-
System.out.println(field1.getClass().getName());
543512
if (field1 ==null) {
544513
if (field2 !=null) {
545514
diffSet.add(name);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
*/
2222
publicclassSimpleRPCRequest {
2323

24-
publicstaticintMODE_AJAX =1;
25-
publicstaticintMODE_LOCAL_JAVA_THREAD =2;
24+
publicstaticfinalintMODE_AJAX =1;
25+
publicstaticfinalintMODE_LOCAL_JAVA_THREAD =2;
2626

27-
staticintrunningMode =MODE_LOCAL_JAVA_THREAD;
27+
privatestaticintrunningMode =MODE_LOCAL_JAVA_THREAD;
28+
29+
publicstaticintgetRequstMode() {
30+
returnrunningMode;
31+
}
2832

2933
publicstaticvoidswitchToAJAXMode() {
3034
runningMode =MODE_AJAX;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SimpleRPCSWTRequest extends SimpleRPCRequest {
2929
*/
3030
publicstaticvoidswtRequest(finalSimpleRPCRunnablerunnable) {
3131
runnable.ajaxIn();
32-
if (runningMode ==MODE_LOCAL_JAVA_THREAD) {
32+
if (getRequstMode() ==MODE_LOCAL_JAVA_THREAD) {
3333
newThread(newRunnable(){
3434
publicvoidrun() {
3535
try {
@@ -43,7 +43,7 @@ public void run() {
4343
runnable.ajaxFail();
4444
}
4545
});
46-
}
46+
}// else ?
4747
return;
4848
}
4949
Displaydisp =Display.getDefault();
@@ -53,7 +53,7 @@ public void run() {
5353
runnable.ajaxOut();
5454
}
5555
});
56-
}
56+
}// else ?
5757
}
5858
}).start();
5959
}else {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp