1515import java .io .IOException ;
1616import java .io .InputStream ;
1717import java .io .PrintWriter ;
18- import java .lang .reflect .Constructor ;
1918import java .lang .reflect .Field ;
20- import java .lang .reflect .InvocationTargetException ;
2119import java .lang .reflect .Modifier ;
2220import java .net .URLDecoder ;
2321import java .util .Arrays ;
@@ -102,48 +100,13 @@ protected long maxXSSRequestLatency() {
102100 * specified class name is invalid, null will be returned.
103101 */
104102 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 );
132106 }
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 ;
147110 }
148111 return null ;
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 PrintWriter writer = resp .getWriter ();
270236 runnable .deserialize (request );
@@ -276,16 +242,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
276242 }
277243 runnable .ajaxRun ();
278244 final String [] diffs = compareDiffs (runnable , clonedRunnable );
279- String serialize = runnable .serialize (new SimpleFieldFilter () {
245+ String serialize = runnable .serialize (new SimpleFilter () {
280246
281- public boolean filter (String field ) {
247+ public boolean accept (String field ) {
282248 if (diffs == null || diffs .length == 0 ) return true ;
283249 for (int i = 0 ; i < diffs .length ; i ++) {
284250 if (diffs [i ].equals (field )) {
285- return false ;
251+ return true ;
286252 }
287253 }
288- return true ;
254+ return false ;
289255 }
290256
291257 });
@@ -343,20 +309,24 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
343309 }
344310 runnable .ajaxRun ();
345311 final String [] diffs = compareDiffs (runnable , clonedRunnable );
346- String serialize = runnable .serialize (new SimpleFieldFilter () {
312+ String serialize = runnable .serialize (new SimpleFilter () {
347313
348- public boolean filter (String field ) {
314+ public boolean accept (String field ) {
349315 if (diffs == null || diffs .length == 0 ) return true ;
350316 for (int i = 0 ; i < diffs .length ; i ++) {
351317 if (diffs [i ].equals (field )) {
352- return false ;
318+ return true ;
353319 }
354320 }
355- return true ;
321+ return false ;
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 (IllegalAccessException e ) {
540510 //e.printStackTrace();
541511 }
542- System .out .println (field1 .getClass ().getName ());
543512 if (field1 == null ) {
544513 if (field2 != null ) {
545514 diffSet .add (name );
0 commit comments