📄 net.java
字号:
/*
$Author: $
$Date: $
$Revision: $
$NoKeywords: $
*/
package jp.co.ntl;
import java.applet.Applet;
import java.io.*;
import java.net.*;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.KeyManagementException;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509KeyManager;
import javax.net.ssl.X509TrustManager;
import jp.co.ntl.ext.GlobalContext;
public class Net implements NetConstants {
public final static int CONNCTION_MAX_RETRY_COUNT = 20;
public final static int CONNECTION_CHECK_PERIOD = 500;
private static Applet applet;
static int counter = 0;
static private Net net = null;
private String sessionId;
private String docBase = null;
//僄儞僐乕僪偼攑巭偐傕
/* private Net(Applet applet) {
this(applet, null);
}*/
private Net(Applet applet, String sessionId, String docBase) {
Net.applet = applet;
this.sessionId = sessionId;
this.docBase = docBase;
}
static public Net makeInstance(Applet applet) {
return makeInstance(applet, null);
}
static public Net makeInstance(Applet applet, String sessionId) {
net = new Net(applet, sessionId, null);
return net;
}
static public Net makeInstance(String docBase) {
net = new Net(null, null, docBase);
return net;
}
static public Net getInstance() {
return net;
}
/**
* 俫俿俵俴僼傽僀儖傪昞帵偡傞
* @param filename html僼傽僀儖柤
* @param target _blank, _self, _top側偳偺僞乕僎僢僩柤
*/
/*
public boolean showPage(String filename, String target) {
try {
URL url = new URL(applet.getDocumentBase(), filename);
applet.getAppletContext().showDocument(url, target);
applet.showStatus ("");
}
catch (Exception e) {
applet.showStatus ("Exception: " + e);
return false;
}
return true;
}
*/
/**
* 僼傽僀儖傪僟僂儞儘乕僪偡傞
* @param filename 僼傽僀儖柤
*/
public boolean download(String filename) {
if (!isApplication()) {
try {
URL url = new URL(applet.getDocumentBase(), filename);
applet.getAppletContext().showDocument(url);
applet.showStatus ("");
}
catch (Exception e) {
applet.showStatus ("Exception: " + e);
return false;
}
}
return true;
}
/**
* 僼傽僀儖傪僟僂儞儘乕僪偡傞
* @param module 僼傽僀儖柤
*/
public boolean download(String module, String argument) {
if (!isApplication()) {
try {
String file = module + (sessionId != null ? ";jsessionid=" + sessionId : "");
if (argument != null) {
file += "?" + argument;
}
URL url = new URL(applet.getDocumentBase(), file);
applet.getAppletContext().showDocument(url);
applet.showStatus ("");
}
catch (Exception e) {
applet.showStatus ("Exception: " + e);
return false;
}
}
return true;
}
/**
* 僒乕僶乕忋偺儌僕儏乕儖偵僐儅儞僪傪幚峴偝偣偰丄寢壥傪庢摼偡傞
* @param module 僼傽僀儖柤
* @param argument 僐儅儞僪偺堷悢
* @param target _blank, _self, _top側偳偺僞乕僎僢僩柤
*/
public boolean showPage(String module, String argument, String target) {
if (!isApplication()) {
try {
String file = module + (sessionId != null ? ";jsessionid=" + sessionId : "");
if (argument != null) {
file += "?" + argument;
}
URL url = new URL(applet.getDocumentBase(), file);
applet.getAppletContext().showDocument(url, target);
} catch (Exception e) {
applet.showStatus ("Exception: " + e);
return false;
}
}
return true;
}
public boolean showPage(String file, String target) {
if (!isApplication()) {
try {
URL url = new URL(applet.getDocumentBase(), file);
applet.getAppletContext().showDocument(url, target);
} catch (Exception e) {
applet.showStatus ("Exception: " + e);
return false;
}
}
return true;
}
/**
* Login儁乕僕傪昞帵偡傞
*/
public void showLoginPage() {
if (!isApplication()) {
try {
//URL url = new URL(applet.getDocumentBase(), "Page?page=login.jsp");
URL docBase = applet.getDocumentBase();
String protocol = docBase.getProtocol();
String host = docBase.getHost();
URL url = new URL(protocol, host, "");
applet.getAppletContext().showDocument(url, "_top");
applet.showStatus("");
} catch (Exception e) {
applet.showStatus ("Exception: " + e);
return;
}
} else {
System.out.println("Session close");
}
return;
}
/**
* 僒乕僶乕忋偺儌僕儏乕儖偵僐儅儞僪傪幚峴偝偣偰丄寢壥傪庢摼偡傞
* @param module 僼傽僀儖柤
* @param command 僐儅儞僪(娭悢柤)
* @return
*/
public InputStream sendCommand(String module, String command)
throws IOException, UnknownServiceException, NoSuchAlgorithmException, KeyManagementException {
URL url = getURL(module);
if (isApplication() && isHttps(url)) {
return connectHttps(url, command, null);
} else {
return connectHttp(url, command, null);
}
}
/**
* 僒乕僶乕忋偺儌僕儏乕儖偵僐儅儞僪傪幚峴偝偣偰丄寢壥傪庢摼偡傞
* @param module 僼傽僀儖柤
* @param command 僐儅儞僪(娭悢柤)
* @param argument 僐儅儞僪偺堷悢
* @return
*/
public InputStream sendCommand(String module, String command, String argument)
throws IOException, UnknownServiceException, NoSuchAlgorithmException, KeyManagementException {
URL url = getURL(module);
if (isApplication() && isHttps(url)) {
return connectHttps(url, command, argument);
} else {
return connectHttp(url, command, argument);
}
}
/**
* 僒乕僶乕忋偺儌僕儏乕儖偵僐儅儞僪傪幚峴偝偣偰丄寢壥傪庢摼偡傞
* @param module 僼傽僀儖柤
* @param command 僐儅儞僪(娭悢柤)
* @param argument 僐儅儞僪偺堷悢
* @return
*/
public InputStream sendCommand(String module, String command, Object argument)
throws IOException, UnknownServiceException, NoSuchAlgorithmException, KeyManagementException {
URL url = getURL(module);
if (isApplication() && isHttps(url)) {
return connectHttps(url, command, argument);
} else {
return connectHttp(url, command, argument);
}
}
public InputStream sendCommand(String module, String command, URL host, String passwd)
throws IOException, UnknownServiceException {
URL url = new URL(host, module + (sessionId != null ? ";jsessionid=" + sessionId : ""));
URLConnection connection = url.openConnection();
if (!passwd.equals("")) {
connection.setRequestProperty("Authorization", "Basic " + passwd);
}
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/octet-stream");
ObjectOutputStream os = new ObjectOutputStream(connection.getOutputStream());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -