1 13 14 package org.ejbca.ui.web.pub; 15 16 import java.io.*; 17 18 import javax.servlet.ServletException ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.ejbca.ui.web.RequestHelper; 23 24 25 29 public class ServletDebug { 30 private final ByteArrayOutputStream buffer; 31 private final PrintStream printer; 32 private final HttpServletRequest request; 33 private final HttpServletResponse response; 34 35 public ServletDebug(HttpServletRequest request, HttpServletResponse response) { 36 buffer = new ByteArrayOutputStream(); 37 printer = new PrintStream(buffer); 38 this.request = request; 39 this.response = response; 40 } 41 42 public void printDebugInfo() throws IOException, ServletException { 43 request.setAttribute("ErrorMessage", new String (buffer.toByteArray())); 44 request.getRequestDispatcher("error.jsp").forward(request, response); 45 } 46 47 public void print(Object o) { 48 printer.println(o); 49 } 50 51 public void printMessage(String msg) { 52 print("<p>" + msg); 53 } 54 55 public void printInsertLineBreaks(byte[] bA) throws Exception { 56 BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bA))); 57 58 while (true) { 59 String line = br.readLine(); 60 61 if (line == null) { 62 break; 63 } 64 65 print(line.toString() + "<br>"); 66 } 67 } 68 69 public void takeCareOfException(Throwable t) { 70 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 71 t.printStackTrace(new PrintStream(baos)); 72 print("<h4>Exception:</h4>"); 73 74 try { 75 printInsertLineBreaks(baos.toByteArray()); 76 } catch (Exception e) { 77 e.printStackTrace(printer); 78 } 79 80 request.setAttribute("Exception", "true"); 81 } 82 83 public void ieCertFix(byte[] bA) throws Exception { 84 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 85 PrintStream tmpPrinter = new PrintStream(baos); 86 RequestHelper.ieCertFormat(bA, tmpPrinter); 87 printInsertLineBreaks(baos.toByteArray()); 88 } 89 } 90 | Popular Tags |