use of org.apache.tomcat.util.res.StringManager in project tomcat70 by apache.
the class HTMLManagerServlet method getSessionsForName.
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) {
if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
String path = null;
if (cn != null) {
path = cn.getPath();
}
throw new IllegalArgumentException(smClient.getString("managerServlet.invalidPath", RequestUtil.filter(path)));
}
Context ctxt = (Context) host.findChild(cn.getName());
if (null == ctxt) {
throw new IllegalArgumentException(smClient.getString("managerServlet.noContext", RequestUtil.filter(cn.getDisplayName())));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<Session>();
sessions.addAll(Arrays.asList(manager.findSessions()));
if (manager instanceof DistributedManager && showProxySessions) {
// Add dummy proxy sessions
Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull();
// Remove active (primary and backup) session IDs from full list
for (Session session : sessions) {
sessionIds.remove(session.getId());
}
// Left with just proxy sessions - add them
for (String sessionId : sessionIds) {
sessions.add(new DummyProxySession(sessionId));
}
}
return sessions;
}
use of org.apache.tomcat.util.res.StringManager in project tomcat70 by apache.
the class HTMLManagerServlet method doPost.
/**
* Process a POST request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
// Identify the request parameters that we need
// By obtaining the command from the pathInfo, per-command security can
// be configured in web.xml
String command = request.getPathInfo();
String path = request.getParameter("path");
ContextName cn = null;
if (path != null) {
cn = new ContextName(path, request.getParameter("version"));
}
String deployPath = request.getParameter("deployPath");
ContextName deployCn = null;
if (deployPath != null) {
deployCn = new ContextName(deployPath, request.getParameter("deployVersion"));
}
String deployConfig = request.getParameter("deployConfig");
String deployWar = request.getParameter("deployWar");
// Prepare our output writer to generate the response message
response.setContentType("text/html; charset=" + Constants.CHARSET);
String message = "";
if (command == null || command.length() == 0) {
// No command == list
// List always displayed -> do nothing
} else if (command.equals("/upload")) {
message = upload(request, smClient);
} else if (command.equals("/deploy")) {
message = deployInternal(deployConfig, deployCn, deployWar, smClient);
} else if (command.equals("/reload")) {
message = reload(cn, smClient);
} else if (command.equals("/undeploy")) {
message = undeploy(cn, smClient);
} else if (command.equals("/expire")) {
message = expireSessions(cn, request, smClient);
} else if (command.equals("/start")) {
message = start(cn, smClient);
} else if (command.equals("/stop")) {
message = stop(cn, smClient);
} else if (command.equals("/findleaks")) {
message = findleaks(smClient);
} else {
// Try GET
doGet(request, response);
return;
}
list(request, response, message, smClient);
}
use of org.apache.tomcat.util.res.StringManager in project tomcat70 by apache.
the class ManagerServlet method sessions.
/**
* Session information for the web application at the specified context path.
* Displays a profile of session thisAccessedTime listing number
* of sessions for each 10 minute interval up to 10 hours.
*
* @param writer Writer to render to
* @param cn Name of the application to list session information for
* @param idle Expire all sessions with idle time > idle for this context
*/
protected void sessions(PrintWriter writer, ContextName cn, int idle, StringManager smClient) {
if (debug >= 1) {
log("sessions: Session information for web application '" + cn + "'");
if (idle >= 0)
log("sessions: Session expiration for " + idle + " minutes '" + cn + "'");
}
if (!validateContextName(cn, writer, smClient)) {
return;
}
String displayPath = cn.getDisplayName();
try {
Context context = (Context) host.findChild(cn.getName());
if (context == null) {
writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath)));
return;
}
Manager manager = context.getManager();
if (manager == null) {
writer.println(smClient.getString("managerServlet.noManager", RequestUtil.filter(displayPath)));
return;
}
int maxCount = 60;
int histoInterval = 1;
int maxInactiveInterval = context.getSessionTimeout();
if (maxInactiveInterval > 0) {
histoInterval = maxInactiveInterval / maxCount;
if (histoInterval * maxCount < maxInactiveInterval)
histoInterval++;
if (0 == histoInterval)
histoInterval = 1;
maxCount = maxInactiveInterval / histoInterval;
if (histoInterval * maxCount < maxInactiveInterval)
maxCount++;
}
writer.println(smClient.getString("managerServlet.sessions", displayPath));
writer.println(smClient.getString("managerServlet.sessiondefaultmax", "" + maxInactiveInterval));
Session[] sessions = manager.findSessions();
int[] timeout = new int[maxCount + 1];
int notimeout = 0;
int expired = 0;
long now = System.currentTimeMillis();
for (int i = 0; i < sessions.length; i++) {
int time;
if (LAST_ACCESS_AT_START) {
time = (int) ((now - sessions[i].getLastAccessedTimeInternal()) / 1000L);
} else {
time = (int) ((now - sessions[i].getThisAccessedTimeInternal()) / 1000L);
}
if (idle >= 0 && time >= idle * 60) {
sessions[i].expire();
expired++;
}
time = time / 60 / histoInterval;
if (time < 0)
notimeout++;
else if (time >= maxCount)
timeout[maxCount]++;
else
timeout[time]++;
}
if (timeout[0] > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout", "<" + histoInterval, "" + timeout[0]));
for (int i = 1; i < maxCount; i++) {
if (timeout[i] > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout", "" + (i) * histoInterval + " - <" + (i + 1) * histoInterval, "" + timeout[i]));
}
if (timeout[maxCount] > 0) {
writer.println(smClient.getString("managerServlet.sessiontimeout", ">=" + maxCount * histoInterval, "" + timeout[maxCount]));
}
if (notimeout > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout.unlimited", "" + notimeout));
if (idle >= 0)
writer.println(smClient.getString("managerServlet.sessiontimeout.expired", ">" + idle, "" + expired));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.sessions[" + displayPath + "]", t);
writer.println(smClient.getString("managerServlet.exception", t.toString()));
}
}
use of org.apache.tomcat.util.res.StringManager in project tomcat70 by apache.
the class ManagerServlet method doPut.
/**
* Process a PUT request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
// Identify the request parameters that we need
String command = request.getPathInfo();
if (command == null)
command = request.getServletPath();
String path = request.getParameter("path");
ContextName cn = null;
if (path != null) {
cn = new ContextName(path, request.getParameter("version"));
}
String tag = request.getParameter("tag");
boolean update = false;
if ((request.getParameter("update") != null) && (request.getParameter("update").equals("true"))) {
update = true;
}
// Prepare our output writer to generate the response message
response.setContentType("text/plain;charset=" + Constants.CHARSET);
// Stop older versions of IE thinking they know best. We set text/plain
// in the line above for a reason. IE's behaviour is unwanted at best
// and dangerous at worst.
response.setHeader("X-Content-Type-Options", "nosniff");
PrintWriter writer = response.getWriter();
// Process the requested command
if (command == null) {
writer.println(smClient.getString("managerServlet.noCommand"));
} else if (command.equals("/deploy")) {
deploy(writer, cn, tag, update, request, smClient);
} else {
writer.println(smClient.getString("managerServlet.unknownCommand", command));
}
// Finish up the response
writer.flush();
writer.close();
}
use of org.apache.tomcat.util.res.StringManager in project tomcat70 by apache.
the class HTMLHostManagerServlet method doGet.
// --------------------------------------------------------- Public Methods
/**
* Process a GET request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
// Identify the request parameters that we need
String command = request.getPathInfo();
// Prepare our output writer to generate the response message
response.setContentType("text/html; charset=" + Constants.CHARSET);
String message = "";
// Process the requested command
if (command == null) {
// No command == list
} else if (command.equals("/list")) {
// Nothing to do - always generate list
} else if (command.equals("/add") || command.equals("/remove") || command.equals("/start") || command.equals("/stop")) {
message = smClient.getString("hostManagerServlet.postCommand", command);
} else {
message = smClient.getString("hostManagerServlet.unknownCommand", command);
}
list(request, response, message, smClient);
}
Aggregations