001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.monitor.client;
043:
044: import java.io.*;
045: import java.text.*;
046: import java.util.Enumeration;
047: import java.util.StringTokenizer;
048: import javax.servlet.*;
049: import javax.servlet.http.*;
050:
051: import org.netbeans.modules.web.monitor.data.MonitorData;
052:
053: import org.openide.filesystems.FileObject;
054: import org.openide.filesystems.FileLock;
055:
056: /*
057: * Send the xml file for a transaction back to the replay filter/interceptor.
058: */
059:
060: public class ReplaySendXMLServlet extends HttpServlet {
061:
062: private static FileObject currDir = null;
063: private static FileObject saveDir = null;
064: private static FileObject replayDir = null;
065: private final static boolean debug = false;
066:
067: //
068: // The action is really going to happen in the GET??
069: //
070: public void doPost(HttpServletRequest req, HttpServletResponse res)
071: throws ServletException, IOException {
072:
073: if (debug)
074: System.out
075: .println("\n\nReplaySendXMLServlet: DoPost.\n\n"); //NOI18N
076: PrintWriter out = res.getWriter();
077: try {
078: out.println("Shouldn't use POST for this!"); //NOI18N
079: } catch (Exception e) {
080: }
081: try {
082: out.close();
083: } catch (Exception ex) {
084: }
085: }
086:
087: // Return the desired transaction file in the response.
088: //
089: public void doGet(HttpServletRequest req, HttpServletResponse res)
090: throws ServletException, IOException {
091:
092: if (debug)
093: System.out.println("\n\nReplaySendXMLServlet: DoGet.\n\n"); //NOI18N
094:
095: String status = null;
096: String id = null;
097:
098: try {
099: status = req.getParameter("status"); //NOI18N
100: id = req.getParameter("id"); //NOI18N
101: if (debug)
102: System.out.println("\n\nReplaySendXMLServlet: id=" + //NOI18N
103: id + " ,status=" + status); //NOI18N
104: } catch (Exception ex) {
105: // PENDING - deal
106: return;
107: }
108:
109: Controller controller = MonitorAction.getController();
110: MonitorData md = controller.retrieveMonitorData(id, status);
111: if (md != null) {
112:
113: Util.setSessionCookieHeader(md);
114: String method = md.getRequestData().getAttributeValue(
115: "method"); //NOI18N
116:
117: if (method.equals("POST")) { //NOI18N
118: Util.removeParametersFromQuery(md.getRequestData());
119: } else if (method.equals("GET")) { //NOI18N
120: Util.composeQueryString(md.getRequestData());
121: }
122:
123: res.addHeader("Content-type", //NOI18N
124: "text/plain;charset=\"UTF-8\""); //NOI18N
125:
126: PrintWriter out = res.getWriter();
127: try {
128: md.write(out);
129: } catch (NullPointerException npe) {
130: if (debug)
131: npe.printStackTrace();
132: } catch (IOException ioe) {
133: if (debug)
134: ioe.printStackTrace();
135: } catch (Throwable t) {
136: if (debug)
137: t.printStackTrace();
138: } finally {
139: // Do we need to close out?
140: try {
141: out.close();
142: } catch (Exception ex) {
143: }
144: }
145: }
146: if (debug) {
147: try {
148: StringBuffer buf = new StringBuffer(System
149: .getProperty("java.io.tmpdir")); // NOI18N
150: buf.append(System.getProperty("file.separator")); // NOI18N
151: buf.append("replay-servlet.xml"); // NOI18N
152: File file = new File(buf.toString());
153: log("Writing replay data to " // NOI18N
154: + file.getAbsolutePath());
155: FileOutputStream fout = new FileOutputStream(file);
156: PrintWriter pw2 = new PrintWriter(fout);
157: md.write(pw2);
158: pw2.close();
159: fout.close();
160:
161: } catch (Throwable t) {
162: }
163: }
164:
165: if (debug)
166: System.out.println("ReplaySendXMLServlet doGet exiting..."); //NOI18N
167: }
168: } //ReplaySendXMLServlet.java
|