Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发者小峰
Jerry Rat Server
提交
a1fdb68a
Jerry Rat Server
项目概览
开发者小峰
/
Jerry Rat Server
9 个月 前同步成功
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Jerry Rat Server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a1fdb68a
编写于
5月 22, 2022
作者:
F
fanjiefeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加长头部支持
上级
2c48cb60
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
194 addition
and
34 deletion
+194
-34
Manage/.classpath
Manage/.classpath
+1
-1
Manage/lib/tools/ConsolePrintStream.class
Manage/lib/tools/ConsolePrintStream.class
+0
-0
Manage/lib/tools/ConsolePrintStream.java
Manage/lib/tools/ConsolePrintStream.java
+10
-4
Manage/resource/css/index.css
Manage/resource/css/index.css
+22
-2
Manage/resource/index.html
Manage/resource/index.html
+5
-1
Manage/resource/js/console/console.js
Manage/resource/js/console/console.js
+11
-3
Manage/src/application/ConsoleApplication.java
Manage/src/application/ConsoleApplication.java
+10
-0
Manage/src/filter/ManageServer.java
Manage/src/filter/ManageServer.java
+2
-0
Manage/src/servlet/ServerConsole.java
Manage/src/servlet/ServerConsole.java
+26
-1
bin/pub/fjf/http/HttpRequest.class
bin/pub/fjf/http/HttpRequest.class
+0
-0
bin/pub/fjf/http/HttpResponse.class
bin/pub/fjf/http/HttpResponse.class
+0
-0
bin/pub/fjf/http/HttpServer.class
bin/pub/fjf/http/HttpServer.class
+0
-0
bin/pub/fjf/http/SessionServer.class
bin/pub/fjf/http/SessionServer.class
+0
-0
src/pub/fjf/http/HttpRequest.java
src/pub/fjf/http/HttpRequest.java
+79
-0
src/pub/fjf/http/HttpResponse.java
src/pub/fjf/http/HttpResponse.java
+11
-9
src/pub/fjf/http/HttpServer.java
src/pub/fjf/http/HttpServer.java
+2
-4
src/pub/fjf/http/SessionServer.java
src/pub/fjf/http/SessionServer.java
+15
-9
未找到文件。
Manage/.classpath
浏览文件 @
a1fdb68a
...
...
@@ -5,5 +5,5 @@
<classpathentry
kind=
"src"
path=
"lib"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
/>
<classpathentry
kind=
"lib"
path=
"tools.jar"
/>
<classpathentry
kind=
"output"
path=
"
bin
"
/>
<classpathentry
kind=
"output"
path=
"
src
"
/>
</classpath>
Manage/lib/tools/ConsolePrintStream.class
浏览文件 @
a1fdb68a
无法预览此类型文件
Manage/lib/tools/ConsolePrintStream.java
浏览文件 @
a1fdb68a
...
...
@@ -13,7 +13,7 @@ public class ConsolePrintStream extends PrintStream {
private
PrintStream
oldPrintStream
;
private
SiftedQueue
infoQueue
;
private
ArrayList
<
String
>
infos
;
p
rivate
boolean
isLog
=
true
;
p
ublic
boolean
isLog
=
true
;
public
ConsolePrintStream
(
File
file
)
throws
FileNotFoundException
{
this
(
file
,
null
);
}
...
...
@@ -23,18 +23,19 @@ public class ConsolePrintStream extends PrintStream {
infoQueue
=
new
SiftedQueue
(
200
);
infos
=
new
ArrayList
<
String
>();
}
@Override
public
void
println
(
String
text
)
{
if
(
isLog
)
{
Date
date
=
new
Date
();
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyy-MM-dd_HH-mm-ss"
);
text
=
formatter
.
format
(
date
)+
":
"
+
text
;
text
=
formatter
.
format
(
date
)+
":
\r\n
"
+
text
;
if
(
oldPrintStream
!=
null
)
{
oldPrintStream
.
println
(
text
);
}
super
.
println
(
text
);
infoQueue
.
push
(
text
);
if
(
text
.
indexOf
(
"/@ServerConsole"
)<
0
)
{
infoQueue
.
push
(
text
);
}
}
}
...
...
@@ -50,4 +51,9 @@ public class ConsolePrintStream extends PrintStream {
}
return
infos
;
}
public
void
pushInfos
(
String
[]
infos
)
{
for
(
int
i
=
0
;
i
<
infos
.
length
;
i
++)
{
infoQueue
.
push
(
infos
[
i
]);
}
}
}
Manage/resource/css/index.css
浏览文件 @
a1fdb68a
...
...
@@ -373,16 +373,36 @@ input{
position
:
absolute
;
visibility
:
hidden
;
}
.Console
{
#ConsoleMain
{
text-align
:
left
;
background
:
rgb
(
240
,
240
,
240
);
}
.Console
#ConsoleText
{
width
:
100
%
;
width
:
99
%
;
height
:
400px
;
overflow-y
:
scroll
;
color
:
rgb
(
240
,
240
,
240
);
background
:
rgb
(
0
,
0
,
0
);
}
.Console
.bottom
{
width
:
100%
;
height
:
80px
;
text-align
:
left
;
}
.Console
#AnalogHTTP
{
width
:
94%
;
height
:
80px
;
overflow-y
:
scroll
;
color
:
rgb
(
0
,
0
,
0
);
background
:
rgb
(
240
,
240
,
240
);
}
.Console
#AnalogButton
{
position
:
absolute
;
width
:
30px
;
height
:
86px
;
right
:
0px
;
bottom
:
4px
;
}
#ListDiv
{
position
:
absolute
;
width
:
100%
;
...
...
Manage/resource/index.html
浏览文件 @
a1fdb68a
...
...
@@ -247,8 +247,12 @@
<div
id=
"fileHandle"
></div>
<script
src=
"js/file/file.js"
type=
"text/javascript"
charset=
"utf-8"
></script>
</div>
<div
class=
"Console content"
>
<div
class=
"Console content"
id=
"ConsoleMain"
>
<textarea
id=
"ConsoleText"
rows=
""
cols=
""
readonly=
"true"
></textarea>
<div
class=
"bottom"
>
<textarea
id=
"AnalogHTTP"
rows=
""
cols=
""
spellcheck=
"false"
></textarea>
<button
type=
"button"
id=
"AnalogButton"
onclick=
"analogHttp()"
>
模
<br>
拟
<br>
请
<br>
求
</button>
</div>
<script
src=
"js/console/console.js"
type=
"text/javascript"
charset=
"utf-8"
></script>
</div>
<div
class=
"Help content"
>
...
...
Manage/resource/js/console/console.js
浏览文件 @
a1fdb68a
...
...
@@ -13,10 +13,18 @@ function showInfos(text) {
var
cons
=
document
.
getElementById
(
"
ConsoleText
"
);
for
(
let
i
=
0
;
i
<
infos
.
length
;
i
++
){
var
info
=
infos
[
i
];
if
(
info
.
indexOf
(
"
/@ServerConsole
"
)
<
0
){
cons
.
innerHTML
+=
infos
[
i
]
+
"
\r\n
"
;
}
cons
.
innerHTML
+=
infos
[
i
]
+
"
\r\n
"
;
}
if
(
infos
.
length
>
0
){
cons
.
scrollTop
=
cons
.
scrollHeight
;
}
}
function
analogHttp
()
{
var
analogHttp
=
document
.
getElementById
(
"
AnalogHTTP
"
);
var
analogText
=
analogHttp
.
value
;
analogText
=
analogText
.
replace
(
"
\n
"
,
"
\r\n
"
);
send
(
"
POST
"
,
"
/@ServerConsole
"
,
true
,
analogText
);
}
setInterval
(
getInfos
,
500
);
...
...
Manage/src/application/ConsoleApplication.java
浏览文件 @
a1fdb68a
...
...
@@ -41,4 +41,14 @@ public class ConsoleApplication extends Application {
return
consolePrintStream
.
getInfos
(
20
);
}
}
public
void
pushInfos
(
String
[]
infos
)
{
if
(
consolePrintStream
!=
null
)
{
consolePrintStream
.
pushInfos
(
infos
);
}
}
public
void
setIsLog
(
boolean
isLog
)
{
if
(
consolePrintStream
!=
null
)
{
consolePrintStream
.
isLog
=
isLog
;
}
}
}
Manage/src/filter/ManageServer.java
浏览文件 @
a1fdb68a
...
...
@@ -34,6 +34,8 @@ public class ManageServer extends ApplicationServer {
Object
logined
=
null
;
if
(
session
!=
null
)
{
logined
=
httpRequest
.
getSession
().
getData
(
"logined"
);
}
else
{
this
.
getWebProject
().
getSessionServer
().
createSession
(
httpRequest
,
httpResponse
);
}
if
(
url
.
equals
(
"/@login"
))
{
String
[]
strs
=
httpRequest
.
getBody
().
split
(
"="
);
...
...
Manage/src/servlet/ServerConsole.java
浏览文件 @
a1fdb68a
package
servlet
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
application.ConsoleApplication
;
import
pub.fjf.http.HttpRequest
;
import
pub.fjf.http.HttpResponse
;
import
pub.fjf.http.HttpServlet
;
import
pub.fjf.http.HttpServletRequest
;
import
pub.fjf.http.HttpServletResponse
;
...
...
@@ -27,7 +32,27 @@ public class ServerConsole extends HttpServlet {
@Override
public
void
doPost
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
// TODO Auto-generated method stub
byte
[]
bytes
=
null
;
((
HttpRequest
)
req
).
readWholeBody
();
try
{
bytes
=
req
.
getBody
().
getBytes
(
req
.
getCharset
());
}
catch
(
UnsupportedEncodingException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
try
{
HttpRequest
analogReq
=
new
HttpRequest
(
bytes
,((
HttpRequest
)
req
).
getIs
(),
req
.
getUrlCharset
(),
req
.
getCharset
());
analogReq
.
setClient
(
req
.
getClient
());
HttpResponse
analogResp
=
new
HttpResponse
((
OutputStream
)
null
,
req
.
getCharset
());
System
.
out
.
println
(
"ģ:\r\n"
+
analogReq
.
toHttpText
());
analogResp
.
setHttpRequset
(
analogReq
);
req
.
getClient
().
getServer
().
handleHttpRequest
(
analogReq
,
analogResp
);
System
.
out
.
println
(
"ģӦ:\r\n"
+
analogResp
.
toHttpText
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
resp
.
sendData
(
"OK"
);
}
}
bin/pub/fjf/http/HttpRequest.class
浏览文件 @
a1fdb68a
无法预览此类型文件
bin/pub/fjf/http/HttpResponse.class
浏览文件 @
a1fdb68a
无法预览此类型文件
bin/pub/fjf/http/HttpServer.class
浏览文件 @
a1fdb68a
无法预览此类型文件
bin/pub/fjf/http/SessionServer.class
浏览文件 @
a1fdb68a
无法预览此类型文件
src/pub/fjf/http/HttpRequest.java
浏览文件 @
a1fdb68a
...
...
@@ -3,6 +3,7 @@ package pub.fjf.http;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
pub.fjf.tools.Bytes
;
...
...
@@ -131,6 +132,51 @@ public class HttpRequest implements HttpServletRequest{
throw
new
IOException
();
}
}
public
static
byte
[]
readEndHead
(
int
receiveTimeOut
,
InputStream
is
)
throws
IOException
{
Bytes
headAndBody
=
new
Bytes
(
"\r\n\r\n"
.
getBytes
());
long
lastReceiveTime
=
System
.
currentTimeMillis
();
boolean
headEnd
=
false
;
byte
[][]
bytesList
=
new
byte
[
16
][];
int
bytesCount
=
0
;
int
byteCount
=
0
;
byte
[]
bytes
=
null
;
while
(!
headEnd
)
{
if
(
is
.
available
()>
0
){
if
(
bytesCount
>=
bytesList
.
length
)
{
throw
new
IOException
(
"头部过长,超过"
+
byteCount
+
"字节!"
);
}
bytes
=
new
byte
[
is
.
available
()];
bytesList
[
bytesCount
]=
bytes
;
is
.
read
(
bytes
);
byteCount
+=
bytes
.
length
;
bytesCount
++;
if
(
new
Bytes
(
bytes
).
indexOf
(
headAndBody
)>=
0
)
{
headEnd
=
true
;
}
lastReceiveTime
=
System
.
currentTimeMillis
();
}
else
{
if
(
System
.
currentTimeMillis
()-
lastReceiveTime
>
receiveTimeOut
)
{
break
;
}
}
}
if
(
bytesCount
>
0
)
{
if
(
bytesCount
>
1
)
{
bytes
=
new
byte
[
byteCount
];
int
b
=
0
;
for
(
int
i
=
0
;
i
<
bytesCount
;
i
++)
{
for
(
int
j
=
0
;
j
<
bytesList
[
i
].
length
;
j
++)
{
bytes
[
b
]=
bytesList
[
i
][
j
];
b
++;
}
}
}
}
else
{
throw
new
IOException
();
}
return
bytes
;
}
public
String
getCharset
()
{
return
charset
;
}
...
...
@@ -258,6 +304,32 @@ public class HttpRequest implements HttpServletRequest{
return
new
String
(
this
.
body
);
}
}
public
void
readWholeBody
()
{
if
(
this
.
haveData
())
{
StringBuffer
sb
=
new
StringBuffer
();
if
(
this
.
body
!=
null
)
{
try
{
sb
.
append
(
new
String
(
this
.
body
,
charset
));
}
catch
(
UnsupportedEncodingException
e
)
{
sb
.
append
(
new
String
(
this
.
body
));
}
}
while
(
this
.
haveData
())
{
byte
[]
bytes
=
this
.
readData
();
try
{
sb
.
append
(
new
String
(
bytes
,
charset
));
}
catch
(
UnsupportedEncodingException
e
)
{
sb
.
append
(
new
String
(
bytes
));
}
}
String
bodyString
=
sb
.
toString
();
try
{
this
.
body
=
bodyString
.
getBytes
(
charset
);
}
catch
(
UnsupportedEncodingException
e
)
{
this
.
body
=
bodyString
.
getBytes
();
}
}
}
/**
* 设置该请求报文的请求体文本
* @param body 请求体文本
...
...
@@ -300,6 +372,13 @@ public class HttpRequest implements HttpServletRequest{
public
void
setSession
(
Session
session
)
{
this
.
session
=
session
;
}
public
InputStream
getIs
()
{
return
is
;
}
public
void
setIs
(
InputStream
is
)
{
this
.
is
=
is
;
}
/**
* 判断是否还有数据未接收
*/
...
...
src/pub/fjf/http/HttpResponse.java
浏览文件 @
a1fdb68a
...
...
@@ -291,15 +291,17 @@ public class HttpResponse implements HttpServletResponse{
this
.
setStateCode
(
"100"
);
}
}
try
{
this
.
os
.
write
(
bytes
);
this
.
os
.
flush
();
result
=
true
;
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
// if(Monitor.HttpMonitor.using) {
// Monitor.HttpMonitor.getInform("发送应答报文失败!\n");
// }
if
(
this
.
os
!=
null
)
{
try
{
this
.
os
.
write
(
bytes
);
this
.
os
.
flush
();
result
=
true
;
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
// if(Monitor.HttpMonitor.using) {
// Monitor.HttpMonitor.getInform("发送应答报文失败!\n");
// }
}
}
return
result
;
}
...
...
src/pub/fjf/http/HttpServer.java
浏览文件 @
a1fdb68a
...
...
@@ -292,7 +292,6 @@ public class HttpServer {
OutputStream
os
=
null
;
HttpRequest
httpRequest
=
null
;
HttpResponse
httpResponse
=
null
;
byte
[]
bytes
=
null
;
long
lastReceiveTime
=
System
.
currentTimeMillis
();
String
connection
=
null
;
boolean
keepAlive
=
true
;
...
...
@@ -302,10 +301,9 @@ public class HttpServer {
os
=
clientSocket
.
getOutputStream
();
while
(
clientSocket
.
isConnected
()&&
keepAlive
){
if
(
is
.
available
()>
0
){
bytes
=
new
byte
[
is
.
available
()];
is
.
read
(
bytes
);
httpResponse
=
new
HttpResponse
(
os
,
this
.
charset
);
try
{
byte
[]
bytes
=
HttpRequest
.
readEndHead
(
receiveTimeOut
,
is
);
if
(
StringTools
.
STR2str
(
this
.
urlCharset
).
equals
(
"default"
))
{
httpRequest
=
new
HttpRequest
(
bytes
,
is
,
this
.
charset
,
this
.
charset
);
}
else
{
...
...
@@ -356,7 +354,7 @@ public class HttpServer {
}
}
p
rivate
void
handleHttpRequest
(
HttpRequest
httpRequest
,
HttpResponse
httpResponse
){
p
ublic
void
handleHttpRequest
(
HttpRequest
httpRequest
,
HttpResponse
httpResponse
){
boolean
handed
=
false
;
String
url
=
httpRequest
.
getUrl
();
String
restUrl
=
null
;
...
...
src/pub/fjf/http/SessionServer.java
浏览文件 @
a1fdb68a
...
...
@@ -74,6 +74,16 @@ public class SessionServer extends HttpRequestFilter {
}
}
}
public
Session
createSession
(
HttpRequest
httpRequest
,
HttpResponse
httpResponse
)
{
Session
session
=
new
Session
();
this
.
sessionMap
.
put
(
session
.
getSessionID
(),
session
);
System
.
out
.
println
(
this
.
getWebProject
().
getName
()+
" 会话"
+
session
.
getSessionID
()+
"增加,目前会话数:"
+
this
.
getSessionCount
());
String
setCookie
=
this
.
SESSION_ID
+
"="
+
session
.
getSessionID
();
httpResponse
.
setKeyValue
(
"Set-Cookie"
,
new
String
(
Base64
.
code
(
setCookie
,
httpResponse
.
getCharset
())));
httpRequest
.
setSession
(
session
);
return
session
;
}
@Override
synchronized
public
boolean
handleHttpRequest
(
String
url
,
HttpRequest
httpRequest
,
HttpResponse
httpResponse
)
{
...
...
@@ -102,15 +112,11 @@ public class SessionServer extends HttpRequestFilter {
}
}
}
}
if
(
session
==
null
)
{
session
=
new
Session
();
this
.
sessionMap
.
put
(
session
.
getSessionID
(),
session
);
System
.
out
.
println
(
this
.
getWebProject
().
getName
()+
" 会话"
+
session
.
getSessionID
()+
"增加,目前会话数:"
+
this
.
getSessionCount
());
String
setCookie
=
this
.
SESSION_ID
+
"="
+
session
.
getSessionID
();
httpResponse
.
setKeyValue
(
"Set-Cookie"
,
new
String
(
Base64
.
code
(
setCookie
,
httpResponse
.
getCharset
())));
}
else
{
session
.
setLastVisitedTime
(
System
.
currentTimeMillis
());
if
(
session
==
null
)
{
session
=
createSession
(
httpRequest
,
httpResponse
);
}
else
{
session
.
setLastVisitedTime
(
System
.
currentTimeMillis
());
}
}
httpRequest
.
setSession
(
session
);
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录