15
15
import java .io .IOException ;
16
16
import java .io .InputStream ;
17
17
import java .io .PrintWriter ;
18
- import java .lang .reflect .Constructor ;
19
18
import java .lang .reflect .Field ;
20
- import java .lang .reflect .InvocationTargetException ;
21
19
import java .lang .reflect .Modifier ;
22
20
import java .net .URLDecoder ;
23
21
import java .util .Arrays ;
@@ -102,48 +100,13 @@ protected long maxXSSRequestLatency() {
102
100
* specified class name is invalid, null will be returned.
103
101
*/
104
102
protected SimpleRPCRunnable getRunnableByRequest (String request ) {
105
- if (request == null ) return null ;
106
- int length = request .length ();
107
- if (length <= 7 || !request .startsWith ("WLL" )) return null ;
108
- int index = request .indexOf ('#' );
109
- if (index == -1 ) return null ;
110
- String clazzName = request .substring (6 , index );
111
- if (!validateRunnable (clazzName )) return null ;
112
- return createRunnableInstance (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
- protected SimpleRPCRunnable createRunnableInstance (String clazzName ) {
123
- try {
124
- Class runnableClass = Class .forName (clazzName );
125
- if (runnableClass != null ) {
126
- // SimpleRPCRunnale should always has default constructor
127
- Constructor constructor = runnableClass .getConstructor (new Class [0 ]);
128
- Object obj = constructor .newInstance (new Object [0 ]);
129
- if (obj != null && obj instanceof SimpleRPCRunnable ) {
130
- return (SimpleRPCRunnable ) obj ;
131
- }
103
+ SimpleSerializable instance = SimpleSerializable .parseInstance (request , new SimpleFilter () {
104
+ public boolean accept (String clazzName ) {
105
+ return validateRunnable (clazzName );
132
106
}
133
- } catch (SecurityException e ) {
134
- e .printStackTrace ();
135
- } catch (IllegalArgumentException e ) {
136
- e .printStackTrace ();
137
- } catch (ClassNotFoundException e ) {
138
- e .printStackTrace ();
139
- } catch (NoSuchMethodException e ) {
140
- e .printStackTrace ();
141
- } catch (InstantiationException e ) {
142
- e .printStackTrace ();
143
- } catch (IllegalAccessException e ) {
144
- e .printStackTrace ();
145
- } catch (InvocationTargetException e ) {
146
- e .printStackTrace ();
107
+ });
108
+ if (instance instanceof SimpleRPCRunnable ) {
109
+ return (SimpleRPCRunnable ) instance ;
147
110
}
148
111
return null ;
149
112
}
@@ -264,7 +227,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
264
227
resp .sendError (HttpServletResponse .SC_NOT_FOUND );
265
228
return ;
266
229
}
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" );
268
234
//resp.setCharacterEncoding("utf-8");
269
235
PrintWriter writer = resp .getWriter ();
270
236
runnable .deserialize (request );
@@ -276,16 +242,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
276
242
}
277
243
runnable .ajaxRun ();
278
244
final String [] diffs = compareDiffs (runnable , clonedRunnable );
279
- String serialize = runnable .serialize (new SimpleFieldFilter () {
245
+ String serialize = runnable .serialize (new SimpleFilter () {
280
246
281
- public boolean filter (String field ) {
247
+ public boolean accept (String field ) {
282
248
if (diffs == null || diffs .length == 0 ) return true ;
283
249
for (int i = 0 ; i < diffs .length ; i ++) {
284
250
if (diffs [i ].equals (field )) {
285
- return false ;
251
+ return true ;
286
252
}
287
253
}
288
- return true ;
254
+ return false ;
289
255
}
290
256
291
257
});
@@ -343,20 +309,24 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
343
309
}
344
310
runnable .ajaxRun ();
345
311
final String [] diffs = compareDiffs (runnable , clonedRunnable );
346
- String serialize = runnable .serialize (new SimpleFieldFilter () {
312
+ String serialize = runnable .serialize (new SimpleFilter () {
347
313
348
- public boolean filter (String field ) {
314
+ public boolean accept (String field ) {
349
315
if (diffs == null || diffs .length == 0 ) return true ;
350
316
for (int i = 0 ; i < diffs .length ; i ++) {
351
317
if (diffs [i ].equals (field )) {
352
- return false ;
318
+ return true ;
353
319
}
354
320
}
355
- return true ;
321
+ return false ;
356
322
}
357
323
358
324
});
359
325
326
+ resp .setHeader ("Pragma" , "no-cache" );
327
+ resp .setHeader ("Cache-Control" , "no-cache" );
328
+ resp .setDateHeader ("Expires" , 0 );
329
+
360
330
if (isScriptReuest ) { // cross site script response
361
331
resp .setContentType ("text/javascript" );
362
332
//resp.setCharacterEncoding("utf-8");
@@ -539,7 +509,6 @@ protected String[] compareDiffs(SimpleRPCRunnable runnable1, SimpleRPCRunnable r
539
509
} catch (IllegalAccessException e ) {
540
510
//e.printStackTrace();
541
511
}
542
- System .out .println (field1 .getClass ().getName ());
543
512
if (field1 == null ) {
544
513
if (field2 != null ) {
545
514
diffSet .add (name );
0 commit comments