KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > examples > logging > TestingServlet


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  * TestingServlet.java
21  *
22  * Created on June 3, 2005, 5:57 PM
23  */

24
25 package org.netbeans.test.examples.logging;
26
27 import java.io.IOException JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29 import javax.servlet.ServletException JavaDoc;
30 import javax.servlet.http.HttpServlet JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 /**
35  *
36  * @author jungi
37  * @version
38  */

39 public class TestingServlet extends HttpServlet JavaDoc {
40
41     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
42      * @param request servlet request
43      * @param response servlet response
44      */

45     protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
46     throws ServletException JavaDoc, IOException JavaDoc {
47         response.setContentType("text/html;charset=UTF-8");
48         PrintWriter JavaDoc out = response.getWriter();
49         out.println("<html>");
50         out.println("<head>");
51         out.println("<title>Servlet TestingServlet</title>");
52         out.println("</head>");
53         out.println("<body>");
54         out.println("<h1>Servlet TestingServlet at " + request.getContextPath() + "</h1>");
55         boolean b = false;
56         Exception JavaDoc e = null;
57         try {
58             getBGTransPort().BGTranslate("Hello");
59             b = true;
60         } catch(java.rmi.RemoteException JavaDoc ex) {
61             // TODO handle remote exception
62
e = ex;
63         }
64         if (b) {
65             out.println("<strong>Call was successful.</strong>");
66         } else {
67             out.println("<strong>Call was not successful!!!</strong>");
68             out.println("<br/><br/>");
69             e.printStackTrace(out);
70         }
71         out.println("</body>");
72         out.println("</html>");
73         out.close();
74     }
75     
76     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
77
/** Handles the HTTP <code>GET</code> method.
78      * @param request servlet request
79      * @param response servlet response
80      */

81     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
82     throws ServletException JavaDoc, IOException JavaDoc {
83         processRequest(request, response);
84     }
85     
86     /** Handles the HTTP <code>POST</code> method.
87      * @param request servlet request
88      * @param response servlet response
89      */

90     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
91     throws ServletException JavaDoc, IOException JavaDoc {
92         processRequest(request, response);
93     }
94     
95     /** Returns a short description of the servlet.
96      */

97     public String JavaDoc getServletInfo() {
98         return "Short description";
99     }
100     // </editor-fold>
101

102     private org.netbeans.test.examples.logging.BGTrans getBGTrans() {
103         org.netbeans.test.examples.logging.BGTrans bGTrans = null;
104         try {
105             javax.naming.InitialContext JavaDoc ic = new javax.naming.InitialContext JavaDoc();
106             bGTrans = (org.netbeans.test.examples.logging.BGTrans) ic.lookup("java:comp/env/service/BGTrans");
107         } catch(javax.naming.NamingException JavaDoc ex) {
108             // TODO handle JNDI naming exception
109
}
110         return bGTrans;
111     }
112     
113     private org.netbeans.test.examples.logging.BGTransPortType getBGTransPort() {
114         org.netbeans.test.examples.logging.BGTransPortType bGTransPort = null;
115         try {
116             bGTransPort = getBGTrans().getBGTransPort();
117         } catch(javax.xml.rpc.ServiceException JavaDoc ex) {
118             // TODO handle service exception
119
}
120         return bGTransPort;
121     }
122 }
123
Popular Tags