All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.willow.servers.InfoServlet Maven / Gradle / Ivy

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(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); String cipherSuite = (String)request.getAttribute("javax.servlet.request.cipher_suite"); if (cipherSuite != null) { out.println(""); out.println(""); } out.println("
Protocol" + request.getProtocol() + "
Method" + request.getMethod() + "
"); out.println("
URI" + filter(request.getRequestURI()) + "
Path Info" + filter(request.getPathInfo()) + "
Path Translated:" + request.getPathTranslated() + "
Remote address" + request.getRemoteAddr() + "
SSLCipherSuite:" + cipherSuite + "
"); } 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(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy