package org.autoplot.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.autoplot.ApplicationModel;
import org.autoplot.AutoplotUtil;
import org.autoplot.dom.Application;
/**
* servlet for reporting version information. This should be
* updated manually before adding and releasing new features.
* @author faden@cottagesystems.com
*/
public class ServletInfo extends HttpServlet {
private static final long birthMilli= System.currentTimeMillis();
public static final String version = "v20200719.0851";
public static long getAgeMillis() {
return System.currentTimeMillis() - birthMilli;
}
/**
* return the duration in a easily-human-consumable form.
* @param dt the duration in milliseconds.
* @return a duration like "2.6 hours"
*/
public static String getDurationForHumans( long dt ) {
if ( dt<2*1000 ) {
return dt+" milliseconds";
} else if ( dt<2*60000 ) {
return String.format( Locale.US, "%.1f",dt/1000.)+" seconds";
} else if ( dt<2*3600000 ) {
return String.format( Locale.US, "%.1f",dt/60000.)+" minutes";
} else if ( dt<2*86400000 ) {
return String.format( Locale.US, "%.1f",dt/3600000.)+" hours";
} else {
return String.format( Locale.US, "%.1f",dt/86400000.)+" days";
}
}
/**
* Processes requests for both HTTP GET
and POST
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("");
out.println("");
out.println("
PWD: "+ ( new File(".").getAbsolutePath() ) +"\n" );
out.println("
Servlet Home: "+ServletUtil.getServletHome() + "\n"); // TODO: security concerns
File sd= ServletUtil.getServletHome();
File ff= new File( sd, "whitelist.txt" );
out.println("
GET
method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP POST
method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}//