avatar Logo
用日志打印出自己的头像logo
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.net.ConnectException;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.LogManager;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Server;
import org.apache.catalina.security.SecurityConfig;
import org.apache.juli.ClassLoaderLogManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.digester.Digester;
import org.apache.tomcat.util.digester.RuleSet;
import org.apache.tomcat.util.log.SystemLogHandler;
import org.apache.tomcat.util.res.StringManager;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
public class Catalina
{
protected static final StringManager sm = StringManager.getManager("org.apache.catalina.startup");
protected boolean await = false;
protected String configFile = "conf/server.xml";
protected ClassLoader parentClassLoader = Catalina.class.getClassLoader();
protected Server server = null;
protected boolean useShutdownHook = true;
protected Thread shutdownHook = null;
protected boolean useNaming = true;
private static final Log log = LogFactory.getLog(Catalina.class);
public Catalina()
{
setSecurityProtection();
}
public void setConfigFile(String file)
{
this.configFile = file;
}
public String getConfigFile()
{
return this.configFile;
}
public void setUseShutdownHook(boolean useShutdownHook)
{
this.useShutdownHook = useShutdownHook;
}
public boolean getUseShutdownHook()
{
return this.useShutdownHook;
}
public void setParentClassLoader(ClassLoader parentClassLoader)
{
this.parentClassLoader = parentClassLoader;
}
public ClassLoader getParentClassLoader() {
if (this.parentClassLoader != null) {
return this.parentClassLoader;
}
return ClassLoader.getSystemClassLoader();
}
public void setServer(Server server) {
this.server = server;
}
public Server getServer()
{
return this.server;
}
public boolean isUseNaming()
{
return this.useNaming;
}
public void setUseNaming(boolean useNaming)
{
this.useNaming = useNaming;
}
public void setAwait(boolean b) {
this.await = b;
}
public boolean isAwait() {
return this.await;
}
protected boolean arguments(String[] args)
{
boolean isConfig = false;
if (args.length < 1) {
usage();
return false;
}
for (int i = 0; i < args.length; i++)
if (isConfig) {
this.configFile = args[i];
isConfig = false;
} else if (args[i].equals("-config")) {
isConfig = true;
} else if (args[i].equals("-nonaming")) {
setUseNaming(false); } else {
if (args[i].equals("-help")) {
usage();
return false;
}if (!args[i].equals("start"))
{
if (!args[i].equals("configtest"))
{
if (!args[i].equals("stop"))
{
usage();
return false;
}
}
}
}
return true;
}
protected File configFile()
{
File file = new File(this.configFile);
if (!file.isAbsolute()) {
file = new File(Bootstrap.getCatalinaBase(), this.configFile);
}
return file;
}
protected Digester createStartDigester()
{
long t1 = System.currentTimeMillis();
Digester digester = new Digester();
digester.setValidating(false);
digester.setRulesValidation(true);
HashMap fakeAttributes = new HashMap();
ArrayList attrs = new ArrayList();
attrs.add("className");
fakeAttributes.put(Object.class, attrs);
digester.setFakeAttributes(fakeAttributes);
digester.setUseContextClassLoader(true);
digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");
digester.addSetProperties("Server");
digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");
digester.addObjectCreate("Server/GlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");
digester.addSetProperties("Server/GlobalNamingResources");
digester.addSetNext("Server/GlobalNamingResources", "setGlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");
digester.addObjectCreate("Server/Listener", null, "className");
digester.addSetProperties("Server/Listener");
digester.addSetNext("Server/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
digester.addObjectCreate("Server/Service", "org.apache.catalina.core.StandardService", "className");
digester.addSetProperties("Server/Service");
digester.addSetNext("Server/Service", "addService", "org.apache.catalina.Service");
digester.addObjectCreate("Server/Service/Listener", null, "className");
digester.addSetProperties("Server/Service/Listener");
digester.addSetNext("Server/Service/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
digester.addObjectCreate("Server/Service/Executor", "org.apache.catalina.core.StandardThreadExecutor", "className");
digester.addSetProperties("Server/Service/Executor");
digester.addSetNext("Server/Service/Executor", "addExecutor", "org.apache.catalina.Executor");
digester.addRule("Server/Service/Connector", new ConnectorCreateRule());
digester.addRule("Server/Service/Connector", new SetAllPropertiesRule(new String[] { "executor" }));
digester.addSetNext("Server/Service/Connector", "addConnector", "org.apache.catalina.connector.Connector");
digester.addObjectCreate("Server/Service/Connector/Listener", null, "className");
digester.addSetProperties("Server/Service/Connector/Listener");
digester.addSetNext("Server/Service/Connector/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
digester.addRuleSet(new EngineRuleSet("Server/Service/"));
digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
addClusterRuleSet(digester, "Server/Service/Engine/Host/Cluster/");
digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));
digester.addRule("Server/Service/Engine", new SetParentClassLoaderRule(this.parentClassLoader));
addClusterRuleSet(digester, "Server/Service/Engine/Cluster/");
long t2 = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("Digester for server.xml created " + (t2 - t1));
}
return digester;
}
private void addClusterRuleSet(Digester digester, String prefix)
{
Class clazz = null;
Constructor constructor = null;
try {
clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet");
constructor = clazz.getConstructor(new Class[] { String.class });
RuleSet ruleSet = (RuleSet)constructor.newInstance(new Object[] { prefix });
digester.addRuleSet(ruleSet);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("catalina.noCluster", new Object[] { e.getClass().getName() + ": " + e.getMessage() }), e);
}
else if (log.isInfoEnabled())
log.info(sm.getString("catalina.noCluster", new Object[] { e.getClass().getName() + ": " + e.getMessage() }));
}
}
protected Digester createStopDigester()
{
Digester digester = new Digester();
digester.setUseContextClassLoader(true);
digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");
digester.addSetProperties("Server");
digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");
return digester;
}
public void stopServer()
{
stopServer(null);
}
public void stopServer(String[] arguments)
{
if (arguments != null) {
arguments(arguments);
}
Server s = getServer();
File file;
Throwable localThrowable4;
if (s == null)
{
Digester digester = createStopDigester();
file = configFile();
try { FileInputStream fis = new FileInputStream(file); localThrowable4 = null;
try { InputSource is = new InputSource(file.toURI().toURL().toString());
is.setByteStream(fis);
digester.push(this);
digester.parse(is);
}
catch (Throwable localThrowable1)
{
localThrowable4 = localThrowable1; throw localThrowable1;
}
finally
{
if (fis != null) if (localThrowable4 != null) try { fis.close(); } catch (Throwable x2) { localThrowable4.addSuppressed(x2); } else fis.close();
} } catch (Exception e) { log.error("Catalina.stop: ", e);
System.exit(1); }
}
else
{
try {
s.stop();
} catch (LifecycleException e) {
log.error("Catalina.stop: ", e);
}
return;
}
s = getServer();
if (s.getPort() > 0) {
try { Socket socket = new Socket(s.getAddress(), s.getPort()); file = null;
try { OutputStream stream = socket.getOutputStream();
localThrowable4 = null;
try {
String shutdown = s.getShutdown();
for (int i = 0; i < shutdown.length(); i++) {
stream.write(shutdown.charAt(i));
}
stream.flush();
}
catch (Throwable localThrowable2)
{
localThrowable4 = localThrowable2; throw localThrowable2; } finally { } } catch (Throwable localThrowable3) { file = localThrowable3; throw localThrowable3;
}
finally
{
if (socket != null) if (file != null) try { socket.close(); } catch (Throwable x2) { file.addSuppressed(x2); } else socket.close();
} } catch (ConnectException ce) { log.error(sm.getString("catalina.stopServer.connectException", new Object[] { s.getAddress(), String.valueOf(s.getPort()) }));
log.error("Catalina.stop: ", ce);
System.exit(1);
} catch (IOException e) {
log.error("Catalina.stop: ", e);
System.exit(1);
}
} else {
log.error(sm.getString("catalina.stopServer"));
System.exit(1);
}
}
public void load()
{
long t1 = System.nanoTime();
initDirs();
initNaming();
Digester digester = createStartDigester();
InputSource inputSource = null;
InputStream inputStream = null;
File file = null;
try {
file = configFile();
inputStream = new FileInputStream(file);
inputSource = new InputSource(file.toURI().toURL().toString());
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("catalina.configFail", new Object[] { file }), e);
}
}
if (inputStream == null) {
try {
inputStream = getClass().getClassLoader().getResourceAsStream(getConfigFile());
inputSource = new InputSource(getClass().getClassLoader().getResource(getConfigFile()).toString());
}
catch (Exception e)
{
if (log.isDebugEnabled()) {
log.debug(sm.getString("catalina.configFail", new Object[] { getConfigFile() }), e);
}
}
}
if (inputStream == null) {
try {
inputStream = getClass().getClassLoader().getResourceAsStream("server-embed.xml");
inputSource = new InputSource(getClass().getClassLoader().getResource("server-embed.xml").toString());
}
catch (Exception e)
{
if (log.isDebugEnabled()) {
log.debug(sm.getString("catalina.configFail", new Object[] { "server-embed.xml" }), e);
}
}
}
if ((inputStream == null) || (inputSource == null)) {
if (file == null) {
log.warn(sm.getString("catalina.configFail", new Object[] { getConfigFile() + "] or [server-embed.xml]" }));
}
else {
log.warn(sm.getString("catalina.configFail", new Object[] { file.getAbsolutePath() }));
if ((file.exists()) && (!file.canRead())) {
log.warn("Permissions incorrect, read permission is not allowed on the file.");
}
}
return;
}
try
{
inputSource.setByteStream(inputStream);
digester.push(this);
digester.parse(inputSource);
} catch (SAXParseException spe) { log.warn("Catalina.start using " + getConfigFile() + ": " + spe.getMessage());
return;
} catch (Exception e) { log.warn("Catalina.start using " + getConfigFile() + ": ", e);
return;
}
finally {
try {
inputStream.close();
}
catch (IOException localIOException3)
{
}
}
getServer().setCatalina(this);
getServer().setCatalinaHome(Bootstrap.getCatalinaHomeFile());
getServer().setCatalinaBase(Bootstrap.getCatalinaBaseFile());
initStreams();
try
{
getServer().init();
} catch (LifecycleException e) {
if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) {
throw new Error(e);
}
log.error("Catalina.start", e);
}
long t2 = System.nanoTime();
if (log.isInfoEnabled())
log.info("Initialization processed in " + (t2 - t1) / 1000000L + " ms");
}
public void load(String[] args)
{
try
{
if (arguments(args))
load();
}
catch (Exception e) {
e.printStackTrace(System.out);
}
}
public void start()
{
if (getServer() == null) {
load();
}
if (getServer() == null) {
log.fatal("Cannot start server. Server instance is not configured.");
return;
}
long t1 = System.nanoTime();
try
{
getServer().start();
} catch (LifecycleException e) {
log.fatal(sm.getString("catalina.serverStartFail"), e);
try {
getServer().destroy();
} catch (LifecycleException e1) {
log.debug("destroy() failed for failed Server ", e1);
}
return;
}
long t2 = System.nanoTime();
if (log.isInfoEnabled()) {
log.info(" .:=+=======+=====+==++=." );
log.info(" ===+=======+===+=======++:");
log.info(" :+===============+=+=======++.");
log.info(" :====+++====================.");
log.info( " :==::::=:..::::=:==+=====+::");
log.info( " .=.:. ..::::==");
log.info( " :::. ...:. ....:=.");
log.info( " =::. . ....:..: ..::=.");
log.info( " ::.. .:.:. . .: . ::+");
log.info( " .= ::=== . ....:.......==");
log.info( " ...= .. ...: :. .:::==:..=.: . .");
log.info( " . .. . : .:.:. =+ . ..:... .:. . ... . ..");
log.info( " .. ... .... ::.. =.:. .::. .: . .. .:....");
log.info( " :.:...... .... :=:. .. . :.. ....: .. :. ..");
log.info( " . . . .. ....... ::.:. :.. .:.. . .:. . .");
log.info( " ..: .:.. . . .:.. .. .: .:. ..: ... .... .");
log.info( " . ..: ........ : .:. .. .: :::.: . .. ...... .");
log.info( " . . ..... : :... : :. . :. .. ..: . ...");
log.info( " . . .. .. .:.. . . . .::. =: . . .");
log.info( " :: . .:. . . . ..::: . :+=. . . .");
log.info( " :. . .. . .. .:..... . . :.:.::: .. +*. .... ..");
log.info( " . .:... .:: :...... . . ...=:.=. .=: .. .");
log.info( " .. :..... . . . ::.:. .. .");
log.info( " :::: .. . ::. . . . ..");
log.info( " . : .::. .: . . ..");
log.info( " . . . .= .. .:. :. . . .");
log.info( " . . .. ... .... =: .");
log.info( " . .:.= . .. .=:. ..");
log.info( " . .::.:. . . .. ..");
log.info( " . .:...::. :. .. .. .. .");
log.info( " .......... .:::.... : . . .:. ........::.");
log.info( " ............. .::....... . ... . :.............:.");
log.info( " ...... .:::........ .. .. ...:.. ......:::");
log.info( " ...... .::....:.....:.. .. .:....:::::....:");
log.info( " ...... .:............. .. . .: .. .:.:.:...:::.....:");
log.info( " ..... .::......... ... .. .. . . .. .: ..:. .:......::::....:");
log.info( ".... .:........::. .: . .. . : .. .......:..::...:.:.");
log.info( ":. .:....... ........ :. . . =:..........:.:::::.:::");
log.info("Server startup in " + (t2 - t1) / 1000000L + " ms");
}
if (this.useShutdownHook) {
if (this.shutdownHook == null) {
this.shutdownHook = new CatalinaShutdownHook();
}
Runtime.getRuntime().addShutdownHook(this.shutdownHook);
LogManager logManager = LogManager.getLogManager();
if ((logManager instanceof ClassLoaderLogManager)) {
((ClassLoaderLogManager)logManager).setUseShutdownHook(false);
}
}
if (this.await) {
await();
stop();
}
}
public void stop()
{
try
{
if (this.useShutdownHook) {
Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
LogManager logManager = LogManager.getLogManager();
if ((logManager instanceof ClassLoaderLogManager))
((ClassLoaderLogManager)logManager).setUseShutdownHook(true);
}
}
catch (Throwable t)
{
ExceptionUtils.handleThrowable(t);
}
try
{
Server s = getServer();
LifecycleState state = s.getState();
if ((LifecycleState.STOPPING_PREP.compareTo(state) > 0) || (LifecycleState.DESTROYED.compareTo(state) < 0))
{
s.stop();
s.destroy();
}
} catch (LifecycleException e) {
log.error("Catalina.stop", e);
}
}
public void await()
{
getServer().await();
}
protected void usage()
{
System.out.println("usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help | start | stop }");
}
protected void initDirs()
{
String temp = System.getProperty("java.io.tmpdir");
if ((temp == null) || (!new File(temp).isDirectory()))
log.error(sm.getString("embedded.notmp", new Object[] { temp }));
}
protected void initStreams()
{
System.setOut(new SystemLogHandler(System.out));
System.setErr(new SystemLogHandler(System.err));
}
protected void initNaming()
{
if (!this.useNaming) {
log.info("Catalina naming disabled");
System.setProperty("catalina.useNaming", "false");
} else {
System.setProperty("catalina.useNaming", "true");
String value = "org.apache.naming";
String oldValue = System.getProperty("java.naming.factory.url.pkgs");
if (oldValue != null) {
value = value + ":" + oldValue;
}
System.setProperty("java.naming.factory.url.pkgs", value);
if (log.isDebugEnabled()) {
log.debug("Setting naming prefix=" + value);
}
value = System.getProperty("java.naming.factory.initial");
if (value == null) {
System.setProperty("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
}
else
{
log.debug("INITIAL_CONTEXT_FACTORY already set " + value);
}
}
}
protected void setSecurityProtection()
{
SecurityConfig securityConfig = SecurityConfig.newInstance();
securityConfig.setPackageDefinition();
securityConfig.setPackageAccess();
}
protected class CatalinaShutdownHook extends Thread
{
protected CatalinaShutdownHook()
{
}
public void run()
{
try
{
if (Catalina.this.getServer() != null)
Catalina.this.stop();
}
catch (Throwable ex)
{
LogManager logManager;
ExceptionUtils.handleThrowable(ex);
Catalina.log.error(Catalina.sm.getString("catalina.shutdownHookFail"), ex);
}
finally
{
LogManager logManager;
LogManager logManager = LogManager.getLogManager();
if ((logManager instanceof ClassLoaderLogManager))
((ClassLoaderLogManager)logManager).shutdown();
}
}
}
}
avatar Logo的更多相关文章
- 博客 博客vno主题(我正在用的这个博客主题)
将你自己博客园博客的主题设置为lessismore, #divRefreshComments { text-align: right; margin-right: 10px; margin-botto ...
- Vno博客样式分享
不知不觉有一年多没有更新博客了,还是几位园友因为喜欢这套博客样式发了消息,否则我都快忘记自己还有一个博客了,哈哈. 言归正传,这套博客样式是当时闲来无事copy的iOS界喵神的博客Vno,确实很漂亮, ...
- 将Temporary文件夹里的Logo文件转移到Logo文件夹
/// <summary> /// 将Temporary文件夹里的Logo文件转移到Logo文件夹 /// </summary> /// <param name=&quo ...
- php实现自定义中间logo的微信小程序码
小程序码生成的时候是默认使用小程序后台设置的小程序icon图片的,但是在有些场景我们可能要替换成我们自己想要的icon. 下面先放代码: public function makeNewQrCodeAc ...
- Three.js实现脸书元宇宙3D动态Logo
背景 Facebook 近期将其母公司改名为 Meta,宣布正式开始进军 元宇宙 领域.本文主要讲述通过 Three.js + Blender 技术栈,实现 Meta 公司炫酷的 3D 动态 Logo ...
- javaScript生成二维码(支持中文,生成logo)
资料搜索 选择star最多的两个 第一个就是用的比较多的jquery.qrcode.js(但不支持中文,不能带logo)啦,第二个支持ie6+,支持中文,根据第二个源代码,使得,jquery.qrco ...
- C#生成带logo的二维码
带logo的二维码生成分为两步骤:首先根据输入的内容生成二维码图片,然后读取本地的logo图片,通过图片处理生成带logo的二维码. 生成的二维码效果如下: 下面直接贴出二维码生成类 QRCode ...
- Devexpress Ribbon Add Logo
一直在网上找类似的效果.在Devpexress控件里面的这个是一个Demo的.没法查看源代码.也不知道怎么写的.所以就在网上搜索了半天的. 终于找到类似的解决办法. 可以使用重绘制的办法的来解决. [ ...
- 网站logo正确写法,个人拙见,不喜勿喷
网站logo既要考虑seo又需要用图片代替网站名字,所有H1标签带来的权重还是需要使用 有些人喜欢直接把<H1></H1>标签直接hidden掉,个人喜欢使用css Text- ...
随机推荐
- .bash_profile和.bashrc的区别,ubuntu下为.profile,没有.bash_profile
.bash_profile 开机自动加载,比如java的环境变量放在里面 .bashrc打开shell或终端就会加载该文件,比如起的别名或快捷方式放里面.alias设置就在其中. 还有一个.profi ...
- 如何查看PowerShell版本
Click Start, click All Programs, click Accessories, click Windows PowerShell, and then click Windows ...
- [转]Jenkins CommonCollections 完美利用(演示)工具
博主URL:http://tools.changesec.com/Jenkins-CommonCollections-Exploit/ 提交漏洞总是要证明漏洞危害,老外写的java代码又有bug,所以 ...
- Servlet异常及其生命周期
Servlet 异常 在javax.servlet包中定义了两个异常类 ServletException类 ServletException类定义了一个通用的异常,可以被init().service( ...
- Kazam: a perfect srceen recorder in Linux/Ubuntu
Kazam provides a well designed and easy to use interface for capturing screencasts and screenshots. ...
- Protractor AngularJS测试框架教程
Protractor是一个建立在WebDriverJS基础上的端到端(E2E)的AngularJS JavaScript Web应用程序测试框架.Protractor全自动化真实的模拟用户在真正的浏览 ...
- 在Yii用createUrl中明明白白生成网址
在Yii中经常要生成URL,不管是为了自动跳转还是仅仅是一个链接.下面对Yii中的URL生成做了一个总结.提示:以下controllerX代表控制器X,actionX代表方法X.在Controller ...
- Android中利用SharedPreferences保存信息
package com.example.sharepreferen; import android.content.Context; import android.content.SharedPref ...
- [转载] 深入理解Linux修改hostname
原文: http://www.cnblogs.com/kerrycode/p/3595724.html 当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问 ...
- img、input到底是行内还是块级元素?
一.img.input属于行内替换元素.height/width/padding/margin均可用.效果等于块元素. 行内非替换元素,例如, height/width/padding to ...