KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > ReplaySendXMLServlet


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 package org.netbeans.modules.web.monitor.client;
21
22 import java.io.*;
23 import java.text.*;
24 import java.util.Enumeration JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29 import org.netbeans.modules.web.monitor.data.MonitorData;
30
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileLock;
33
34 /*
35  * Send the xml file for a transaction back to the replay filter/interceptor.
36  */

37
38 public class ReplaySendXMLServlet extends HttpServlet {
39
40
41     private static FileObject currDir = null;
42     private static FileObject saveDir = null;
43     private static FileObject replayDir = null;
44     private final static boolean debug = false;
45      
46
47     //
48
// The action is really going to happen in the GET??
49
//
50
public void doPost(HttpServletRequest req, HttpServletResponse res)
51     throws ServletException, IOException {
52
53     if(debug)
54         System.out.println("\n\nReplaySendXMLServlet: DoPost.\n\n"); //NOI18N
55
PrintWriter out = res.getWriter();
56     try {
57         out.println("Shouldn't use POST for this!"); //NOI18N
58
}
59     catch (Exception JavaDoc e) {
60     }
61     try { out.close(); } catch(Exception JavaDoc ex) {}
62     }
63
64     // Return the desired transaction file in the response.
65
//
66
public void doGet(HttpServletRequest req, HttpServletResponse res)
67     throws ServletException, IOException {
68
69     if(debug) System.out.println("\n\nReplaySendXMLServlet: DoGet.\n\n"); //NOI18N
70

71     String JavaDoc status = null;
72     String JavaDoc id = null;
73     
74     try {
75         status = req.getParameter("status"); //NOI18N
76
id = req.getParameter("id"); //NOI18N
77
if(debug)
78         System.out.println("\n\nReplaySendXMLServlet: id=" + //NOI18N
79
id + " ,status=" + status); //NOI18N
80
}
81     catch(Exception JavaDoc ex) {
82         // PENDING - deal
83
return;
84     }
85
86     Controller controller = MonitorAction.getController();
87     MonitorData md = controller.retrieveMonitorData(id, status);
88     if(md != null) {
89
90         Util.setSessionCookieHeader(md);
91         String JavaDoc method =
92         md.getRequestData().getAttributeValue("method"); //NOI18N
93

94         if(method.equals("POST")) { //NOI18N
95
Util.removeParametersFromQuery(md.getRequestData());
96         }
97         else if(method.equals("GET")) { //NOI18N
98
Util.composeQueryString(md.getRequestData());
99         }
100
101         res.addHeader("Content-type", //NOI18N
102
"text/plain;charset=\"UTF-8\""); //NOI18N
103

104         PrintWriter out = res.getWriter();
105         try {
106         md.write(out);
107         }
108         catch(NullPointerException JavaDoc npe) {
109         if(debug) npe.printStackTrace();
110         }
111         catch(IOException ioe) {
112         if(debug) ioe.printStackTrace();
113         }
114         catch(Throwable JavaDoc t) {
115         if(debug) t.printStackTrace();
116         }
117         finally {
118         // Do we need to close out?
119
try {
120             out.close();
121         }
122         catch(Exception JavaDoc ex) {
123         }
124         }
125     }
126     if(debug) {
127         try {
128         StringBuffer JavaDoc buf = new StringBuffer JavaDoc
129             (System.getProperty("java.io.tmpdir")); // NOI18N
130
buf.append(System.getProperty("file.separator")); // NOI18N
131
buf.append("replay-servlet.xml"); // NOI18N
132
File file = new File(buf.toString());
133         log("Writing replay data to " // NOI18N
134
+ file.getAbsolutePath());
135         FileOutputStream fout = new FileOutputStream(file);
136         PrintWriter pw2 = new PrintWriter(fout);
137         md.write(pw2);
138         pw2.close();
139         fout.close();
140
141         }
142         catch(Throwable JavaDoc t) {
143         }
144     }
145     
146     if(debug)
147         System.out.println("ReplaySendXMLServlet doGet exiting..."); //NOI18N
148
}
149 } //ReplaySendXMLServlet.java
150

151
152
153
Popular Tags