• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision66 (tree)
Time2010-12-15 13:35:27
Authorhoritaku

Log Message

WebSocket実装途中

Change Summary

Incremental Difference

--- branch/Basic 0.2x/sokect_action/socket_action/Test1.java (revision 0)
+++ branch/Basic 0.2x/sokect_action/socket_action/Test1.java (revision 66)
@@ -0,0 +1,5 @@
1+package socket_action;
2+
3+public class Test1 {
4+
5+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- branch/Basic 0.2x/src/servercore/http/OldHttpRequest.java (revision 65)
+++ branch/Basic 0.2x/src/servercore/http/OldHttpRequest.java (revision 66)
@@ -1,157 +0,0 @@
1-package servercore.http;
2-
3-import java.io.UnsupportedEncodingException;
4-import java.net.URLDecoder;
5-import java.util.*;
6-
7-public class OldHttpRequest {
8- public boolean post = false;
9- private int errorLevel = 0;
10- private String errorMsg = null;
11-
12- private String method = null;
13-
14- private String path = null;
15-
16- private String extension = null;
17-
18- private HashMap<String,String> getParamMap = null;
19-
20- private HashMap<String,String> postParamMap = null;
21-
22- private int keepAliveMillis = 0;
23- public int getErrorLevel() {
24- return errorLevel;
25- }
26- public String getErrorMsg() {
27- return errorMsg;
28- }
29-
30- private String[] getHeadaer(ArrayList<String> requestHeader) {
31- int index = requestHeader.get(0).indexOf("\r\n");
32- if(index < 0) {
33- index = requestHeader.get(0).indexOf("\n");
34- }
35- String header = requestHeader.get(0).substring(0, index);
36- return header.split(" ");
37- }
38- public void setRequestHeader(ArrayList<String> requestHeader) {
39- post = false;
40- if(requestHeader == null || requestHeader.size() == 0) {
41- System.out.println("不正なリクエストです");
42- errorLevel = 400;
43- return;
44- }
45- try {
46- headLineCheck(requestHeader);
47- // リクエストされたファイル名を収得
48- String[] head = getHeadaer(requestHeader);
49-
50- method = head[0];
51- if(method.equals("POST")) {
52- // POSTパラメータを取得
53- int index = requestHeader.get(0).lastIndexOf("\n") + 1;
54- if(index > 0) {
55- postParamMap = splitGetParam(requestHeader.get(0).substring(index));
56- }
57- System.out.println("POST⇒" + postParamMap);
58- post = true;
59- }
60- String[] allPath = head[1].split("\\?");
61- path = allPath[0];
62- path = path.replaceAll("\\/", "\\\\");
63-
64- // GETパラメータを取得
65- if(allPath.length > 1) {
66- getParamMap = splitGetParam(allPath[1]);
67- System.out.println("GET⇒" + getParamMap);
68- }
69-
70- // リクエストが"\\"で終わっていたらindex.htmlを追加
71- if(path.lastIndexOf("\\") == (path.length() - 1)) {
72- path += "index.html";
73- }
74- int index = path.lastIndexOf(".");
75- if(index < 0) {
76- extension = "";
77- } else {
78- extension = path.substring(index,path.length());
79- }
80- //System.out.println("\r\n\r\n");
81- // リクエストが正常に処理されたら200を返す
82- errorLevel = 200;
83- } catch(Exception e) {
84- errorLevel = 400;
85- e.printStackTrace();
86- }
87- }
88- public String getPath() {
89- return path;
90- }
91- public String getExtention() {
92- return extension;
93- }
94- private HashMap<String,String> splitGetParam(String param) {
95- HashMap<String,String> map = new HashMap<String,String>();
96- String[] list = param.split("\\&");
97-
98- try{
99- for(int i = 0;i < list.length;i++) {
100- String[] str = list[i].split("\\=");
101- String key = str[0];
102- if(str.length < 2) {
103- map.put(key, "");
104- } else {
105- String value = str[1];
106- map.put(key, value);
107- }
108- }
109- } catch(Exception e) {
110- e.printStackTrace();
111- }
112- return map;
113- }
114- public String getParam(String key) {
115- if(getParamMap == null) {
116- return null;
117- }
118- return getParamMap.get(key);
119- }
120- public String postParam(String key) {
121- if(postParamMap == null) {
122- return null;
123- }
124- return postParamMap.get(key);
125- }
126- public String postParamDec(String key) {
127- if(postParamMap == null) {
128- return null;
129- }
130- String ret = postParamMap.get(key);
131- if(ret != null) {
132- try {
133- ret = URLDecoder.decode(ret, "utf-8");
134- } catch (UnsupportedEncodingException e) {
135- e.printStackTrace();
136- ret = null;
137- }
138- }
139- return ret;
140- }
141- private void headLineCheck(ArrayList<String> requestHeader) {
142- for(String requestHead:requestHeader) {
143- String[] headers = requestHead.split("\n");
144- for(String line: headers) {
145- String[] str = line.split(":");
146- if(str != null && str.length == 2) {
147- str[0] = str[0].toLowerCase();
148- if("keep-alive".equals(str[0])) {
149- str[1] =str[1].trim();
150- int time = Integer.parseInt(str[1]);
151- keepAliveMillis = time;
152- }
153- }
154- }
155- }
156- }
157-}
--- branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 65)
+++ branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 66)
@@ -2,7 +2,11 @@
22
33 import java.io.File;
44 import java.io.IOException;
5+import java.io.InputStream;
6+import java.io.OutputStream;
57 import java.lang.reflect.Method;
8+import java.security.MessageDigest;
9+import java.security.NoSuchAlgorithmException;
610
711 import lib.io.ByteUtil;
812 import servercore.http.HttpRequest;
@@ -11,6 +15,9 @@
1115
1216 public class GeneratePage {
1317 public static HttpResponse execute(HttpRequest req) {
18+ return execute(req, null, null);
19+ }
20+ public static HttpResponse execute(HttpRequest req, OutputStream ops, InputStream ips) {
1421 File ifThisIsFile = null;
1522 HttpResponse res = new HttpResponse();
1623 String realPath = req.getPath();
@@ -23,6 +30,10 @@
2330 String pkg = "refrect_action" + cgiPath.substring(0, index);
2431 res = executeCgi(req, pkg);
2532 return res;
33+ } else if("ws".equals(ext)) {
34+ int index = cgiPath.indexOf("ws");
35+ String pkg = "socket_action" + cgiPath.substring(0, index);
36+ executeWebSokcet(req, pkg, ops, ips);
2637 }
2738 ifThisIsFile = new File(realPath);
2839 if(!ifThisIsFile.exists()) {
@@ -59,4 +70,12 @@
5970 // 実行する
6071 return (HttpResponse)method.invoke(cls.newInstance(),req);
6172 }
73+ private static void executeWebSokcet(HttpRequest req, String PackageName, OutputStream ops, InputStream ips) throws Exception {
74+ Class<Action> cls = null;
75+
76+ cls = (Class<Action>)Class.forName(PackageName);
77+ Method method = cls.getMethod("execute", HttpRequest.class);
78+ // 実行する
79+ method.invoke(cls.newInstance(),req);
80+ }
6281 }
--- branch/Basic 0.2x/src/servercore/job/WebSocketWorker.java (revision 0)
+++ branch/Basic 0.2x/src/servercore/job/WebSocketWorker.java (revision 66)
@@ -0,0 +1,5 @@
1+package servercore.job;
2+
3+public class WebSocketWorker {
4+
5+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 65)
+++ branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 66)
@@ -34,15 +34,11 @@
3434
3535 System.out.print(req.getMethod() + "\t" + req.getRowPath() + "\t");
3636
37- // ブラウザがWebSocketを要求したとき
38- if("ws".equals(ext)) {
39- websocketHandShake(req, ops, ips);
40- }
4137 HttpResponse res = null;
4238 if(HttpServer.useSecurity()) {
4339 res = security(req);
4440 if(res.getStatusCore() == 200) {
45- res = GeneratePage.execute(req);
41+ res = GeneratePage.execute(req, ops, ips);
4642 }
4743 } else {
4844 res = GeneratePage.execute(req);
--- branch/Basic 0.2x/src/extension/file/LogWriter.java (revision 65)
+++ branch/Basic 0.2x/src/extension/file/LogWriter.java (revision 66)
@@ -6,87 +6,87 @@
66 import java.util.ArrayList;
77
88 public class LogWriter {
9- FileOutputStream logFile = null;
10- /**
11- * コンストラクタ ログファイルのパスが必要
12- * @param logFilePath
13- */
14- public LogWriter(String logFilePath){
15- try {
16- logFile = new FileOutputStream(logFilePath);
17- } catch (FileNotFoundException e1) {
18- e1.printStackTrace();
19- }
20- }
21- /**
22- * ログファイルの開放
23- */
24- public void close() {
25- try {
26- logFile.close();
27- } catch (IOException e1) {
28- e1.printStackTrace();
29- }
30- logFile = null;
31- }
9+ FileOutputStream logFile = null;
10+ /**
11+ * コンストラクタ ログファイルのパスが必要
12+ * @param logFilePath
13+ */
14+ public LogWriter(String logFilePath){
15+ try {
16+ logFile = new FileOutputStream(logFilePath);
17+ } catch (FileNotFoundException e1) {
18+ e1.printStackTrace();
19+ }
20+ }
21+ /**
22+ * ログファイルの開放
23+ */
24+ public void close() {
25+ try {
26+ logFile.close();
27+ } catch (IOException e1) {
28+ e1.printStackTrace();
29+ }
30+ logFile = null;
31+ }
3232
33- /**
34- * ログ出力(テキスト)
35- * @param str
36- */
37- public void logWriteStr(String str) {
38- if(logFile != null) {
39- try {
40- logFile.write((str + "\r\n").getBytes());
41- } catch (IOException e) {
42- e.printStackTrace();
43- }
44- } else {
45- System.err.println("logFile is null");
46- }
47- }
48- /**
49- * ログ出力(バイトのリスト)
50- * @param byteList
51- */
52- public void logWriteByteList(ArrayList<byte[]> byteList) {
53- if(logFile != null) {
54- if(byteList == null) {
55- System.err.println("byteList is null");
56- return;
57- }
58- if(byteList.size() == 0) {
59- byte[] outBuff = "byteList.size=0\r\n".getBytes();
60- byteList.add(outBuff);
61- }
62- try {
63- for(byte[] b: byteList) {
64- logFile.write(b);
65- }
66- logFile.write("\r\n".getBytes());
67- } catch (IOException e) {
68- e.printStackTrace();
69- }
70- } else {
71- System.err.println("logFile is null");
72- }
73- }
74- /**
75- * ログ出力(文字列のリスト型)
76- * @param list
77- */
78- public void logWriteStrList(ArrayList<String> list) {
79- if(logFile != null) {
80- try {
81- for(String str:list) {
82- logFile.write((str + "\r\n").getBytes());
83- }
84- logFile.write("\r\n".getBytes());
85- } catch (IOException e) {
86- e.printStackTrace();
87- }
88- } else {
89- System.err.println("logFile is null");
90- }
91- }
33+ /**
34+ * ログ出力(テキスト)
35+ * @param str
36+ */
37+ public void logWriteStr(String str) {
38+ if(logFile != null) {
39+ try {
40+ logFile.write((str + "\r\n").getBytes());
41+ } catch (IOException e) {
42+ e.printStackTrace();
43+ }
44+ } else {
45+ System.err.println("logFile is null");
46+ }
47+ }
48+ /**
49+ * ログ出力(バイトのリスト)
50+ * @param byteList
51+ */
52+ public void logWriteByteList(ArrayList<byte[]> byteList) {
53+ if(logFile != null) {
54+ if(byteList == null) {
55+ System.err.println("byteList is null");
56+ return;
57+ }
58+ if(byteList.size() == 0) {
59+ byte[] outBuff = "byteList.size=0\r\n".getBytes();
60+ byteList.add(outBuff);
61+ }
62+ try {
63+ for(byte[] b: byteList) {
64+ logFile.write(b);
65+ }
66+ logFile.write("\r\n".getBytes());
67+ } catch (IOException e) {
68+ e.printStackTrace();
69+ }
70+ } else {
71+ System.err.println("logFile is null");
72+ }
73+ }
74+ /**
75+ * ログ出力(文字列のリスト型)
76+ * @param list
77+ */
78+ public void logWriteStrList(ArrayList<String> list) {
79+ if(logFile != null) {
80+ try {
81+ for(String str:list) {
82+ logFile.write((str + "\r\n").getBytes());
83+ }
84+ logFile.write("\r\n".getBytes());
85+ } catch (IOException e) {
86+ e.printStackTrace();
87+ }
88+ } else {
89+ System.err.println("logFile is null");
90+ }
91+ }
9292 }
--- branch/Basic 0.2x/src/extension/file/EasyIni.java (revision 65)
+++ branch/Basic 0.2x/src/extension/file/EasyIni.java (revision 66)
@@ -4,64 +4,64 @@
44 import java.io.FileReader;
55
66 public class EasyIni {
7- private int line_num = 0;
8- private String[] iniData = null;
7+ private int line_num = 0;
8+ private String[] iniData = null;
99
10- /**
11- * コンストラクタ.
12- * iniファイルを読み込む
13- * @param iniFilePath
14- */
15- public EasyIni(String iniFilePath) {
16- iniData = new String[200];
17- FileReader fr = null;
18- BufferedReader br = null;
10+ /**
11+ * コンストラクタ.
12+ * iniファイルを読み込む
13+ * @param iniFilePath
14+ */
15+ public EasyIni(String iniFilePath) {
16+ iniData = new String[200];
17+ FileReader fr = null;
18+ BufferedReader br = null;
1919
20- try {
21- fr = new FileReader(iniFilePath);
22- br = new BufferedReader(fr);
20+ try {
21+ fr = new FileReader(iniFilePath);
22+ br = new BufferedReader(fr);
2323
24- String line = null;
25- // ファイルを行ごとに読み込み終了したらnullが返る
26- while(true){
27- line = br.readLine();
28- if(line == null) {
29- break;
30- }
31- iniData[line_num++] = line;
32- }
24+ String line = null;
25+ // ファイルを行ごとに読み込み終了したらnullが返る
26+ while(true){
27+ line = br.readLine();
28+ if(line == null) {
29+ break;
30+ }
31+ iniData[line_num++] = line;
32+ }
3333
34- } catch (Exception e) {
35- e.printStackTrace();
36- } finally {
37- try {
38- fr.close();
39- br.close();
40- } catch (Exception e) {
41- e.printStackTrace();
42- }
43- }
44- }
34+ } catch (Exception e) {
35+ e.printStackTrace();
36+ } finally {
37+ try {
38+ fr.close();
39+ br.close();
40+ } catch (Exception e) {
41+ e.printStackTrace();
42+ }
43+ }
44+ }
4545
46- public String getPro(String key) {
47- String iniParam = null;
48- for(int i = 0;i < line_num;i++) {
49- String line = iniData[i];
50- if("".equals(line) || line.charAt(0) == ';') {
51- continue;
52- }
53- String[] lineData = line.split("=");
54- if(lineData.length != 2) {
55- continue;
56- }
57- String iniKey = lineData[0].trim();
58- if(!iniKey.equals(key)) {
59- continue;
60- }
61- iniParam = lineData[1].trim();
62- break;
63- }
64- return iniParam;
65- }
46+ public String getPro(String key) {
47+ String iniParam = null;
48+ for(int i = 0;i < line_num;i++) {
49+ String line = iniData[i];
50+ if("".equals(line) || line.charAt(0) == ';') {
51+ continue;
52+ }
53+ String[] lineData = line.split("=");
54+ if(lineData.length != 2) {
55+ continue;
56+ }
57+ String iniKey = lineData[0].trim();
58+ if(!iniKey.equals(key)) {
59+ continue;
60+ }
61+ iniParam = lineData[1].trim();
62+ break;
63+ }
64+ return iniParam;
65+ }
6666
6767 }
Show on old repository browser