1 19 24 25 package org.netbeans.modules.exceptions; 26 import java.io.ByteArrayOutputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.io.PrintWriter ; 30 import java.io.Writer ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServlet ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 38 39 44 public class LoadingServlet extends HttpServlet { 45 private static int count = 0; private static int SIZE = 128*1024; 51 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 52 throws ServletException , IOException { 53 response.setContentType("text/html;charset=UTF-8"); 54 PrintWriter out = new PrintWriter (response.getWriter()); 55 out.println("<html>"); 56 out.println("<head>"); 57 out.println("<title>Exceptions Loading Servlet</title>"); 58 out.println("</head>"); 59 out.println("<body>"); 60 out.println("<h1>Exceptions Loading Servlet</h1>"); 61 out.println("Aktualni pocet zaslanych reportu je: <b>"+new Integer (count).toString()+"</b>"); 62 out.println("</body>"); 63 out.println("</html>"); 64 out.close(); 65 } 66 67 protected void doPut(HttpServletRequest request, HttpServletResponse response) 68 throws ServletException , IOException { 69 InputStream istream = request.getInputStream(); 70 ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream (SIZE); 71 int i; 72 int pocet = 0; 73 while ((i = istream.read()) != -1){ 74 byteArrayStream.write(i); 75 ++pocet; 76 } 77 new Thread (new DbInsertion(byteArrayStream.toByteArray())).start(); 78 Writer resp = response.getWriter(); 79 resp.write("Issue was successfully send to NetBeansQE"); 80 resp.close(); 81 Logger.getLogger(LoadingServlet.class.getName()).log(Level.INFO, 82 "Connection number: "+String.valueOf(++count)+"; "+ String.valueOf(pocet)+" of bytes was read"); 83 } 84 85 public static int getCount(){ 86 return count; 87 } 88 89 94 protected void doGet(HttpServletRequest request, HttpServletResponse response) 95 throws ServletException , IOException { 96 processRequest(request, response); 97 } 98 99 103 protected void doPost(HttpServletRequest request, HttpServletResponse response) 104 throws ServletException , IOException { 105 processRequest(request, response); 106 } 107 108 110 public String getServletInfo() { 111 return "This servlet servs for accepting NetBeans exception report"; 112 } 113 } 115 | Popular Tags |