Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9d9d2798c2c54c0912e6eb63cb0fa4360947f1d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.eclipse.stem.ui.ge.servlet;
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/ 
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.stem.ui.Activator;


/**
 * Servlet that allows the client to verify that the 
 * web server is started and the STEM-GoogleEarth servlets 
 * are deployed.
 * 
 * If it gets a String "VerifyClient v.v.v"
 * It returns a String "VerifyServlet v.v.v"
 * 
 */
public class VerifyServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	
	  /**
     * String that we will send the client
     */
 	private static String outputText="VerifyServlet "+
 			Version.version;
 	/**
 	 * String that client should send us.
 	 */
 	private static String expectedText="VerifyClient "+
 	 		Version.version;
    /**
     * 
     * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    protected void service(HttpServletRequest request,HttpServletResponse response) 
            throws ServletException, IOException {
    	
		DataInputStream in = 
			new DataInputStream(request.getInputStream());
		response.setContentType("application/octer-stream");
		// use ByteArray output
		ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
		DataOutputStream output =
			new DataOutputStream(byteOutput);
		//
		// read the input from the client
		//
		String stringValue = in.readUTF();
		if (stringValue.startsWith(expectedText)) {
			output.writeUTF(outputText);
			if (stringValue.contains("DEBUG")) {
				SlideShowServlet.DEBUG = true;
			}
		} else {
			String errmsg = "Error: "+
			                "Expected: "+expectedText+
			                " Received: "+stringValue;
			debug(errmsg);
			output.writeUTF(errmsg);
		}
		output.flush();
		byte[] buf = byteOutput.toByteArray();
		response.setContentLength(buf.length);
		ServletOutputStream servletOutput = response.getOutputStream();
		servletOutput.write(buf);
		servletOutput.close();
		
	}
	
	
	@SuppressWarnings("unused")
	private void errHtml(HttpServletResponse response, String msg)
			throws IOException {
		response.setContentType("text/html");
		PrintWriter out = new PrintWriter(response.getOutputStream());
		out.println("<html>");
		out.println("<head><title>VerifyServlet Error</title></head>");
		out.println("<body>");
		out.println("<p>" + msg + "</p>");
		out.println("</body></html>");
		out.flush();
	}
	


    /**
     * print debug messages to the server log.
     * @param msg
     */
	private static void debug(String msg) {
		if (SlideShowServlet.DEBUG) {		  
		  Activator.logInformation("VerifyServlet: "+msg);
		}
	}
	
	@SuppressWarnings("unused")
	private static void debug(String msg,Throwable e) {
		//log(msg,e);
		Activator.logInformation(msg);
		e.printStackTrace();
		
	}
}


Back to the top