⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 restartcontextactiondelegate.java

📁 一个学习eclipse插件开发的绝好入门程序
💻 JAVA
字号:
package com.sysdeo.eclipse.tomcat.actions;

/*
 * (c) Copyright Sysdeo SA 2001, 2002.
 * All Rights Reserved.
 */
 

import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;

import com.sysdeo.eclipse.tomcat.TomcatLauncherPlugin;
import com.sysdeo.eclipse.tomcat.TomcatProject;

public class RestartContextActionDelegate extends TomcatProjectAbstractActionDelegate {
	
	public void doActionOn(TomcatProject prj) throws Exception {
		String path = TomcatLauncherPlugin.getDefault().getManagerAppUrl();

		try {
			path += "/reload?path=" + prj.getWebPath();
			URL url = new URL(path);
			Authenticator.setDefault(new Authenticator() {
				protected PasswordAuthentication getPasswordAuthentication() {
					String user = TomcatLauncherPlugin.getDefault().getManagerAppUser();
					String password = TomcatLauncherPlugin.getDefault().getManagerAppPassword();				
					return new PasswordAuthentication(user, password.toCharArray());
				}
			});
				
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();			
			connection.getContent();
			connection.disconnect();
			Authenticator.setDefault(null);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new Exception(
				"The following url was used : \n" + path + 
				"\n\nCheck manager app settings (username and password)\n\n");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -