KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > LoadingServlet


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * NewServlet.java
21  *
22  * Created on November 6, 2006, 4:55 PM
23  */

24
25 package org.netbeans.modules.exceptions;
26 import java.io.ByteArrayOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import java.io.Writer JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServlet JavaDoc;
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37
38
39 /**
40  *
41  * @author jindra
42  * @version
43  */

44 public class LoadingServlet extends HttpServlet JavaDoc {
45     private static int count = 0;// number of accesses
46
private static int SIZE = 128*1024;//128kB
47
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
48      * @param request servlet request
49      * @param response servlet response
50      */

51     protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
52     throws ServletException JavaDoc, IOException JavaDoc {
53         response.setContentType("text/html;charset=UTF-8");
54         PrintWriter JavaDoc out = new PrintWriter JavaDoc(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 JavaDoc(count).toString()+"</b>");
62         out.println("</body>");
63         out.println("</html>");
64         out.close();
65     }
66     
67     protected void doPut(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
68     throws ServletException JavaDoc, IOException JavaDoc {
69         InputStream JavaDoc istream = request.getInputStream();
70         ByteArrayOutputStream JavaDoc byteArrayStream = new ByteArrayOutputStream JavaDoc(SIZE);
71         int i;
72         int pocet = 0;
73         while ((i = istream.read()) != -1){
74             byteArrayStream.write(i);
75             ++pocet;
76         }
77         new Thread JavaDoc(new DbInsertion(byteArrayStream.toByteArray())).start();
78         Writer JavaDoc 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     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
90
/** Handles the HTTP <code>GET</code> method.
91      * @param request servlet request
92      * @param response servlet response
93      */

94     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
95     throws ServletException JavaDoc, IOException JavaDoc {
96         processRequest(request, response);
97     }
98     
99     /** Handles the HTTP <code>POST</code> method.
100      * @param request servlet request
101      * @param response servlet response
102      */

103     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
104     throws ServletException JavaDoc, IOException JavaDoc {
105         processRequest(request, response);
106     }
107     
108     /** Returns a short description of the servlet.
109      */

110     public String JavaDoc getServletInfo() {
111         return "This servlet servs for accepting NetBeans exception report";
112     }
113     // </editor-fold>
114
}
115
Popular Tags