com
@@ -3,4 +3,6 @@ | ||
3 | 3 | userSecury=false |
4 | 4 | compress=gzip |
5 | 5 | |
6 | -port=80 | |
\ No newline at end of file | ||
6 | +port=8080 | |
7 | + | |
8 | +loadInit=./config/database.ini | |
\ No newline at end of file |
@@ -3,6 +3,7 @@ | ||
3 | 3 | import servercore.statics.StaticValues; |
4 | 4 | import servercore.statics.StaticsMeothds; |
5 | 5 | import servercore.tcp.TcpServer; |
6 | +import extension.file.EasyIni; | |
6 | 7 | import extension.file.LogWriter; |
7 | 8 | |
8 | 9 | public class HttpServer extends Thread implements StaticValues{ |
@@ -18,6 +19,8 @@ | ||
18 | 19 | |
19 | 20 | private static String useCompress = null; |
20 | 21 | |
22 | + private static EasyIni loadedIni = null; | |
23 | + | |
21 | 24 | /** |
22 | 25 | * 接続ポート番号を設定 |
23 | 26 | * @param portNum |
@@ -81,6 +84,18 @@ | ||
81 | 84 | return useCompress; |
82 | 85 | } |
83 | 86 | |
87 | + public static void setLoadIni(EasyIni ini) { | |
88 | + if(isRunning) { | |
89 | + System.err.println("Server is running"); | |
90 | + return; | |
91 | + } | |
92 | + if(ini != null) { | |
93 | + loadedIni = ini; | |
94 | + } | |
95 | + } | |
96 | + public static String getLoadedIniValue(String key) { | |
97 | + return loadedIni.getPro(key); | |
98 | + } | |
84 | 99 | public void run() { |
85 | 100 | LogWriter log = new LogWriter(httpServerLogPath); |
86 | 101 | TcpServer server = new TcpServer(); |
@@ -0,0 +1,207 @@ | ||
1 | +package event; | |
2 | + | |
3 | +import java.awt.Graphics; | |
4 | +import java.awt.TextField; | |
5 | +import java.awt.Label; | |
6 | +import java.awt.event.ActionEvent; | |
7 | +import java.awt.event.ActionListener; | |
8 | +import java.awt.event.WindowAdapter; | |
9 | +import java.awt.event.WindowEvent; | |
10 | + | |
11 | +import javax.swing.JButton; | |
12 | +import javax.swing.JFrame; | |
13 | + | |
14 | +import java.util.Map; | |
15 | + | |
16 | +//import http.HttpServer; | |
17 | +//import lib.property.EasyIni; | |
18 | +/** | |
19 | + * サーバーを操作するGUI | |
20 | + */ | |
21 | +public class MainView extends JFrame implements ActionListener { | |
22 | + private static final long serialVersionUID = 1L; | |
23 | + | |
24 | +// /** 設定情報を管理 */ | |
25 | +// EasyIni iniObj = null; | |
26 | + | |
27 | + /** 環境変数(未使用) */ | |
28 | + private static Map systemEnv = null; | |
29 | + /** Java環境(未使用) */ | |
30 | + private static Map systemPro = null; | |
31 | + | |
32 | +// private HttpServer server = null; | |
33 | + | |
34 | + /** 開始・停止スイッチ切り替え */ | |
35 | + boolean btn = true; | |
36 | + | |
37 | + /** プロキシ接続切り替え */ | |
38 | + boolean pryFlg = false; | |
39 | + | |
40 | + /** ポート番号を入力するフィールド */ | |
41 | + TextField inputPort = new TextField(""); | |
42 | + /** ルートディレクトリのパス */ | |
43 | + TextField inputRootDirectory = new TextField(""); | |
44 | + /** ルートディレクトリのパス */ | |
45 | + TextField inputConfigDirectory = new TextField(""); | |
46 | + /** プロキシ接続するパス */ | |
47 | + TextField inputProxyPath = new TextField(""); | |
48 | + JButton BtnStt = new JButton("接続を開始"); | |
49 | + JButton BtnPcy = new JButton("プロキシ使用する"); | |
50 | + | |
51 | + Label rootLabel = new Label("ルートディレクトリ"); | |
52 | + Label configLabel = new Label("設定ファイルパス"); | |
53 | + Label portLabel = new Label("ポート番号"); | |
54 | + Label proxyLabel = new Label("プロキシ接続パス"); | |
55 | + /** | |
56 | + * イベント発生時のメソッド | |
57 | + */ | |
58 | + public void actionPerformed(ActionEvent e) { | |
59 | + // 開始ボタン押下 | |
60 | + if(e.getSource() == BtnStt) { | |
61 | + // サーバーの開始 | |
62 | + if(btn){ | |
63 | +// if(server == null){ | |
64 | +// BtnStt.setText("接続の停止"); | |
65 | +// | |
66 | +// server = new HttpServer(); | |
67 | +// server.setPortNum(inputPort.getText()); | |
68 | +// server.setRootDirPath(inputRootDirectory.getText()); | |
69 | +// server.setConfigFilePath(inputConfigDirectory.getText()); | |
70 | +// | |
71 | +// String str = inputProxyPath.getText(); | |
72 | +// str = str.replaceAll("http\\:\\/\\/", ""); | |
73 | +// str = str.replaceAll("\\/", ""); | |
74 | +// String[] s = str.split("\\:"); | |
75 | +// server.setProxyHost(s[0]); | |
76 | +// server.setProxyPortNum(s[1]); | |
77 | +// server.setPcyFlag(pryFlg); | |
78 | +// | |
79 | +// // サーバースレッドを実行する | |
80 | +// server.start(); | |
81 | +// btn = false; | |
82 | +// } | |
83 | + } | |
84 | + // サーバーの停止要求 | |
85 | + else{ | |
86 | +// BtnStt.setText("接続の開始"); | |
87 | +// | |
88 | +// // 停止命令を送る | |
89 | +// server.doStop = false; | |
90 | +// | |
91 | +// // 1秒待ってもサーバー終了されないときはエラー | |
92 | +// for(int i = 0; i < 100; i++){ | |
93 | +// try { | |
94 | +// Thread.sleep(10); | |
95 | +// } catch (InterruptedException e1) {} | |
96 | +// if(!server.isAlive()) { | |
97 | +// server = null; | |
98 | +// break; | |
99 | +// } | |
100 | +// } | |
101 | +// if(server != null && server.isAlive()) { | |
102 | +// System.out.println("サーバーソケットの終了に失敗した模様"); | |
103 | +// } else { | |
104 | +// btn = true; | |
105 | +// } | |
106 | + } | |
107 | + } | |
108 | + // プロキシボタン押下 | |
109 | + if(e.getSource() == BtnPcy) { | |
110 | + if(pryFlg) { | |
111 | + inputProxyPath.disable(); | |
112 | + BtnPcy.setText("プロキシ使用する"); | |
113 | + pryFlg = false; | |
114 | + } else { | |
115 | + inputProxyPath.enable(); | |
116 | + BtnPcy.setText("プロキシ使用しない"); | |
117 | + pryFlg = true; | |
118 | + } | |
119 | + } | |
120 | + } | |
121 | + // 閉じるボタンが押されたら | |
122 | + class ClosingWindowListener extends WindowAdapter { | |
123 | + public void windowClosing(WindowEvent e) { | |
124 | + try { | |
125 | +// if(server != null) { | |
126 | +// server.doStop = false; | |
127 | +// } | |
128 | + } catch(Exception ex) { | |
129 | + ex.printStackTrace(); | |
130 | + } | |
131 | + System.exit(0); | |
132 | + } | |
133 | + } | |
134 | + public void paintComponent(Graphics g) { | |
135 | + } | |
136 | + public MainView() { | |
137 | +// iniObj = new EasyIni("./config/web_server.ini"); | |
138 | +// String irDir = iniObj.getPro("irDir"); | |
139 | +// String icDir = iniObj.getPro("icDir"); | |
140 | +// | |
141 | +// addWindowListener(new ClosingWindowListener()); | |
142 | +// | |
143 | +// //入力用のテキストフィールド | |
144 | +// inputPort.setBounds(90,10,50,20); | |
145 | +// inputPort.addActionListener(this); | |
146 | +// inputPort.setText("80"); | |
147 | +// this.add(inputPort); | |
148 | +// | |
149 | +// //入力用のテキストフィールド | |
150 | +// inputRootDirectory.setBounds(120,50,400,20); | |
151 | +// inputRootDirectory.addActionListener(this); | |
152 | +// inputRootDirectory.setText(irDir); | |
153 | +// this.add(inputRootDirectory); | |
154 | +// | |
155 | +// //入力用のテキストフィールド | |
156 | +// inputConfigDirectory.setBounds(120,100,400,20); | |
157 | +// inputConfigDirectory.addActionListener(this); | |
158 | +// inputConfigDirectory.setText(icDir); | |
159 | +// this.add(inputConfigDirectory); | |
160 | +// | |
161 | +// //プロキシパス入力用のテキストフィールド | |
162 | +// inputProxyPath.setBounds(120,150,400,20); | |
163 | +// inputProxyPath.addActionListener(this); | |
164 | +// inputProxyPath.setText("http://localhost:5555/"); | |
165 | +// inputProxyPath.disable(); | |
166 | +// this.add(inputProxyPath); | |
167 | + | |
168 | + //通信制御用のボタン | |
169 | + BtnStt.addActionListener(this); | |
170 | + BtnStt.setBounds(200, 10, 100, 20); | |
171 | + this.add(BtnStt); | |
172 | + | |
173 | + //プロキシ使用のボタン | |
174 | + BtnPcy.addActionListener(this); | |
175 | + BtnPcy.setBounds(310, 10, 160, 20); | |
176 | + this.add(BtnPcy); | |
177 | + | |
178 | + rootLabel.setBounds(10, 50, 110, 20); | |
179 | + this.add(rootLabel); | |
180 | + | |
181 | + configLabel.setBounds(10, 100, 110, 20); | |
182 | + this.add(configLabel); | |
183 | + | |
184 | + portLabel.setBounds(10, 10, 70, 20); | |
185 | + this.add(portLabel); | |
186 | + | |
187 | + proxyLabel.setBounds(10, 150, 110, 20); | |
188 | + this.add(proxyLabel); | |
189 | + | |
190 | + this.setSize(640,250); | |
191 | + getContentPane().setLayout(null); | |
192 | + | |
193 | + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
194 | + setTitle("HTTP Server"); | |
195 | + setVisible(true); | |
196 | + } | |
197 | + /** | |
198 | + * @param args | |
199 | + */ | |
200 | + public static void main(String[] args) { | |
201 | + systemEnv = System.getenv(); | |
202 | + // System.out.println(systemEnv); | |
203 | + systemEnv = System.getProperties(); | |
204 | + // // System.out.println(systemPro); | |
205 | + new MainView(); | |
206 | + } | |
207 | +} |
@@ -10,6 +10,10 @@ | ||
10 | 10 | HttpServer.setRootDirPath(ini.getPro("irDir")); |
11 | 11 | HttpServer.setUseSecurity(ini.getPro("userSecury")); |
12 | 12 | HttpServer.setUseCompress(ini.getPro("compress")); |
13 | + String exIniPath = ini.getPro("loadInit"); | |
14 | + if(exIniPath != null) { | |
15 | + HttpServer.setLoadIni(new EasyIni(exIniPath)); | |
16 | + } | |
13 | 17 | HttpServer server = new HttpServer(); |
14 | 18 | server.start(); |
15 | 19 |
@@ -32,7 +32,7 @@ | ||
32 | 32 | } |
33 | 33 | |
34 | 34 | } catch (Exception e) { |
35 | - e.printStackTrace(); | |
35 | + throw new RuntimeException(e); | |
36 | 36 | } finally { |
37 | 37 | try { |
38 | 38 | fr.close(); |