com.nitorcreations.willow.servers.InfoServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of willow-servers Show documentation
Show all versions of willow-servers Show documentation
Willow operational servlets and servers
The newest version!
package com.nitorcreations.willow.servers;
import java.io.IOException;
import java.io.PrintWriter;
import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Singleton
public class InfoServlet extends HttpServlet {
private static final long serialVersionUID = -1042463048053284271L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("");
out.println("");
out.println("");
String title = "Request Info";
out.println("" + title + " ");
out.println("");
out.println("" + title + "
");
out.println("");
out.println("Protocol ");
out.println("" + request.getProtocol() + " ");
out.println("Method ");
out.println("" + request.getMethod() + " ");
out.println("");
out.println(" URI ");
out.println("" + filter(request.getRequestURI()) + " ");
out.println("Path Info ");
out.println("" + filter(request.getPathInfo()) + " ");
out.println("Path Translated: ");
out.println("" + request.getPathTranslated() + " ");
out.println("Remote address ");
out.println("" + request.getRemoteAddr() + " ");
String cipherSuite = (String)request.getAttribute("javax.servlet.request.cipher_suite");
if (cipherSuite != null) {
out.println("SSLCipherSuite: ");
out.println("" + cipherSuite + " ");
}
out.println("
");
} finally {
out.close();
}
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response);
}
private static String filter(String message) {
if (message == null) return null;
int len = message.length();
StringBuffer result = new StringBuffer(len + 20);
char aChar;
for (int i = 0; i < len; ++i) {
aChar = message.charAt(i);
switch (aChar) {
case '<': result.append("<"); break;
case '>': result.append(">"); break;
case '&': result.append("&"); break;
case '"': result.append("""); break;
default: result.append(aChar);
}
}
return result.toString();
}
}