1
2
3
4
5
6
7
8
9
10
11
12
13
14 package com.acme;
15 import java.io.BufferedWriter;
16 import java.io.IOException;
17 import java.io.OutputStream;
18 import java.io.OutputStreamWriter;
19 import java.io.PrintWriter;
20 import java.io.Reader;
21 import java.lang.reflect.Array;
22 import java.lang.reflect.Field;
23 import java.util.Enumeration;
24 import java.util.Locale;
25
26 import javax.servlet.ServletConfig;
27 import javax.servlet.ServletException;
28 import javax.servlet.ServletRequest;
29 import javax.servlet.ServletRequestWrapper;
30 import javax.servlet.ServletResponse;
31 import javax.servlet.ServletResponseWrapper;
32 import javax.servlet.UnavailableException;
33 import javax.servlet.http.Cookie;
34 import javax.servlet.http.HttpServlet;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletRequestWrapper;
37 import javax.servlet.http.HttpServletResponse;
38 import javax.servlet.http.HttpServletResponseWrapper;
39
40 import org.eclipse.jetty.continuation.Continuation;
41 import org.eclipse.jetty.continuation.ContinuationSupport;
42 import org.eclipse.jetty.http.HttpHeaders;
43 import org.eclipse.jetty.util.StringUtil;
44
45
46
47
48
49
50
51 public class Dump extends HttpServlet
52 {
53 static boolean fixed;
54
55 public void init(ServletConfig config) throws ServletException
56 {
57 super.init(config);
58
59 if (config.getInitParameter("unavailable")!=null && !fixed)
60 {
61
62 fixed=true;
63 throw new UnavailableException("Unavailable test",Integer.parseInt(config.getInitParameter("unavailable")));
64 }
65 }
66
67
68 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
69 {
70 doGet(request, response);
71 }
72
73
74 public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
75 {
76 if(request.getPathInfo()!=null && request.getPathInfo().toLowerCase().indexOf("script")!=-1)
77 {
78 response.sendRedirect(getServletContext().getContextPath() + "/dump/info");
79 return;
80 }
81
82 request.setCharacterEncoding("UTF-8");
83
84 if (request.getParameter("empty")!=null)
85 {
86 response.setStatus(200);
87 response.flushBuffer();
88 return;
89 }
90
91 if (request.getParameter("sleep")!=null)
92 {
93 try
94 {
95 long s = Long.parseLong(request.getParameter("sleep"));
96 if (request.getHeader(HttpHeaders.EXPECT)!=null &&request.getHeader(HttpHeaders.EXPECT).indexOf("102")>=0)
97 {
98 Thread.sleep(s/2);
99 response.sendError(102);
100 Thread.sleep(s/2);
101 }
102 else
103 Thread.sleep(s);
104 }
105 catch (InterruptedException e)
106 {
107 return;
108 }
109 catch (Exception e)
110 {
111 throw new ServletException(e);
112 }
113 }
114
115 if (request.getAttribute("RESUME")==null && request.getParameter("resume")!=null)
116 {
117 request.setAttribute("RESUME",Boolean.TRUE);
118
119 final long resume=Long.parseLong(request.getParameter("resume"));
120 new Thread(new Runnable()
121 {
122 public void run()
123 {
124 try
125 {
126 Thread.sleep(resume);
127 }
128 catch (InterruptedException e)
129 {
130 e.printStackTrace();
131 }
132 Continuation continuation = ContinuationSupport.getContinuation(request,response);
133 continuation.resume();
134 }
135
136 }).start();
137 }
138
139 if (request.getParameter("suspend")!=null)
140 {
141 try
142 {
143 Continuation continuation = ContinuationSupport.getContinuation(request,response);
144 continuation.setTimeout(Long.parseLong(request.getParameter("suspend")));
145 continuation.suspend();
146 }
147 catch(Exception e)
148 {
149 throw new ServletException(e);
150 }
151 }
152
153 if (request.getParameter("complete")!=null)
154 {
155 final long complete=Long.parseLong(request.getParameter("complete"));
156 new Thread(new Runnable()
157 {
158 public void run()
159 {
160 try
161 {
162 Thread.sleep(complete);
163 }
164 catch (InterruptedException e)
165 {
166 e.printStackTrace();
167 }
168 try
169 {
170 response.setContentType("text/html");
171 response.getOutputStream().println("<h1>COMPLETED</h1>");
172 Continuation continuation = ContinuationSupport.getContinuation(request,response);
173 continuation.complete();
174 }
175 catch (IOException e)
176 {
177 e.printStackTrace();
178 }
179 }
180
181 }).start();
182 }
183
184
185 request.setAttribute("Dump", this);
186 getServletContext().setAttribute("Dump",this);
187
188
189
190 String length= request.getParameter("length");
191 if (length != null && length.length() > 0)
192 {
193 response.setContentLength(Integer.parseInt(length));
194 }
195
196
197 String data= request.getParameter("data");
198 String block= request.getParameter("block");
199 String dribble= request.getParameter("dribble");
200 boolean flush= request.getParameter("flush")!=null?Boolean.parseBoolean(request.getParameter("flush")):false;
201 if (data != null && data.length() > 0)
202 {
203 int d=Integer.parseInt(data);
204 int b=(block!=null&&block.length()>0)?Integer.parseInt(block):50;
205 byte[] buf=new byte[b];
206 for (int i=0;i<b;i++)
207 {
208
209 buf[i]=(byte)('0'+(i%10));
210 if (i%10==9)
211 buf[i]=(byte)'\n';
212 }
213 buf[0]='o';
214 OutputStream out=response.getOutputStream();
215 response.setContentType("text/plain");
216 while (d > 0)
217 {
218 if (b==1)
219 {
220 out.write(d%80==0?'\n':'.');
221 d--;
222 }
223 else if (d>=b)
224 {
225 out.write(buf);
226 d=d-b;
227 }
228 else
229 {
230 out.write(buf,0,d);
231 d=0;
232 }
233
234 if (dribble!=null)
235 {
236 out.flush();
237 try
238 {
239 Thread.sleep(Long.parseLong(dribble));
240 }
241 catch (Exception e)
242 {
243 e.printStackTrace();
244 break;
245 }
246 }
247
248 }
249
250 if (flush)
251 out.flush();
252
253 return;
254 }
255
256
257
258 String info= request.getPathInfo();
259 if (info != null && info.endsWith("Exception"))
260 {
261 try
262 {
263 throw (Throwable) Thread.currentThread().getContextClassLoader().loadClass(info.substring(1)).newInstance();
264 }
265 catch (Throwable th)
266 {
267 throw new ServletException(th);
268 }
269 }
270
271
272 String reset= request.getParameter("reset");
273 if (reset != null && reset.length() > 0)
274 {
275 response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
276 response.setHeader("SHOULD_NOT","BE SEEN");
277 response.reset();
278 }
279
280
281
282 String redirect= request.getParameter("redirect");
283 if (redirect != null && redirect.length() > 0)
284 {
285 response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
286 response.sendRedirect(redirect);
287 try
288 {
289 response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
290 }
291 catch(IOException e)
292 {
293
294 }
295 return;
296 }
297
298
299 String error= request.getParameter("error");
300 if (error != null && error.length() > 0 && request.getAttribute("javax.servlet.error.status_code")==null)
301 {
302 response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
303 response.sendError(Integer.parseInt(error));
304 try
305 {
306 response.getOutputStream().println("THIS SHOULD NOT BE SEEN!");
307 }
308 catch(IllegalStateException e)
309 {
310 try
311 {
312 response.getWriter().println("NOR THIS!!");
313 }
314 catch(IOException e2){}
315 }
316 catch(IOException e){}
317 return;
318 }
319
320
321 String buffer= request.getParameter("buffer");
322 if (buffer != null && buffer.length() > 0)
323 response.setBufferSize(Integer.parseInt(buffer));
324
325 String charset= request.getParameter("charset");
326 if (charset==null)
327 charset="UTF-8";
328 response.setCharacterEncoding(charset);
329 response.setContentType("text/html");
330
331 if (info != null && info.indexOf("Locale/") >= 0)
332 {
333 try
334 {
335 String locale_name= info.substring(info.indexOf("Locale/") + 7);
336 Field f= java.util.Locale.class.getField(locale_name);
337 response.setLocale((Locale)f.get(null));
338 }
339 catch (Exception e)
340 {
341 e.printStackTrace();
342 response.setLocale(Locale.getDefault());
343 }
344 }
345
346 String cn= request.getParameter("cookie");
347 String cv=request.getParameter("cookiev");
348 if (cn!=null && cv!=null)
349 {
350 Cookie cookie= new Cookie(cn, cv);
351 if (request.getParameter("version")!=null)
352 cookie.setVersion(Integer.parseInt(request.getParameter("version")));
353 cookie.setComment("Cookie from dump servlet");
354 response.addCookie(cookie);
355 }
356
357 String pi= request.getPathInfo();
358 if (pi != null && pi.startsWith("/ex"))
359 {
360 OutputStream out= response.getOutputStream();
361 out.write("</H1>This text should be reset</H1>".getBytes());
362 if ("/ex0".equals(pi))
363 throw new ServletException("test ex0", new Throwable());
364 else if ("/ex1".equals(pi))
365 throw new IOException("test ex1");
366 else if ("/ex2".equals(pi))
367 throw new UnavailableException("test ex2");
368 else if (pi.startsWith("/ex3/"))
369 throw new UnavailableException("test ex3",Integer.parseInt(pi.substring(5)));
370 throw new RuntimeException("test");
371 }
372
373 if ("true".equals(request.getParameter("close")))
374 response.setHeader("Connection","close");
375
376 String buffered= request.getParameter("buffered");
377
378 PrintWriter pout=null;
379
380 try
381 {
382 pout =response.getWriter();
383 }
384 catch(IllegalStateException e)
385 {
386 pout=new PrintWriter(new OutputStreamWriter(response.getOutputStream(),charset));
387 }
388 if (buffered!=null)
389 pout = new PrintWriter(new BufferedWriter(pout,Integer.parseInt(buffered)));
390
391 try
392 {
393 pout.write("<html>\n<body>\n");
394 pout.write("<h1>Dump Servlet</h1>\n");
395 pout.write("<table width=\"95%\">");
396 pout.write("<tr>\n");
397 pout.write("<th align=\"right\">getMethod: </th>");
398 pout.write("<td>" + notag(request.getMethod())+"</td>");
399 pout.write("</tr><tr>\n");
400 pout.write("<th align=\"right\">getContentLength: </th>");
401 pout.write("<td>"+Integer.toString(request.getContentLength())+"</td>");
402 pout.write("</tr><tr>\n");
403 pout.write("<th align=\"right\">getContentType: </th>");
404 pout.write("<td>"+notag(request.getContentType())+"</td>");
405 pout.write("</tr><tr>\n");
406 pout.write("<th align=\"right\">getRequestURI: </th>");
407 pout.write("<td>"+notag(request.getRequestURI())+"</td>");
408 pout.write("</tr><tr>\n");
409 pout.write("<th align=\"right\">getRequestURL: </th>");
410 pout.write("<td>"+notag(request.getRequestURL().toString())+"</td>");
411 pout.write("</tr><tr>\n");
412 pout.write("<th align=\"right\">getContextPath: </th>");
413 pout.write("<td>"+request.getContextPath()+"</td>");
414 pout.write("</tr><tr>\n");
415 pout.write("<th align=\"right\">getServletPath: </th>");
416 pout.write("<td>"+notag(request.getServletPath())+"</td>");
417 pout.write("</tr><tr>\n");
418 pout.write("<th align=\"right\">getPathInfo: </th>");
419 pout.write("<td>"+notag(request.getPathInfo())+"</td>");
420 pout.write("</tr><tr>\n");
421 pout.write("<th align=\"right\">getPathTranslated: </th>");
422 pout.write("<td>"+notag(request.getPathTranslated())+"</td>");
423 pout.write("</tr><tr>\n");
424 pout.write("<th align=\"right\">getQueryString: </th>");
425 pout.write("<td>"+notag(request.getQueryString())+"</td>");
426 pout.write("</tr><tr>\n");
427
428 pout.write("<th align=\"right\">getProtocol: </th>");
429 pout.write("<td>"+request.getProtocol()+"</td>");
430 pout.write("</tr><tr>\n");
431 pout.write("<th align=\"right\">getScheme: </th>");
432 pout.write("<td>"+request.getScheme()+"</td>");
433 pout.write("</tr><tr>\n");
434 pout.write("<th align=\"right\">getServerName: </th>");
435 pout.write("<td>"+notag(request.getServerName())+"</td>");
436 pout.write("</tr><tr>\n");
437 pout.write("<th align=\"right\">getServerPort: </th>");
438 pout.write("<td>"+Integer.toString(request.getServerPort())+"</td>");
439 pout.write("</tr><tr>\n");
440 pout.write("<th align=\"right\">getLocalName: </th>");
441 pout.write("<td>"+request.getLocalName()+"</td>");
442 pout.write("</tr><tr>\n");
443 pout.write("<th align=\"right\">getLocalAddr: </th>");
444 pout.write("<td>"+request.getLocalAddr()+"</td>");
445 pout.write("</tr><tr>\n");
446 pout.write("<th align=\"right\">getLocalPort: </th>");
447 pout.write("<td>"+Integer.toString(request.getLocalPort())+"</td>");
448 pout.write("</tr><tr>\n");
449 pout.write("<th align=\"right\">getRemoteUser: </th>");
450 pout.write("<td>"+request.getRemoteUser()+"</td>");
451 pout.write("</tr><tr>\n");
452 pout.write("<th align=\"right\">getRemoteAddr: </th>");
453 pout.write("<td>"+request.getRemoteAddr()+"</td>");
454 pout.write("</tr><tr>\n");
455 pout.write("<th align=\"right\">getRemoteHost: </th>");
456 pout.write("<td>"+request.getRemoteHost()+"</td>");
457 pout.write("</tr><tr>\n");
458 pout.write("<th align=\"right\">getRemotePort: </th>");
459 pout.write("<td>"+request.getRemotePort()+"</td>");
460 pout.write("</tr><tr>\n");
461 pout.write("<th align=\"right\">getRequestedSessionId: </th>");
462 pout.write("<td>"+request.getRequestedSessionId()+"</td>");
463 pout.write("</tr><tr>\n");
464 pout.write("<th align=\"right\">isSecure(): </th>");
465 pout.write("<td>"+request.isSecure()+"</td>");
466
467 pout.write("</tr><tr>\n");
468 pout.write("<th align=\"right\">isUserInRole(admin): </th>");
469 pout.write("<td>"+request.isUserInRole("admin")+"</td>");
470
471 pout.write("</tr><tr>\n");
472 pout.write("<th align=\"right\">getLocale: </th>");
473 pout.write("<td>"+request.getLocale()+"</td>");
474
475 Enumeration locales= request.getLocales();
476 while (locales.hasMoreElements())
477 {
478 pout.write("</tr><tr>\n");
479 pout.write("<th align=\"right\">getLocales: </th>");
480 pout.write("<td>"+locales.nextElement()+"</td>");
481 }
482 pout.write("</tr><tr>\n");
483
484 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Other HTTP Headers:</big></th>");
485 Enumeration h= request.getHeaderNames();
486 String name;
487 while (h.hasMoreElements())
488 {
489 name= (String)h.nextElement();
490
491 Enumeration h2= request.getHeaders(name);
492 while (h2.hasMoreElements())
493 {
494 String hv= (String)h2.nextElement();
495 pout.write("</tr><tr>\n");
496 pout.write("<th align=\"right\">"+notag(name)+": </th>");
497 pout.write("<td>"+notag(hv)+"</td>");
498 }
499 }
500
501 pout.write("</tr><tr>\n");
502 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Request Parameters:</big></th>");
503 h= request.getParameterNames();
504 while (h.hasMoreElements())
505 {
506 name= (String)h.nextElement();
507 pout.write("</tr><tr>\n");
508 pout.write("<th align=\"right\">"+notag(name)+": </th>");
509 pout.write("<td>"+notag(request.getParameter(name))+"</td>");
510 String[] values= request.getParameterValues(name);
511 if (values == null)
512 {
513 pout.write("</tr><tr>\n");
514 pout.write("<th align=\"right\">"+notag(name)+" Values: </th>");
515 pout.write("<td>"+"NULL!"+"</td>");
516 }
517 else if (values.length > 1)
518 {
519 for (int i= 0; i < values.length; i++)
520 {
521 pout.write("</tr><tr>\n");
522 pout.write("<th align=\"right\">"+notag(name)+"["+i+"]: </th>");
523 pout.write("<td>"+notag(values[i])+"</td>");
524 }
525 }
526 }
527
528 pout.write("</tr><tr>\n");
529 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Cookies:</big></th>");
530 Cookie[] cookies = request.getCookies();
531 for (int i=0; cookies!=null && i<cookies.length;i++)
532 {
533 Cookie cookie = cookies[i];
534
535 pout.write("</tr><tr>\n");
536 pout.write("<th align=\"right\">"+notag(cookie.getName())+": </th>");
537 pout.write("<td>"+notag(cookie.getValue())+"</td>");
538 }
539
540 String content_type=request.getContentType();
541 if (content_type!=null &&
542 !content_type.startsWith("application/x-www-form-urlencoded") &&
543 !content_type.startsWith("multipart/form-data"))
544 {
545 pout.write("</tr><tr>\n");
546 pout.write("<th align=\"left\" valign=\"top\" colspan=\"2\"><big><br/>Content:</big></th>");
547 pout.write("</tr><tr>\n");
548 pout.write("<td><pre>");
549 char[] content= new char[4096];
550 int len;
551 try{
552 Reader in=request.getReader();
553
554 while((len=in.read(content))>=0)
555 pout.write(notag(new String(content,0,len)));
556 }
557 catch(IOException e)
558 {
559 pout.write(e.toString());
560 }
561
562 pout.write("</pre></td>");
563 }
564
565
566 pout.write("</tr><tr>\n");
567 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Request Attributes:</big></th>");
568 Enumeration a= request.getAttributeNames();
569 while (a.hasMoreElements())
570 {
571 name= (String)a.nextElement();
572 pout.write("</tr><tr>\n");
573 pout.write("<th align=\"right\" valign=\"top\">"+name.replace("."," .")+": </th>");
574 pout.write("<td>"+"<pre>" + toString(request.getAttribute(name)) + "</pre>"+"</td>");
575 }
576
577
578 pout.write("</tr><tr>\n");
579 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Servlet InitParameters:</big></th>");
580 a= getInitParameterNames();
581 while (a.hasMoreElements())
582 {
583 name= (String)a.nextElement();
584 pout.write("</tr><tr>\n");
585 pout.write("<th align=\"right\">"+name+": </th>");
586 pout.write("<td>"+ toString(getInitParameter(name)) +"</td>");
587 }
588
589 pout.write("</tr><tr>\n");
590 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Context InitParameters:</big></th>");
591 a= getServletContext().getInitParameterNames();
592 while (a.hasMoreElements())
593 {
594 name= (String)a.nextElement();
595 pout.write("</tr><tr>\n");
596 pout.write("<th align=\"right\" valign=\"top\">"+name.replace("."," .")+": </th>");
597 pout.write("<td>"+ toString(getServletContext().getInitParameter(name)) + "</td>");
598 }
599
600 pout.write("</tr><tr>\n");
601 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Context Attributes:</big></th>");
602 a= getServletContext().getAttributeNames();
603 while (a.hasMoreElements())
604 {
605 name= (String)a.nextElement();
606 pout.write("</tr><tr>\n");
607 pout.write("<th align=\"right\" valign=\"top\">"+name.replace("."," .")+": </th>");
608 pout.write("<td>"+"<pre>" + toString(getServletContext().getAttribute(name)) + "</pre>"+"</td>");
609 }
610
611
612 String res= request.getParameter("resource");
613 if (res != null && res.length() > 0)
614 {
615 pout.write("</tr><tr>\n");
616 pout.write("<th align=\"left\" colspan=\"2\"><big><br/>Get Resource: \""+res+"\"</big></th>");
617
618 pout.write("</tr><tr>\n");
619 pout.write("<th align=\"right\">this.getClass().getResource(...): </th>");
620 pout.write("<td>"+this.getClass().getResource(res)+"</td>");
621
622 pout.write("</tr><tr>\n");
623 pout.write("<th align=\"right\">this.getClass().getClassLoader().getResource(...): </th>");
624 pout.write("<td>"+this.getClass().getClassLoader().getResource(res)+"</td>");
625
626 pout.write("</tr><tr>\n");
627 pout.write("<th align=\"right\">Thread.currentThread().getContextClassLoader().getResource(...): </th>");
628 pout.write("<td>"+Thread.currentThread().getContextClassLoader().getResource(res)+"</td>");
629
630 pout.write("</tr><tr>\n");
631 pout.write("<th align=\"right\">getServletContext().getResource(...): </th>");
632 try{pout.write("<td>"+getServletContext().getResource(res)+"</td>");}
633 catch(Exception e) {pout.write("<td>"+"" +e+"</td>");}
634 }
635
636 pout.write("</tr></table>\n");
637
638
639 pout.write("<h2>Request Wrappers</h2>\n");
640 ServletRequest rw=request;
641 int w=0;
642 while (rw !=null)
643 {
644 pout.write((w++)+": "+rw.getClass().getName()+"<br/>");
645 if (rw instanceof HttpServletRequestWrapper)
646 rw=((HttpServletRequestWrapper)rw).getRequest();
647 else if (rw instanceof ServletRequestWrapper)
648 rw=((ServletRequestWrapper)rw).getRequest();
649 else
650 rw=null;
651 }
652
653
654 pout.write("<h2>Response Wrappers</h2>\n");
655 ServletResponse rsw=response;
656 w=0;
657 while (rsw !=null)
658 {
659 pout.write((w++)+": "+rsw.getClass().getName()+"<br/>");
660 if (rsw instanceof HttpServletResponseWrapper)
661 rsw=((HttpServletResponseWrapper)rsw).getResponse();
662 else if (rsw instanceof ServletResponseWrapper)
663 rsw=((ServletResponseWrapper)rsw).getResponse();
664 else
665 rsw=null;
666 }
667
668 pout.write("<br/>");
669 pout.write("<h2>International Characters (UTF-8)</h2>");
670 pout.write("LATIN LETTER SMALL CAPITAL AE<br/>\n");
671 pout.write("Directly uni encoded(\\u1d01): \u1d01<br/>");
672 pout.write("HTML reference (&AElig;): Æ<br/>");
673 pout.write("Decimal (&#7425;): ᴁ<br/>");
674 pout.write("Javascript unicode (\\u1d01) : <script language='javascript'>document.write(\"\u1d01\");</script><br/>");
675 pout.write("<br/>");
676 pout.write("<h2>Form to generate GET content</h2>");
677 pout.write("<form method=\"GET\" action=\""+response.encodeURL(getURI(request))+"\">");
678 pout.write("TextField: <input type=\"text\" name=\"TextField\" value=\"value\"/><br/>\n");
679 pout.write("<input type=\"submit\" name=\"Action\" value=\"Submit\">");
680 pout.write("</form>");
681
682 pout.write("<br/>");
683
684 pout.write("<h2>Form to generate POST content</h2>");
685 pout.write("<form method=\"POST\" accept-charset=\"utf-8\" action=\""+response.encodeURL(getURI(request))+"\">");
686 pout.write("TextField: <input type=\"text\" name=\"TextField\" value=\"value\"/><br/>\n");
687 pout.write("Select: <select multiple name=\"Select\">\n");
688 pout.write("<option>ValueA</option>");
689 pout.write("<option>ValueB1,ValueB2</option>");
690 pout.write("<option>ValueC</option>");
691 pout.write("</select><br/>");
692 pout.write("<input type=\"submit\" name=\"Action\" value=\"Submit\"><br/>");
693 pout.write("</form>");
694 pout.write("<br/>");
695
696 pout.write("<h2>Form to generate UPLOAD content</h2>");
697 pout.write("<form method=\"POST\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" action=\""+response.encodeURL(getURI(request))+"\">");
698 pout.write("TextField: <input type=\"text\" name=\"TextField\" value=\"comment\"/><br/>\n");
699 pout.write("File 1: <input type=\"file\" name=\"file1\" /><br/>\n");
700 pout.write("File 2: <input type=\"file\" name=\"file2\" /><br/>\n");
701 pout.write("<input type=\"submit\" name=\"Action\" value=\"Submit\"><br/>");
702 pout.write("</form>");
703
704 pout.write("<h2>Form to set Cookie</h2>");
705 pout.write("<form method=\"POST\" action=\""+response.encodeURL(getURI(request))+"\">");
706 pout.write("cookie: <input type=\"text\" name=\"cookie\" /><br/>\n");
707 pout.write("value: <input type=\"text\" name=\"cookiev\" /><br/>\n");
708 pout.write("<input type=\"submit\" name=\"Action\" value=\"setCookie\">");
709 pout.write("</form>\n");
710
711 pout.write("<h2>Form to get Resource</h2>");
712 pout.write("<form method=\"POST\" action=\""+response.encodeURL(getURI(request))+"\">");
713 pout.write("resource: <input type=\"text\" name=\"resource\" /><br/>\n");
714 pout.write("<input type=\"submit\" name=\"Action\" value=\"getResource\">");
715 pout.write("</form>\n");
716 }
717 catch (Exception e)
718 {
719 getServletContext().log("dump", e);
720 }
721
722 String lines= request.getParameter("lines");
723 if (lines!=null)
724 {
725 char[] line = "<span>A line of characters. Blah blah blah blah. blooble blooble</span></br>\n".toCharArray();
726 for (int l=Integer.parseInt(lines);l-->0;)
727 {
728 pout.write("<span>"+l+" </span>");
729 pout.write(line);
730 }
731 }
732
733 pout.write("</body>\n</html>\n");
734
735 pout.close();
736
737 if (pi != null)
738 {
739 if ("/ex4".equals(pi))
740 throw new ServletException("test ex4", new Throwable());
741 if ("/ex5".equals(pi))
742 throw new IOException("test ex5");
743 if ("/ex6".equals(pi))
744 throw new UnavailableException("test ex6");
745 }
746
747
748 }
749
750
751 public String getServletInfo()
752 {
753 return "Dump Servlet";
754 }
755
756
757 public synchronized void destroy()
758 {
759 }
760
761
762 private String getURI(HttpServletRequest request)
763 {
764 String uri= (String)request.getAttribute("javax.servlet.forward.request_uri");
765 if (uri == null)
766 uri= request.getRequestURI();
767 return uri;
768 }
769
770
771 private static String toString(Object o)
772 {
773 if (o == null)
774 return null;
775
776 try
777 {
778 if (o.getClass().isArray())
779 {
780 StringBuffer sb = new StringBuffer();
781 if (!o.getClass().getComponentType().isPrimitive())
782 {
783 Object[] array= (Object[])o;
784 for (int i= 0; i < array.length; i++)
785 {
786 if (i > 0)
787 sb.append("\n");
788 sb.append(array.getClass().getComponentType().getName());
789 sb.append("[");
790 sb.append(i);
791 sb.append("]=");
792 sb.append(toString(array[i]));
793 }
794 return sb.toString();
795 }
796 else
797 {
798 int length = Array.getLength(o);
799 for (int i=0;i<length;i++)
800 {
801 if (i > 0)
802 sb.append("\n");
803 sb.append(o.getClass().getComponentType().getName());
804 sb.append("[");
805 sb.append(i);
806 sb.append("]=");
807 sb.append(toString(Array.get(o, i)));
808 }
809 return sb.toString();
810 }
811 }
812 else
813 return o.toString();
814 }
815 catch (Exception e)
816 {
817 return e.toString();
818 }
819 }
820
821 private String notag(String s)
822 {
823 if (s==null)
824 return "null";
825 s=StringUtil.replace(s,"&","&");
826 s=StringUtil.replace(s,"<","<");
827 s=StringUtil.replace(s,">",">");
828 return s;
829 }
830 }