Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e7d13540
authored
Mar 15, 2017
by
xueli.xue
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
通讯协议二进制据增强校验,处理非正常请求;
parent
81508178
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
14 deletions
README.md
xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/client/JettyClient.java
xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServerHandler.java
xxl-job-core/src/main/java/com/xxl/job/core/util/HttpClientUtil.java
README.md
View file @
e7d13540
...
...
@@ -768,6 +768,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
#### 6.12 版本 V1.6.1 特性 (Coding)
-
1、rolling日志,日志界面风格同glue任务编辑器;
-
2、
#### TODO LIST
...
...
xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/client/JettyClient.java
View file @
e7d13540
...
...
@@ -4,17 +4,39 @@ import com.xxl.job.core.rpc.codec.RpcRequest;
import
com.xxl.job.core.rpc.codec.RpcResponse
;
import
com.xxl.job.core.rpc.serialize.HessianSerializer
;
import
com.xxl.job.core.util.HttpClientUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* jetty client
* @author xuxueli 2015-11-24 22:25:15
*/
public
class
JettyClient
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JettyClient
.
class
);
public
RpcResponse
send
(
RpcRequest
request
)
throws
Exception
{
try
{
// serialize request
byte
[]
requestBytes
=
HessianSerializer
.
serialize
(
request
);
// remote invoke
byte
[]
responseBytes
=
HttpClientUtil
.
postRequest
(
"http://"
+
request
.
getServerAddress
()
+
"/"
,
requestBytes
);
return
(
RpcResponse
)
HessianSerializer
.
deserialize
(
responseBytes
,
RpcResponse
.
class
);
if
(
responseBytes
==
null
||
responseBytes
.
length
==
0
)
{
RpcResponse
rpcResponse
=
new
RpcResponse
();
rpcResponse
.
setError
(
"RpcResponse byte[] is null"
);
return
rpcResponse
;
}
// deserialize response
RpcResponse
rpcResponse
=
(
RpcResponse
)
HessianSerializer
.
deserialize
(
responseBytes
,
RpcResponse
.
class
);
return
rpcResponse
;
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
RpcResponse
rpcResponse
=
new
RpcResponse
();
rpcResponse
.
setError
(
"Servet-error:"
+
e
.
getMessage
());
return
rpcResponse
;
}
}
}
xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServerHandler.java
View file @
e7d13540
...
...
@@ -7,6 +7,8 @@ import com.xxl.job.core.rpc.serialize.HessianSerializer;
import
com.xxl.job.core.util.HttpClientUtil
;
import
org.eclipse.jetty.server.Request
;
import
org.eclipse.jetty.server.handler.AbstractHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -19,17 +21,13 @@ import java.io.OutputStream;
* @author xuxueli 2015-11-19 22:32:36
*/
public
class
JettyServerHandler
extends
AbstractHandler
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JettyServerHandler
.
class
);
@Override
public
void
handle
(
String
target
,
Request
baseRequest
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
// deserialize request
byte
[]
requestBytes
=
HttpClientUtil
.
readBytes
(
request
);
RpcRequest
rpcRequest
=
(
RpcRequest
)
HessianSerializer
.
deserialize
(
requestBytes
,
RpcRequest
.
class
);
// invoke
RpcResponse
rpcResponse
=
NetComServerFactory
.
invokeService
(
rpcRequest
,
null
);
RpcResponse
rpcResponse
=
doInvoke
(
request
);
// serialize response
byte
[]
responseBytes
=
HessianSerializer
.
serialize
(
rpcResponse
);
...
...
@@ -44,4 +42,27 @@ public class JettyServerHandler extends AbstractHandler {
}
private
RpcResponse
doInvoke
(
HttpServletRequest
request
)
{
try
{
// deserialize request
byte
[]
requestBytes
=
HttpClientUtil
.
readBytes
(
request
);
if
(
requestBytes
==
null
||
requestBytes
.
length
==
0
)
{
RpcResponse
rpcResponse
=
new
RpcResponse
();
rpcResponse
.
setError
(
"RpcRequest byte[] is null"
);
return
rpcResponse
;
}
RpcRequest
rpcRequest
=
(
RpcRequest
)
HessianSerializer
.
deserialize
(
requestBytes
,
RpcRequest
.
class
);
// invoke
RpcResponse
rpcResponse
=
NetComServerFactory
.
invokeService
(
rpcRequest
,
null
);
return
rpcResponse
;
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
RpcResponse
rpcResponse
=
new
RpcResponse
();
rpcResponse
.
setError
(
"Servet-error:"
+
e
.
getMessage
());
return
rpcResponse
;
}
}
}
xxl-job-core/src/main/java/com/xxl/job/core/util/HttpClientUtil.java
View file @
e7d13540
package
com
.
xxl
.
job
.
core
.
util
;
import
com.xxl.job.core.rpc.codec.RpcResponse
;
import
com.xxl.job.core.rpc.serialize.HessianSerializer
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
...
...
@@ -27,7 +25,7 @@ public class HttpClientUtil {
/**
* post request
*/
public
static
byte
[]
postRequest
(
String
reqURL
,
byte
[]
date
)
{
public
static
byte
[]
postRequest
(
String
reqURL
,
byte
[]
date
)
throws
Exception
{
byte
[]
responseBytes
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
reqURL
);
...
...
@@ -53,10 +51,7 @@ public class HttpClientUtil {
}
}
catch
(
Exception
e
)
{
logger
.
error
(
""
,
e
);
RpcResponse
rpcResponse
=
new
RpcResponse
();
rpcResponse
.
setError
(
e
.
getMessage
());
responseBytes
=
HessianSerializer
.
serialize
(
rpcResponse
);
throw
e
;
}
finally
{
httpPost
.
releaseConnection
();
try
{
...
...
@@ -93,6 +88,7 @@ public class HttpClientUtil {
return
message
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
return
new
byte
[]
{};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment