Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1998-2018 Caucho Technology -- all rights reserved
*
* This file is part of Resin(R) Open Source
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Resin Open Source is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Resin Open Source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
* of NON-INFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with Resin Open Source; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Scott Ferguson
*/
package com.caucho.servlets;
import com.caucho.VersionFactory;
import com.caucho.config.ConfigException;
import com.caucho.jmx.Jmx;
import com.caucho.management.server.*;
import com.caucho.util.L10N;
import com.caucho.util.QDate;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Displays some status information about the Resin server.
* The servlet must be explicitly enabled (using /servlet is forbidden),
* and it must have the init-param enable set to "read" or "write".
* (There will likely be a future additional requirement of satisfying
* a role.)
*/
public class ResinStatusServlet extends GenericServlet {
static final protected Logger log
= Logger.getLogger(ResinStatusServlet.class.getName());
static final L10N L = new L10N(ResinStatusServlet.class);
private static final long SECOND = 1000L;
private static final long MINUTE = 60 * SECOND;
private static final long HOUR = 60 * MINUTE;
private static final long DAY = 24 * HOUR;
private String _enable;
private MBeanServer _mbeanServer;
private ResinMXBean _resin;
private ServerMXBean _server;
private ClusterMXBean _cluster;
private ProxyCacheMXBean _proxyCache;
/**
* Set to read or write.
*/
public void setEnable(String enable)
throws ConfigException
{
if ("read".equals(enable) || "write".equals(enable))
_enable = enable;
else
throw new ConfigException(L.l("enable value '{0}' must either be read or write.",
enable));
}
/**
* Initialize the servlet with the server's sruns.
*/
public void init()
throws ServletException
{
if (_enable == null)
throw new ServletException(L.l("ResinStatusServlet requires an explicit enable attribute."));
try {
//_mbeanServer = (MBeanServer) new InitialContext().lookup("java:comp/jmx/GlobalMBeanServer");
// _mbeanServer = Jmx.findMBeanServer();
// _mbeanServer = Jmx.getMBeanServer();
_mbeanServer =
Jmx.getGlobalMBeanServer();
//_resinServer = (ResinServerMBean) Jmx.find("resin:type=ResinServer");
//_servletServer = (ServletServerMBean) Jmx.find("resin:name=default,type=Server");
_resin = (ResinMXBean) Jmx.findGlobal("resin:type=Resin");
_server = (ServerMXBean) Jmx.findGlobal("resin:type=Server");
_cluster = (ClusterMXBean) Jmx.findGlobal("resin:type=Cluster");
_proxyCache = (ProxyCacheMXBean) Jmx.findGlobal("resin:type=ProxyCache");
} catch (Exception e) {
throw new ServletException(e);
}
}
/**
* Handle the request.
*/
public void service(ServletRequest request, ServletResponse response)
throws IOException, ServletException
{
try {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
res.setContentType("text/html");
Thread thread = Thread.currentThread();
thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
PrintWriter out = res.getWriter();
printHeader(out);
String hostName = req.getParameter("host");
String appName = req.getParameter("app");
printServerHeader(out);
printPorts(out);
printSrun(out);
/*
printJNDI(out, _server.getJndiContext());
*/
printApplicationSummary(out, req.getRequestURI());
printFooter(out);
} catch (IOException e) {
throw e;
} catch (ServletException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
/*
private void printApplication(PrintWriter out,
ApplicationAdmin app,
String pwd)
throws IOException, ServletException
{
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(app.getClassLoader());
printHeader(out);
printApplicationHeader(out, app, pwd);
printJNDI(out, app.getJndiContext());
printJMXServlets(out, app.getMBeanServer());
printFooter(out);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
*/
/**
* Prints generic server information.
*/
public void printHeader(PrintWriter out)
throws IOException, ServletException
{
}
/**
* Prints server information.
*/
public void printServerHeader(PrintWriter out)
throws Exception
{
out.println("resin-status
");
}
} catch (Exception e) {
throw new ServletException(e);
}
}
public void printConnectionPools(PrintWriter out, String context)
throws Exception
{
ObjectName pattern = new ObjectName("resin:*,type=ConnectionPool" + context);
Set poolNames;
poolNames = _mbeanServer.queryNames(pattern, null);
if (poolNames.size() == 0)
return;
out.println("
Connection Pools
");
out.println("
");
out.println("
Connections
Config");
out.println("
Name
Active
Idle
Total");
out.println("
max-connections
idle-time");
Iterator iter = poolNames.iterator();
while (iter.hasNext()) {
ObjectName name = iter.next();
ConnectionPoolMXBean pool = (ConnectionPoolMXBean) Jmx.findGlobal(name);
if (pool != null) {
out.println("
");
}
public void printJNDI(PrintWriter out, Context ic)
throws IOException, ServletException
{
printDatabasePools(out, ic);
printEJBLocalHomes(out, ic);
printEJBRemoteHomes(out, ic);
}
public void printEJBLocalHomes(PrintWriter out, Context ic)
throws IOException, ServletException
{
try {
Context cmpCxt = (Context) ic.lookup("java:comp/env/cmp");
if (cmpCxt == null)
return;
NamingEnumeration list = cmpCxt.list("");
ArrayList cmpNames = new ArrayList();
while (list.hasMoreElements()) {
NameClassPair pair = (NameClassPair) list.nextElement();
cmpNames.add(pair.getName());
}
if (cmpNames.size() == 0)
return;
out.println("
EJB Local Home
");
out.println("
");
out.println("
Name
Home Stub Class");
Collections.sort(cmpNames);
for (int i = 0; i < cmpNames.size(); i++) {
String name = (String) cmpNames.get(i);
Object value = cmpCxt.lookup(name);
if (! (value instanceof EJBLocalHome))
continue;
EJBLocalHome home = (EJBLocalHome) value;
out.print("
cmp/" + name);
Class homeStub = home.getClass();
Class []interfaces = home.getClass().getInterfaces();
for (int j = 0; j < interfaces.length; j++) {
if (EJBLocalHome.class.isAssignableFrom(interfaces[j])) {
homeStub = interfaces[j];
break;
}
}
out.print("
" + homeStub.getName());
}
out.println("
");
} catch (Exception e) {
dbg.log(e);
}
}
public void printEJBRemoteHomes(PrintWriter out, Context ic)
throws IOException, ServletException
{
try {
Context ejbCxt = (Context) ic.lookup("java:comp/env/ejb");
if (ejbCxt == null)
return;
NamingEnumeration list = ejbCxt.list("");
ArrayList ejbNames = new ArrayList();
while (list.hasMoreElements()) {
NameClassPair pair = (NameClassPair) list.nextElement();
ejbNames.add(pair.getName());
}
if (ejbNames.size() == 0)
return;
out.println("
EJB Home
");
out.println("
");
out.println("
Name
Home Stub Class");
Collections.sort(ejbNames);
for (int i = 0; i < ejbNames.size(); i++) {
String name = (String) ejbNames.get(i);
Object value = ejbCxt.lookup(name);
if (! (value instanceof EJBHome))
continue;
EJBHome home = (EJBHome) value;
out.print("
ejb/" + name);
Class homeStub = home.getClass();
Class []interfaces = home.getClass().getInterfaces();
for (int j = 0; j < interfaces.length; j++) {
if (EJBHome.class.isAssignableFrom(interfaces[j])) {
homeStub = interfaces[j];
break;
}
}
out.print("
" + homeStub.getName());
}
out.println("
");
} catch (Exception e) {
dbg.log(e);
}
}
public void printJMXServlets(PrintWriter out, MXBeanServer server)
throws IOException, ServletException
{
try {
ObjectName queryName = new ObjectName("*:j2eeType=Servlet,*");
Set servlets = server.queryNames(queryName, null);
if (servlets.size() == 0)
return;
out.println("
Servlets
");
Iterator iter = servlets.iterator();
while (iter.hasNext()) {
ObjectName servletName = (ObjectName) iter.next();
String name = servletName.getKeyProperty("name");
MXBeanInfo mbeanInfo = server.getMXBeanInfo(servletName);
MXBeanAttributeInfo []attrs = mbeanInfo.getAttributes();
out.println("
");
out.print("
Name
");
for (int i = 0; i < attrs.length; i++)
out.print("
" + attrs[i].getName() + "
");
out.println("
");
out.print("
" + name + "
");
for (int i = 0; i < attrs.length; i++) {
Object value = server.getAttribute(servletName, attrs[i].getName());
out.print("
Sessions");
ObjectName hostPattern = new ObjectName("resin:*,type=Host");
Set names = _mbeanServer.queryNames(hostPattern, null);
Iterator iter = names.iterator();
ArrayList hosts = new ArrayList();
while (iter.hasNext()) {
ObjectName name = iter.next();
// the Host with name=current is a duplicate
if ("current".equals(name.getKeyProperty("name")))
continue;
HostMXBean host = (HostMXBean) Jmx.findGlobal(name);
if (host != null) {
hosts.add(host);
}
}
Collections.sort(hosts, new HostCompare());
for (int i = 0; i < hosts.size(); i++) {
HostMXBean host = hosts.get(i);
out.println("
" + host.getURL() + "");
// thread.setContextClassLoader(hostLoader);
String hostName = host.getHostName();
if (hostName.equals(""))
hostName = "default";
ObjectName appPattern = new ObjectName("resin:*,Host=" + hostName + ",type=WebApp");
names = _mbeanServer.queryNames(appPattern, null);
iter = names.iterator();
ArrayList apps = new ArrayList();
while (iter.hasNext()) {
ObjectName name = iter.next();
try {
WebAppMXBean app = (WebAppMXBean) Jmx.findGlobal(name);
if (app != null)
apps.add(app);
} catch (Exception e) {
log.log(Level.WARNING, e.toString());
out.println("