• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision75 (tree)
Time2012-12-13 15:49:15
Authorhoritaku

Log Message

ソースを整理

Change Summary

Incremental Difference

--- branch/Basic 0.2x/startup_action/startup_action/StartTest.java (revision 74)
+++ branch/Basic 0.2x/startup_action/startup_action/StartTest.java (revision 75)
@@ -37,7 +37,7 @@
3737 while(true) {
3838 int length = ips.read(readData);
3939 String str = new String(readData, 0, length);
40- WebTest.send(str);
40+ //WebTest.send(str);
4141 System.out.println(str);
4242 }
4343
--- branch/Basic 0.2x/config/web_server.ini (revision 74)
+++ branch/Basic 0.2x/config/web_server.ini (revision 75)
@@ -3,6 +3,6 @@
33 userSecury=false
44 compress=gzip
55
6-port=8080
6+port=80
77
88 loadInit=./config/database.ini
\ No newline at end of file
--- branch/Basic 0.2x/sokect_action/socket_action/Test1.java (revision 74)
+++ branch/Basic 0.2x/sokect_action/socket_action/Test1.java (nonexistent)
@@ -1,5 +0,0 @@
1-package socket_action;
2-
3-public class Test1 {
4-
5-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- branch/Basic 0.2x/sokect_action/socket_action/WebTest2.java (revision 74)
+++ branch/Basic 0.2x/sokect_action/socket_action/WebTest2.java (revision 75)
@@ -8,12 +8,13 @@
88 import servercore.http.HttpRequest;
99
1010 public class WebTest2 extends WebSocketFrame{
11+
1112 public boolean cont = true;
1213 public static String A = "";
1314 private String B = null;
14- public void execute(HttpRequest req, OutputStream ops, InputStream ips) {
15- super.ops = ops;
16- super.ips = ips;
15+
16+ @Override
17+ public void execute(HttpRequest req) {
1718 System.out.println("\r\nWebTest start");
1819 B = WebTest2.A;
1920 SyncsThread th = new SyncsThread();
--- branch/Basic 0.2x/sokect_action/socket_action/WebTest.java (revision 74)
+++ branch/Basic 0.2x/sokect_action/socket_action/WebTest.java (revision 75)
@@ -8,10 +8,11 @@
88 import servercore.html5.WebSocketFrame;
99
1010 public class WebTest extends WebSocketFrame{
11+
1112 public boolean cont = true;
12- public void execute(HttpRequest req, OutputStream ops, InputStream ips) {
13- super.ops = ops;
14- super.ips = ips;
13+
14+ @Override
15+ public void execute(HttpRequest req) {
1516 System.out.println("\r\nWebTest start");
1617 try {
1718 System.out.println("READ:" + read());
@@ -28,5 +29,4 @@
2829 }
2930 System.out.println("\r\nWebTest end");
3031 }
31-
3232 }
--- branch/Basic 0.2x/src/servercore/html5/WebSocketFrame.java (revision 74)
+++ branch/Basic 0.2x/src/servercore/html5/WebSocketFrame.java (revision 75)
@@ -4,10 +4,27 @@
44 import java.io.InputStream;
55 import java.io.OutputStream;
66
7-public class WebSocketFrame {
8- protected static OutputStream ops = null;
9- protected static InputStream ips = null;
7+import servercore.http.HttpRequest;
108
9+public abstract class WebSocketFrame {
10+ abstract protected void execute(HttpRequest req);
11+ public enum OP_CODE_TYPE{
12+ CONTINUATION,
13+ TEXT,
14+ BINARY,
15+ NON_CONTROL,
16+ CLOSE,
17+ PING,
18+ PONG,
19+ FURTHER_CONTROL
20+ }
21+ protected OutputStream ops = null;
22+ protected InputStream ips = null;
23+
24+ public void setStream(OutputStream ops, InputStream ips) {
25+ this.ops = ops;
26+ this.ips = ips;
27+ }
1128 public String read() throws IOException{
1229 byte[] data = new byte[8098];
1330 int len = ips.read(data);
@@ -16,19 +33,47 @@
1633 System.out.printf("%2d:%#x\n", i, data[i]);
1734 }
1835 */
19- String str = new String(data, 0, len);
2036 if(len < 8) {
2137 return "";
2238 }
2339 boolean isFinalPacket = (data[0] & 0x80) == 0x80;
2440 int opCode = data[0] & 0x15;
25- String opCodeType = "";
41+ OP_CODE_TYPE opCodeType = null;
2642 switch(opCode) {
27- case 0x01:
28- opCodeType = "text";
29- break;
30- default:
31- break;
43+ case 0x00:
44+ opCodeType = OP_CODE_TYPE.CONTINUATION;
45+ break;
46+ case 0x01:
47+ opCodeType = OP_CODE_TYPE.TEXT;
48+ break;
49+ case 0x02:
50+ opCodeType = OP_CODE_TYPE.BINARY;
51+ break;
52+ case 0x03:
53+ case 0x04:
54+ case 0x05:
55+ case 0x06:
56+ case 0x07:
57+ opCodeType = OP_CODE_TYPE.NON_CONTROL;
58+ break;
59+ case 0x08:
60+ opCodeType = OP_CODE_TYPE.CLOSE;
61+ break;
62+ case 0x09:
63+ opCodeType = OP_CODE_TYPE.PING;
64+ break;
65+ case 0x0A:
66+ opCodeType = OP_CODE_TYPE.PONG;
67+ break;
68+ case 0x0B:
69+ case 0x0C:
70+ case 0x0D:
71+ case 0x0E:
72+ case 0x0F:
73+ opCodeType = OP_CODE_TYPE.FURTHER_CONTROL;
74+ break;
75+ default:
76+ break;
3277 }
3378 boolean masked = (data[1] & 0x80) == 0x80;
3479 byte payloadLength = (byte)(data[1] & 0x7f);
@@ -45,18 +90,33 @@
4590 byte[] appData = new byte[payloadLength];
4691 for(int i = 0;i < payloadLength;i++) {
4792 appData[i] = (byte)(data[6 + i] ^ maskingKey[i % 4]);
48-
4993 }
5094 return new String(appData);
5195 }
52- public static void send(String str) throws IOException {
96+ public void send(String str) throws IOException {
5397 if(ops == null) {
5498 return;
5599 }
100+ int payloadLength = str.length();
56101 ops.write(0x81);
57- ops.write((byte)str.length());
102+ if(payloadLength < 126) {
103+ ops.write((byte)payloadLength);
104+ } else if(payloadLength < 65536) {
105+ ops.write(0x7e);
106+ ops.write(payloadLength >> 8 & 0xFF);
107+ ops.write(payloadLength & 0xFF);
108+ } else {
109+ ops.write(0x7F);
110+ ops.write(0x00);
111+ ops.write(0x00);
112+ ops.write(0x00);
113+ ops.write(0x00);
114+ ops.write(payloadLength >> 24 & 0xFF);
115+ ops.write(payloadLength >> 16 & 0xFF);
116+ ops.write(payloadLength >> 8 & 0xFF);
117+ ops.write(payloadLength & 0xFF);
118+ }
58119 ops.write(str.getBytes());
59120 ops.flush();
60-
61121 }
62122 }
--- branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 74)
+++ branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 75)
@@ -11,6 +11,7 @@
1111 import sun.misc.BASE64Encoder;
1212
1313 import lib.io.ByteUtil;
14+import servercore.html5.WebSocketFrame;
1415 import servercore.http.HttpRequest;
1516 import servercore.http.HttpResponse;
1617 import servercore.servelet.reflect.Action;
@@ -35,7 +36,7 @@
3536 } else if("ws".equals(ext)) {
3637 int index = cgiPath.indexOf(".ws");
3738 String pkg = "socket_action" + cgiPath.substring(0, index);
38- executeWebSokcet(req, pkg, ops, ips);
39+ handshakeWebSocket(req, pkg, ops, ips);
3940 }
4041 ifThisIsFile = new File(realPath);
4142 if(!ifThisIsFile.exists()) {
@@ -75,7 +76,7 @@
7576 // 実行する
7677 return (HttpResponse)method.invoke(cls.newInstance(),req);
7778 }
78- private static void executeWebSokcet(HttpRequest req, String PackageName, OutputStream ops, InputStream ips) throws Exception {
79+ private static void handshakeWebSocket(HttpRequest req, String PackageName, OutputStream ops, InputStream ips) throws Exception {
7980
8081 StringBuffer sb = new StringBuffer();
8182 String webSocketVersion = req.getHeader().get("Sec-WebSocket-Version");
@@ -104,11 +105,16 @@
104105 sb.append("\r\n");
105106 ops.write(sb.toString().getBytes());
106107
107- Class<Action> cls = null;
108+ Class<WebSocketFrame> cls = null;
108109
109- cls = (Class<Action>)Class.forName(PackageName);
110- Method method = cls.getMethod("execute", HttpRequest.class, OutputStream.class, InputStream.class);
110+ cls = (Class<WebSocketFrame>)Class.forName(PackageName);
111+ WebSocketFrame class2 = cls.newInstance();
112+ Method method = cls.getMethod("setStream", OutputStream.class, InputStream.class);
111113 // 実行する
112- method.invoke(cls.newInstance(), req, ops, ips);
114+ method.invoke(class2, ops, ips);
115+
116+ method = cls.getMethod("execute", HttpRequest.class);
117+ // 実行する
118+ method.invoke(class2, req);
113119 }
114120 }
Show on old repository browser