home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 March
/
PCWorld_2001-03_cd.bin
/
Software
/
Komercni
/
VAgeJava
/
ivj35
/
setup
/
JSP.Cab
/
F27201_ServletEngineConfigDumper.java
< prev
next >
Wrap
Text File
|
2000-08-10
|
18KB
|
410 lines
package com.ibm.ivj.wte.samples.servletconfig;
// Licensed Material - Property of IBM
// (C) Copyright IBM Corp. 2000 - All Rights Reserved
//
// DISCLAIMER:
// The following [enclosed] code is sample code created by IBM
// Corporation. This sample code is not part of any standard IBM product
// and is provided to you solely for the purpose of assisting you in the
// development of your applications. The code is provided 'AS IS',
// without warranty or condition of any kind. IBM shall not be liable for any damages
// arising out of your use of the sample code, even if IBM has been
// advised of the possibility of such damages.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Enumeration;
import com.ibm.servlet.engine.*;
import com.ibm.servlet.engine.srt.*;
import com.ibm.servlet.engine.config.*;
import com.ibm.servlet.util.*;
import java.util.*;
/**
* Config Dumper
*
* <P> This servlet dumps the current servlet engine configuration
*/
public class ServletEngineConfigDumper extends HttpServlet
{
private static final String copyright =
"(c) Copyright IBM Corporation 2000.";
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
// Set a break point at the next line
String cmd = req.getParameter("cmd");
if ( cmd == null )
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Current Servlet Engine Configuration</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
out.println("<H1><CENTER>Current Servlet Engine Configuration</CENTER></H1><HR>");
out.println("<H2>Supported Transports - Active Transport is Bold</H2>");
Enumeration suppTrans = engineInfo.getSupportedTransportNames();
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Name</TH><TH>Code</TH><TH>Arguments</TH></TR>");
while ( suppTrans.hasMoreElements() )
{
TransportInfo transInfo = (TransportInfo)engineInfo.getTransportInfo((String)suppTrans.nextElement());
out.println("<TR><TD>");
if ( transInfo.getName().equals(engineInfo.getActiveTransportName()) )
{
out.println("<B>" + transInfo.getName() + "</B></TD><TD><B>" + transInfo.getCode() + "</B></TD><TD>");
Properties args = transInfo.getArgs();
Enumeration argsList = args.keys();
out.println("<UL>");
while ( argsList.hasMoreElements() )
{
String argName = (String)argsList.nextElement();
String argValue = args.getProperty(argName);
out.println("<LI><B>" + argName + ": " + argValue + "</B>");
}
}
else
{
out.println(transInfo.getName() + "</TD><TD>" + transInfo.getCode() + "</TD><TD>");
Properties args = transInfo.getArgs();
Enumeration argsList = args.keys();
out.println("<UL>");
while ( argsList.hasMoreElements() )
{
String argName = (String)argsList.nextElement();
String argValue = args.getProperty(argName);
out.println("<LI>" + argName + ": " + argValue);
}
}
out.println("</TD></TR>");
}
out.println("</TABLE><HR>");
Enumeration enum = engineInfo.getServletHostNames();
while ( enum.hasMoreElements() )
{
try
{
out.println("<H2>Virtual Hosts</H2>");
String name = (String)enum.nextElement();
out.println("<H3><A HREF=\"" + req.getRequestURI() + "?cmd=virtualHost&vhost=" + java.net.URLEncoder.encode(name) + "\">Configuration for Virtual Host: <I>" + name + "</I></a></H3>");
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
out.println("<HR><H2>WebSphere Application Server Version Info</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TD>Product Name</TD><TD>" + WASSystem.getProductName() + "</TD></TR>");
out.println("<TR><TD>Product Edition</TD><TD>" + WASSystem.getProductEdition() + "</TD></TR>");
out.println("<TR><TD>Product Version</TD><TD>" + WASSystem.getProductVersion() + "</TD></TR>");
out.println("<TR><TD>Product Major Version</TD><TD>" + WASSystem.getProductMajorVersion() + "</TD></TR>");
out.println("<TR><TD>Product Minor Version</TD><TD>" + WASSystem.getProductMinorVersion() + "</TD></TR>");
out.println("<TR><TD>Product Service Level</TD><TD>" + WASSystem.getProductServiceLevel() + "</TD></TR>");
out.println("<TR><TD>Product Build Level</TD><TD>" + WASSystem.getProductBuild() + "</TD></TR>");
out.println("<TR><TD>Product Build Date</TD><TD>" + WASSystem.getProductBuildDate() + "</TD></TR>");
out.println("</TABLE><HR>");
out.println("<H2>System Properties</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Property</TH><TH>Value</TH></TR>");
out.println("<TR><TD>Operating System</TD><TD>" + System.getProperty("os.name") + "</TD></TR>");
out.println("<TR><TD>Operating System Version</TD><TD>" + System.getProperty("os.version") + "</TD></TR>");
out.println("<TR><TD>Hardware Architecture</TD><TD>" + System.getProperty("os.arch") + "</TD></TR>");
out.println("<TR><TD>JVM Version</TD><TD>" + System.getProperty("java.version") + "</TD></TR>");
out.println("<TR><TD>JVM Vendor</TD><TD>" + System.getProperty("java.vendor") + "</TD></TR>");
out.println("<TR><TD>JVM Vendor URL</TD><TD>" + System.getProperty("java.vendor.url") + "</TD></TR>");
out.println("<TR><TD>JVM Class Version</TD><TD>" + System.getProperty("java.class.version") + "</TD></TR>");
out.println("<TR><TD>JVM Home Directory</TD><TD>" + System.getProperty("java.home") + "</TD></TR>");
out.println("<TR><TD>JVM Compiler (JIT)</TD><TD>" + System.getProperty("java.compiler") + "</TD></TR>");
out.println("<TR><TD>JVM Class Path</TD><TD><UL>");
String cp = System.getProperty("java.class.path");
StringTokenizer tokenizer = new StringTokenizer(cp, File.pathSeparator);
while ( tokenizer.hasMoreTokens() )
{
out.println("<LI>" + tokenizer.nextToken());
}
out.println("</UL></TD></TR>");
out.println("<TR><TD>File Separator</TD><TD>" + System.getProperty("file.separator") + "</TD></TR>");
out.println("<TR><TD>Path Separator</TD><TD>" + System.getProperty("path.separator") + "</TD></TR>");
out.println("<TR><TD>Line Separator</TD><TD>" + System.getProperty("line.separator") + "</TD></TR>");
out.println("<TR><TD>User Name</TD><TD>" + System.getProperty("user.name") + "</TD></TR>");
out.println("<TR><TD>User Home Directory</TD><TD>" + System.getProperty("user.home") + "</TD></TR>");
out.println("<TR><TD>Current Working Directory</TD><TD>" + System.getProperty("user.dir") + "</TD></TR>");
out.println("<TR><TD>User Language</TD><TD>" + System.getProperty("user.language") + "</TD></TR>");
out.println("<TR><TD>User Region</TD><TD>" + System.getProperty("user.region") + "</TD></TR>");
out.println("<TR><TD>User Timezone</TD><TD>" + System.getProperty("user.timezone") + "</TD></TR>");
out.println("<TR><TD>File Encoding</TD><TD>" + System.getProperty("file.encoding") + "</TD></TR>");
out.println("<TR><TD>File Encoding Package</TD><TD>" + System.getProperty("file.encoding.pkg") + "</TD></TR>");
Enumeration propKeys = System.getProperties().keys();
while ( propKeys.hasMoreElements() )
{
String key = (String)propKeys.nextElement();
if ( !key.equals("os.name") &&
!key.equals("os.version") &&
!key.equals("os.arch") &&
!key.equals("java.version") &&
!key.equals("java.vendor") &&
!key.equals("java.vendor.url") &&
!key.equals("java.class.version") &&
!key.equals("java.home") &&
!key.equals("java.compiler") &&
!key.equals("java.class.path") &&
!key.equals("file.separator") &&
!key.equals("path.separator") &&
!key.equals("line.separator") &&
!key.equals("user.name") &&
!key.equals("user.home") &&
!key.equals("user.dir") &&
!key.equals("user.language") &&
!key.equals("user.region") &&
!key.equals("user.timezone") &&
!key.equals("file.encoding") &&
!key.equals("file.encoding.pkg") )
{
String value = System.getProperty(key);
out.println("<TR><TD>" + key + "</TD><TD>" + value + "</TD></TR>");
}
}
out.println("</TABLE>");
out.println("<HR>");
out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
out.println("</BODY></HTML>");
out.flush();
out.close();
}
else if ( cmd.equalsIgnoreCase("mime") )
{
String vhost = req.getParameter("vhost");
ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
ServletHostInfo vhinfo = engineInfo.getServletHostInfo(vhost);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Mime Table for Virtual Host - " + vhost + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
out.println("<CENTER><H1>Mime Table for Virtual Host <b><i>" + vhost + "</i></b></H1><HR></CENTER><BR><P>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>File Extension</TH><TH>Mime Type</TH></TR>");
Hashtable mimemap = vhinfo.getMimeMap();
Enumeration mimeenum = mimemap.keys();
while ( mimeenum.hasMoreElements() )
{
String ext = (String)mimeenum.nextElement();
String type = (String)mimemap.get(ext);
out.println("<TR><TD>" + ext + "</TD><TD>" + type + "</TD></TR>");
}
out.println("</TABLE>");
out.println("<HR>");
out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
out.println("</BODY></HTML>");
out.flush();
out.close();
}
else if ( cmd.equalsIgnoreCase("virtualHost") )
{
try
{
String name = req.getParameter("vhost");
ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
ServletHostInfo hostInfo = engineInfo.getServletHostInfo(name);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Configuration for Virtual Host " + name + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
out.println("<CENTER><H1>Configuration for Virtual Host<b><i> " + name + "</i></B></H1></CENTER><HR>");
out.println("<TABLE Border=\"2\" WIDTH=\"50%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Supported DNS Names (Alias List)</TH></TR>");
Enumeration bindings = engineInfo.getHostnameBindingInfos();
while ( bindings.hasMoreElements() )
{
HostnameBindingInfo binding = (HostnameBindingInfo)bindings.nextElement();
out.println("<TR><TD>" + binding.getHostname() + "</TD></TR>");
}
out.println("</TABLE>");
out.println("<H3><A HREF=\"" + req.getRequestURI() + "?cmd=mime&vhost=" + java.net.URLEncoder.encode(name) + "\">Mime Table</a></H3>");
Enumeration enum2 = hostInfo.getWebGroupNames();
while ( enum2.hasMoreElements() )
{
String groupName = (String)enum2.nextElement();
out.println("<H3><A HREF=\"" + req.getRequestURI() + "?cmd=webapp&vhost=" + java.net.URLEncoder.encode(name) + "&webgroup=" + groupName + "\">Configuration for Web Application: <B><I> " + groupName + "</i></b></A></H3>");
}
out.println("<HR>");
out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
out.println("</BODY></HTML>");
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
else if ( cmd.equalsIgnoreCase("webapp") )
{
String vhost = req.getParameter("vhost");
String webgroup = req.getParameter("webgroup");
ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
ServletHostInfo vhinfo = engineInfo.getServletHostInfo(vhost);
WebGroupInfo wgInfo = vhinfo.getWebGroupInfo(webgroup);
WebAppInfo appInfo = wgInfo.getWebAppInfo();
String serverName = req.getServerName() + ":" + req.getServerPort();
Enumeration hnames = engineInfo.getHostnameBindingInfos();
while ( hnames.hasMoreElements() )
{
HostnameBindingInfo bindingInfo = (HostnameBindingInfo)hnames.nextElement();
if ( bindingInfo.getServletHostName().equals(vhost) )
{
if ( !bindingInfo.getHostname().equals("localhost") )
{
serverName = bindingInfo.getHostname();
break;
}
}
}
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try
{
out.println("<HTML><HEAD><TITLE>Configuration for " + webgroup + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
out.println("<H1><CENTER>Configuration for Web Application <i><b>" + webgroup + "</i></b></CENTER></H1><HR>");
out.println("<H2>Web Application Settings</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TD><B>Description:</B></TD><TD>" + appInfo.getDescription() + "</TD></TR>");
out.println("<TR><TD><B>Virtual Host:</B></TD><TD>" + vhost + "</TD></TR>");
out.println("<TR><TD><B>Engine:</B></TD><TD>" + engineInfo.getName() + "</TD></TR>");
out.println("<TR><TD><B>Document Root:</B></TD><TD>" + wgInfo.getDocumentRoot() + "</TD></TR>");
out.println("<TR><TD><B>Classpath:</B></TD><TD>" + wgInfo.getClasspath() + "</TD></TR>");
out.println("<TR><TD><B>Root URI:</B></TD><TD>" + wgInfo.getRootURI() + "</TD></TR>");
out.println("<TR><TD><B>Shared Context In Use:</B></TD><TD>" + wgInfo.isSharedContext() + "</TD></TR>");
out.println("<TR><TD><B>Shared Context JNDI Name:</B></TD><TD>" + wgInfo.getSharedContextJNDIName() + "</TD></TR>");
out.println("<TR><TD><B>Auto reload:</B></TD><TD>" + wgInfo.isAutoReload() + "</TD></TR>");
out.println("<TR><TD><B>Auto reload polling interval:</B></TD><TD>" + wgInfo.getAutoReloadPollingInterval() / 1000 + " seconds</TD></TR>");
out.println("<TR><TD><B>Error Page:</B></TD><TD>" + appInfo.getErrorPage() + "</TD></TR>");
out.println("</TABLE>");
out.println("<H2>Web Application Attributes</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Attribute Name</TH><TH>Type</TH><TH>Value</TH></TR>");
Enumeration ae = appInfo.getAttributeNames();
while ( ae.hasMoreElements() )
{
String name = (String)ae.nextElement();
AttributeInfo attrInfo = appInfo.getAttributeInfo(name);
out.println("<TR>");
out.println("<TD><B>" + attrInfo.getName() + "</B></TD>");
out.println("<TD>" + attrInfo.getType() + "</TD>");
if ( attrInfo.getType().equals(AttributeInfo.TYPE_STRING) )
{
out.println("<TD>" + attrInfo.getString() + "</TD>");
}
else
{
out.println("<TD>" + attrInfo.getBeanInfo().toString() + "</TD>");
}
out.println("</UL></TD></TR>");
}
out.println("</TABLE>");
out.println("<H2>Mime Filters</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Mime Type</TH><TH>Servlet Name</TH></TR>");
Enumeration me = appInfo.getMimeFilterTypes();
while ( me.hasMoreElements() )
{
String name = (String)me.nextElement();
MimeFilterInfo mimeInfo = appInfo.getMimeFilterInfo(name);
out.println("<TR>");
out.println("<TD><B>" + mimeInfo.getMimeType() + "</B></TD>");
out.println("<TD>" + mimeInfo.getServletName() + "</TD>");
out.println("</UL></TD></TR>");
}
out.println("</TABLE>");
out.println("<H2>Servlet Information</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
out.println("<TR><TH>Name</TH><TH>Description</TH><TH>Code</TH><TH>Auto-start</TH><TH>Init Parameters</TH><TH>Paths</TH></TR>");
Enumeration e1 = appInfo.getServletNames();
while ( e1.hasMoreElements() )
{
out.println("<TR>");
String servletName = (String)e1.nextElement();
ServletInfo sinfo = appInfo.getServletInfoByName(servletName);
out.println("<TD><B>" + sinfo.getName() + "</B></TD>");
out.println("<TD>" + sinfo.getDescription() + "</TD>");
String code = sinfo.getCode();
if ( code.lastIndexOf(".") != -1 )
{
String codePkg = code;
code = code.substring(code.lastIndexOf(".") + 1);
codePkg = codePkg.substring(0, codePkg.lastIndexOf("."));
out.println("<TD><B>" + code + "</B><BR><font size=-1>" + codePkg + "</font></TD>");
}
else
{
out.println("<TD><B>" + code + "</B></TD>");
}
out.println("<TD>" + sinfo.isAutostart() + "</TD>");
out.println("<TD><UL>");
Enumeration e2 = sinfo.getInitParameterNames();
while ( e2.hasMoreElements() )
{
String initName = (String)e2.nextElement();
out.println("<LI>" + initName + ": " + sinfo.getInitParameter(initName));
}
out.println("</UL></TD>");
out.println("<TD><UL>");
Enumeration e3 = sinfo.getServletPaths();
while ( e3.hasMoreElements() )
{
String path = (String)e3.nextElement();
String ref = "http://" + serverName + wgInfo.getRootURI();
if ( ref.endsWith("/") )
ref = ref.substring(0, ref.length() - 1);
ref += path;
out.println("<LI>" + path);
}
out.println("</UL></TD></TR>");
}
out.println("</TABLE>");
}
catch ( Exception ex )
{
ex.printStackTrace();
}
out.println("<HR>");
out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
out.println("</BODY></HTML>");
out.flush();
out.close();
}
}
}