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 >
Text File  |  2000-08-10  |  18KB  |  410 lines

  1. package com.ibm.ivj.wte.samples.servletconfig;
  2.  
  3. // Licensed Material - Property of IBM 
  4. // (C) Copyright IBM Corp. 2000 - All Rights Reserved 
  5. // 
  6. // DISCLAIMER: 
  7. // The following [enclosed] code is sample code created by IBM 
  8. // Corporation.  This sample code is not part of any standard IBM product 
  9. // and is provided to you solely for the purpose of assisting you in the 
  10. // development of your applications.  The code is provided 'AS IS', 
  11. // without warranty or condition of any kind.  IBM shall not be liable for any damages 
  12. // arising out of your use of the sample code, even if IBM has been 
  13. // advised of the possibility of such damages.
  14.  
  15. import java.io.*;
  16. import javax.servlet.*;
  17. import javax.servlet.http.*;
  18. import java.util.Enumeration;
  19. import com.ibm.servlet.engine.*;
  20. import com.ibm.servlet.engine.srt.*;
  21. import com.ibm.servlet.engine.config.*;
  22. import com.ibm.servlet.util.*;
  23. import java.util.*;
  24.  
  25. /**
  26.  * Config Dumper
  27.  *
  28.  * <P> This servlet dumps the current servlet engine configuration
  29.  */
  30. public class ServletEngineConfigDumper extends HttpServlet
  31. {
  32. private static final String copyright = 
  33.     "(c) Copyright IBM Corporation 2000.";
  34.  
  35.  
  36.     public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
  37.     {
  38.         // Set a break point at the next line
  39.         String cmd = req.getParameter("cmd");
  40.         if ( cmd == null )
  41.         {
  42.             res.setContentType("text/html");
  43.             PrintWriter out = res.getWriter();
  44.  
  45.             out.println("<HTML><HEAD><TITLE>Current Servlet Engine Configuration</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
  46.             ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
  47.             out.println("<H1><CENTER>Current Servlet Engine Configuration</CENTER></H1><HR>");
  48.             out.println("<H2>Supported Transports - Active Transport is Bold</H2>");
  49.             Enumeration suppTrans = engineInfo.getSupportedTransportNames();
  50.             out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  51.             out.println("<TR><TH>Name</TH><TH>Code</TH><TH>Arguments</TH></TR>");
  52.             while ( suppTrans.hasMoreElements() )
  53.             {
  54.                 TransportInfo transInfo = (TransportInfo)engineInfo.getTransportInfo((String)suppTrans.nextElement());
  55.                 out.println("<TR><TD>");
  56.                 if ( transInfo.getName().equals(engineInfo.getActiveTransportName()) )
  57.                 {
  58.                     out.println("<B>" + transInfo.getName() + "</B></TD><TD><B>" + transInfo.getCode() + "</B></TD><TD>");
  59.                     Properties args = transInfo.getArgs();
  60.                     Enumeration argsList = args.keys();
  61.                     out.println("<UL>");
  62.                     while ( argsList.hasMoreElements() )
  63.                     {
  64.                         String argName = (String)argsList.nextElement();
  65.                         String argValue = args.getProperty(argName);
  66.                         out.println("<LI><B>" + argName + ": " + argValue + "</B>");
  67.                     }
  68.                 }
  69.                 else
  70.                 {
  71.                     out.println(transInfo.getName() + "</TD><TD>" + transInfo.getCode() + "</TD><TD>");
  72.                     Properties args = transInfo.getArgs();
  73.                     Enumeration argsList = args.keys();
  74.                     out.println("<UL>");
  75.                     while ( argsList.hasMoreElements() )
  76.                     {
  77.                         String argName = (String)argsList.nextElement();
  78.                         String argValue = args.getProperty(argName);
  79.                         out.println("<LI>" + argName + ": " + argValue);
  80.                     }
  81.                 }
  82.                 out.println("</TD></TR>");
  83.             }
  84.             out.println("</TABLE><HR>");
  85.  
  86.             Enumeration enum = engineInfo.getServletHostNames();
  87.             while ( enum.hasMoreElements() )
  88.             {
  89.                 try
  90.                 {
  91.                     out.println("<H2>Virtual Hosts</H2>");
  92.                     String name = (String)enum.nextElement();
  93.                     out.println("<H3><A HREF=\"" + req.getRequestURI() + "?cmd=virtualHost&vhost=" + java.net.URLEncoder.encode(name) + "\">Configuration for Virtual Host: <I>" + name + "</I></a></H3>");
  94.                 }
  95.                 catch ( Exception ex )
  96.                 {
  97.                     ex.printStackTrace();
  98.                 }
  99.  
  100.             }
  101.  
  102.             out.println("<HR><H2>WebSphere Application Server Version Info</H2>");
  103.             out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  104.             out.println("<TR><TD>Product Name</TD><TD>" + WASSystem.getProductName() + "</TD></TR>");
  105.             out.println("<TR><TD>Product Edition</TD><TD>" + WASSystem.getProductEdition() + "</TD></TR>");
  106.             out.println("<TR><TD>Product Version</TD><TD>" + WASSystem.getProductVersion() + "</TD></TR>");
  107.             out.println("<TR><TD>Product Major Version</TD><TD>" + WASSystem.getProductMajorVersion() + "</TD></TR>");
  108.             out.println("<TR><TD>Product Minor Version</TD><TD>" + WASSystem.getProductMinorVersion() + "</TD></TR>");
  109.             out.println("<TR><TD>Product Service Level</TD><TD>" + WASSystem.getProductServiceLevel() + "</TD></TR>");
  110.             out.println("<TR><TD>Product Build Level</TD><TD>" + WASSystem.getProductBuild() + "</TD></TR>");
  111.             out.println("<TR><TD>Product Build Date</TD><TD>" + WASSystem.getProductBuildDate() + "</TD></TR>");
  112.             out.println("</TABLE><HR>");
  113.  
  114.             out.println("<H2>System Properties</H2>");
  115.             out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  116.             out.println("<TR><TH>Property</TH><TH>Value</TH></TR>");
  117.  
  118.             out.println("<TR><TD>Operating System</TD><TD>" + System.getProperty("os.name") + "</TD></TR>");
  119.             out.println("<TR><TD>Operating System Version</TD><TD>" + System.getProperty("os.version") + "</TD></TR>");
  120.             out.println("<TR><TD>Hardware Architecture</TD><TD>" + System.getProperty("os.arch") + "</TD></TR>");
  121.             out.println("<TR><TD>JVM Version</TD><TD>" + System.getProperty("java.version") + "</TD></TR>");
  122.             out.println("<TR><TD>JVM Vendor</TD><TD>" + System.getProperty("java.vendor") + "</TD></TR>");
  123.             out.println("<TR><TD>JVM Vendor URL</TD><TD>" + System.getProperty("java.vendor.url") + "</TD></TR>");
  124.             out.println("<TR><TD>JVM Class Version</TD><TD>" + System.getProperty("java.class.version") + "</TD></TR>");
  125.             out.println("<TR><TD>JVM Home Directory</TD><TD>" + System.getProperty("java.home") + "</TD></TR>");
  126.             out.println("<TR><TD>JVM Compiler (JIT)</TD><TD>" + System.getProperty("java.compiler") + "</TD></TR>");
  127.  
  128.             out.println("<TR><TD>JVM Class Path</TD><TD><UL>");
  129.             String cp = System.getProperty("java.class.path");
  130.             StringTokenizer tokenizer = new StringTokenizer(cp, File.pathSeparator);
  131.             while ( tokenizer.hasMoreTokens() )
  132.             {
  133.                 out.println("<LI>" + tokenizer.nextToken());
  134.             }
  135.             out.println("</UL></TD></TR>");
  136.             out.println("<TR><TD>File Separator</TD><TD>" + System.getProperty("file.separator") + "</TD></TR>");
  137.             out.println("<TR><TD>Path Separator</TD><TD>" + System.getProperty("path.separator") + "</TD></TR>");
  138.             out.println("<TR><TD>Line Separator</TD><TD>" + System.getProperty("line.separator") + "</TD></TR>");
  139.             out.println("<TR><TD>User Name</TD><TD>" + System.getProperty("user.name") + "</TD></TR>");
  140.             out.println("<TR><TD>User Home Directory</TD><TD>" + System.getProperty("user.home") + "</TD></TR>");
  141.             out.println("<TR><TD>Current Working Directory</TD><TD>" + System.getProperty("user.dir") + "</TD></TR>");
  142.             out.println("<TR><TD>User Language</TD><TD>" + System.getProperty("user.language") + "</TD></TR>");
  143.             out.println("<TR><TD>User Region</TD><TD>" + System.getProperty("user.region") + "</TD></TR>");
  144.             out.println("<TR><TD>User Timezone</TD><TD>" + System.getProperty("user.timezone") + "</TD></TR>");
  145.             out.println("<TR><TD>File Encoding</TD><TD>" + System.getProperty("file.encoding") + "</TD></TR>");
  146.             out.println("<TR><TD>File Encoding Package</TD><TD>" + System.getProperty("file.encoding.pkg") + "</TD></TR>");
  147.  
  148.             Enumeration propKeys = System.getProperties().keys();
  149.             while ( propKeys.hasMoreElements() )
  150.             {
  151.                 String key = (String)propKeys.nextElement();
  152.                 if ( !key.equals("os.name") &&
  153.                      !key.equals("os.version") &&
  154.                      !key.equals("os.arch") &&
  155.                      !key.equals("java.version") &&
  156.                      !key.equals("java.vendor") &&
  157.                      !key.equals("java.vendor.url") &&
  158.                      !key.equals("java.class.version") &&
  159.                      !key.equals("java.home") &&
  160.                      !key.equals("java.compiler") &&
  161.                      !key.equals("java.class.path") &&
  162.                      !key.equals("file.separator") &&
  163.                      !key.equals("path.separator") &&
  164.                      !key.equals("line.separator") &&
  165.                      !key.equals("user.name") &&
  166.                      !key.equals("user.home") &&
  167.                      !key.equals("user.dir") &&
  168.                      !key.equals("user.language") &&
  169.                      !key.equals("user.region") &&
  170.                      !key.equals("user.timezone") &&
  171.                      !key.equals("file.encoding") &&
  172.                      !key.equals("file.encoding.pkg") )
  173.                 {
  174.                     String value = System.getProperty(key);
  175.                     out.println("<TR><TD>" + key + "</TD><TD>" + value + "</TD></TR>");
  176.                 }
  177.             }
  178.             out.println("</TABLE>");
  179.             out.println("<HR>");
  180.             out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
  181.             out.println("</BODY></HTML>");
  182.             out.flush();
  183.             out.close();
  184.         }
  185.         else if ( cmd.equalsIgnoreCase("mime") )
  186.         {
  187.             String vhost = req.getParameter("vhost");
  188.  
  189.             ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
  190.             ServletHostInfo vhinfo = engineInfo.getServletHostInfo(vhost);
  191.  
  192.             res.setContentType("text/html");
  193.             PrintWriter out = res.getWriter();
  194.  
  195.             out.println("<HTML><HEAD><TITLE>Mime Table for Virtual Host - " + vhost + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
  196.             out.println("<CENTER><H1>Mime Table for Virtual Host <b><i>" + vhost + "</i></b></H1><HR></CENTER><BR><P>");
  197.  
  198.             out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  199.             out.println("<TR><TH>File Extension</TH><TH>Mime Type</TH></TR>");
  200.             Hashtable mimemap = vhinfo.getMimeMap();
  201.             Enumeration mimeenum = mimemap.keys();
  202.             while ( mimeenum.hasMoreElements() )
  203.             {
  204.                 String ext = (String)mimeenum.nextElement();
  205.                 String type = (String)mimemap.get(ext);
  206.                 out.println("<TR><TD>" + ext + "</TD><TD>" + type + "</TD></TR>");
  207.             }
  208.             out.println("</TABLE>");
  209.             out.println("<HR>");
  210.             out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
  211.             out.println("</BODY></HTML>");
  212.             out.flush();
  213.             out.close();
  214.         }
  215.         else if ( cmd.equalsIgnoreCase("virtualHost") )
  216.         {
  217.             try
  218.             {
  219.                 String name    = req.getParameter("vhost");
  220.                 ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
  221.                 ServletHostInfo hostInfo       = engineInfo.getServletHostInfo(name);
  222.  
  223.                 res.setContentType("text/html");
  224.                 PrintWriter out = res.getWriter();
  225.  
  226.                 out.println("<HTML><HEAD><TITLE>Configuration for Virtual Host " + name + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
  227.                 out.println("<CENTER><H1>Configuration for Virtual Host<b><i> " + name + "</i></B></H1></CENTER><HR>");
  228.  
  229.                 out.println("<TABLE Border=\"2\" WIDTH=\"50%\" BGCOLOR=\"#DDDDFF\">");
  230.                 out.println("<TR><TH>Supported DNS Names (Alias List)</TH></TR>");
  231.                 Enumeration bindings = engineInfo.getHostnameBindingInfos();
  232.                 while ( bindings.hasMoreElements() )
  233.                 {
  234.                     HostnameBindingInfo binding = (HostnameBindingInfo)bindings.nextElement();
  235.                     out.println("<TR><TD>" + binding.getHostname() + "</TD></TR>");
  236.                 }
  237.                 out.println("</TABLE>");
  238.  
  239.                 out.println("<H3><A HREF=\"" + req.getRequestURI() + "?cmd=mime&vhost=" + java.net.URLEncoder.encode(name) + "\">Mime Table</a></H3>");
  240.  
  241.                 Enumeration enum2 = hostInfo.getWebGroupNames();
  242.                 while ( enum2.hasMoreElements() )
  243.                 {
  244.                     String groupName = (String)enum2.nextElement();
  245.                     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>");
  246.                 }
  247.                 out.println("<HR>");
  248.                 out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
  249.                 out.println("</BODY></HTML>");
  250.             }
  251.             catch ( Exception ex )
  252.             {
  253.                 ex.printStackTrace();
  254.             }
  255.         }
  256.         else if ( cmd.equalsIgnoreCase("webapp") )
  257.         {
  258.             String vhost    = req.getParameter("vhost");
  259.             String webgroup = req.getParameter("webgroup");
  260.  
  261.             ServletEngineInfo engineInfo = ServletEngine.getEngine().getInfo();
  262.             ServletHostInfo vhinfo       = engineInfo.getServletHostInfo(vhost);
  263.             WebGroupInfo wgInfo          = vhinfo.getWebGroupInfo(webgroup);
  264.             WebAppInfo appInfo           = wgInfo.getWebAppInfo();
  265.  
  266.             String serverName = req.getServerName() + ":" + req.getServerPort();
  267.  
  268.             Enumeration hnames = engineInfo.getHostnameBindingInfos();
  269.             while ( hnames.hasMoreElements() )
  270.             {
  271.                 HostnameBindingInfo bindingInfo = (HostnameBindingInfo)hnames.nextElement();
  272.                 if ( bindingInfo.getServletHostName().equals(vhost) )
  273.                 {
  274.                     if ( !bindingInfo.getHostname().equals("localhost") )
  275.                     {
  276.                         serverName = bindingInfo.getHostname();
  277.                         break;
  278.                     }
  279.                 }
  280.             }
  281.  
  282.             res.setContentType("text/html");
  283.             PrintWriter out = res.getWriter();
  284.  
  285.             try
  286.             {
  287.                 out.println("<HTML><HEAD><TITLE>Configuration for " + webgroup + "</TITLE></HEAD><BODY BGCOLOR=\"#C0C0C0\">");
  288.                 out.println("<H1><CENTER>Configuration for Web Application <i><b>" + webgroup + "</i></b></CENTER></H1><HR>");
  289.  
  290.                 out.println("<H2>Web Application Settings</H2>");
  291.                 out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  292.                 out.println("<TR><TD><B>Description:</B></TD><TD>"                  + appInfo.getDescription() + "</TD></TR>");
  293.                 out.println("<TR><TD><B>Virtual Host:</B></TD><TD>"                 + vhost + "</TD></TR>");
  294.                 out.println("<TR><TD><B>Engine:</B></TD><TD>"                       + engineInfo.getName() + "</TD></TR>");
  295.                 out.println("<TR><TD><B>Document Root:</B></TD><TD>"                + wgInfo.getDocumentRoot() + "</TD></TR>");
  296.                 out.println("<TR><TD><B>Classpath:</B></TD><TD>"                    + wgInfo.getClasspath() + "</TD></TR>");
  297.                 out.println("<TR><TD><B>Root URI:</B></TD><TD>"                     + wgInfo.getRootURI() + "</TD></TR>");
  298.                 out.println("<TR><TD><B>Shared Context In Use:</B></TD><TD>"        + wgInfo.isSharedContext() + "</TD></TR>");
  299.                 out.println("<TR><TD><B>Shared Context JNDI Name:</B></TD><TD>"     + wgInfo.getSharedContextJNDIName() + "</TD></TR>");
  300.                 out.println("<TR><TD><B>Auto reload:</B></TD><TD>"                  + wgInfo.isAutoReload() + "</TD></TR>");
  301.                 out.println("<TR><TD><B>Auto reload polling interval:</B></TD><TD>" + wgInfo.getAutoReloadPollingInterval() / 1000 + " seconds</TD></TR>");
  302.                 out.println("<TR><TD><B>Error Page:</B></TD><TD>"                   + appInfo.getErrorPage() + "</TD></TR>");
  303.                 out.println("</TABLE>");
  304.  
  305.                 out.println("<H2>Web Application Attributes</H2>");
  306.                 out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  307.                 out.println("<TR><TH>Attribute Name</TH><TH>Type</TH><TH>Value</TH></TR>");
  308.                 Enumeration ae = appInfo.getAttributeNames();
  309.                 while ( ae.hasMoreElements() )
  310.                 {
  311.                     String name = (String)ae.nextElement();
  312.                     AttributeInfo attrInfo = appInfo.getAttributeInfo(name);
  313.  
  314.                     out.println("<TR>");
  315.                     out.println("<TD><B>" + attrInfo.getName() + "</B></TD>");
  316.                     out.println("<TD>" + attrInfo.getType() + "</TD>");
  317.  
  318.                     if ( attrInfo.getType().equals(AttributeInfo.TYPE_STRING) )
  319.                     {
  320.                         out.println("<TD>" + attrInfo.getString() + "</TD>");
  321.                     }
  322.                     else
  323.                     {
  324.                         out.println("<TD>" + attrInfo.getBeanInfo().toString() + "</TD>");
  325.                     }
  326.                     out.println("</UL></TD></TR>");
  327.                 }
  328.                 out.println("</TABLE>");
  329.  
  330.                 out.println("<H2>Mime Filters</H2>");
  331.                 out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  332.                 out.println("<TR><TH>Mime Type</TH><TH>Servlet Name</TH></TR>");
  333.                 Enumeration me = appInfo.getMimeFilterTypes();
  334.                 while ( me.hasMoreElements() )
  335.                 {
  336.                     String name = (String)me.nextElement();
  337.                     MimeFilterInfo mimeInfo = appInfo.getMimeFilterInfo(name);
  338.  
  339.                     out.println("<TR>");
  340.                     out.println("<TD><B>" + mimeInfo.getMimeType() + "</B></TD>");
  341.                     out.println("<TD>" + mimeInfo.getServletName() + "</TD>");
  342.                     out.println("</UL></TD></TR>");
  343.                 }
  344.                 out.println("</TABLE>");
  345.  
  346.                 out.println("<H2>Servlet Information</H2>");
  347.                 out.println("<TABLE Border=\"2\" WIDTH=\"100%\" BGCOLOR=\"#DDDDFF\">");
  348.                 out.println("<TR><TH>Name</TH><TH>Description</TH><TH>Code</TH><TH>Auto-start</TH><TH>Init Parameters</TH><TH>Paths</TH></TR>");
  349.                 Enumeration e1 = appInfo.getServletNames();
  350.                 while ( e1.hasMoreElements() )
  351.                 {
  352.                     out.println("<TR>");
  353.                     String servletName = (String)e1.nextElement();
  354.                     ServletInfo sinfo = appInfo.getServletInfoByName(servletName);
  355.                     out.println("<TD><B>" + sinfo.getName() + "</B></TD>");
  356.                     out.println("<TD>" + sinfo.getDescription() + "</TD>");
  357.  
  358.                     String code = sinfo.getCode();
  359.                     if ( code.lastIndexOf(".") != -1 )
  360.                     {
  361.                         String codePkg = code;
  362.                         code = code.substring(code.lastIndexOf(".") + 1);
  363.                         codePkg = codePkg.substring(0, codePkg.lastIndexOf("."));
  364.                         out.println("<TD><B>" + code + "</B><BR><font size=-1>" + codePkg + "</font></TD>");
  365.                     }
  366.                     else
  367.                     {
  368.                         out.println("<TD><B>" + code + "</B></TD>");
  369.                     }
  370.  
  371.                     out.println("<TD>" + sinfo.isAutostart() + "</TD>");
  372.                     out.println("<TD><UL>");
  373.                     Enumeration e2 = sinfo.getInitParameterNames();
  374.                     while ( e2.hasMoreElements() )
  375.                     {
  376.                         String initName = (String)e2.nextElement();
  377.                         out.println("<LI>" + initName + ": " + sinfo.getInitParameter(initName));
  378.                     }
  379.                     out.println("</UL></TD>");
  380.  
  381.                     out.println("<TD><UL>");
  382.                     Enumeration e3 = sinfo.getServletPaths();
  383.                     while ( e3.hasMoreElements() )
  384.                     {
  385.                         String path = (String)e3.nextElement();
  386.                         String ref = "http://" + serverName + wgInfo.getRootURI();
  387.                         if ( ref.endsWith("/") )
  388.                             ref = ref.substring(0, ref.length() - 1);
  389.  
  390.                         ref += path;
  391.  
  392.                         out.println("<LI>" + path);
  393.                     }
  394.                     out.println("</UL></TD></TR>");
  395.                 }
  396.                 out.println("</TABLE>");
  397.             }
  398.             catch ( Exception ex )
  399.             {
  400.                 ex.printStackTrace();
  401.             }
  402.             out.println("<HR>");
  403.             out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
  404.             out.println("</BODY></HTML>");
  405.             out.flush();
  406.             out.close();
  407.         }
  408.     }
  409. }
  410.