Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
be-esb-core
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
be-esb-ecosystem-maven
be-esb-core
Commits
e8a25b29
Commit
e8a25b29
authored
Aug 11, 2022
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码整理
parent
1689dc97
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
109 deletions
+107
-109
ShortSocketHandle.java
...rc/com/brilliance/eibs/main/client/ShortSocketHandle.java
+107
-109
SocketServerMode.java
.../brilliance/eibs/server/socket/impl/SocketServerMode.java
+0
-0
No files found.
src/main/src/com/brilliance/eibs/main/client/ShortSocketHandle.java
View file @
e8a25b29
...
...
@@ -13,113 +13,111 @@ import java.net.Socket;
public
class
ShortSocketHandle
implements
Runnable
{
private
Object
[]
args
;
private
Socket
socket
;
private
String
interfaceName
;
private
String
transName
;
private
boolean
has_head
=
true
;
// 是否有报文头
private
String
head_len_type
=
IServerInstance
.
HEAD_LEN_TYPE_10
;
// 报文头长度是二进制还是十进制
private
int
head_len
=
0
;
// 报文头长度
private
boolean
is_contain_head_len
=
false
;
// 报文头长度是否包含报文头
private
int
fill_len
=
0
;
// 默认为0
private
boolean
is_contain_fill_len
=
false
;
// 报文头长度是否包含报文头和报文体之间数据的长度 true
private
int
body_offset
=
0
;
// 报文体位移量 默认为0, -1为减去1个长度,+1为增加1个长度
private
String
encoding
=
"UTF-8"
;
private
Logger
logger
;
public
ShortSocketHandle
(
Socket
socket
,
String
interfaceName
,
String
transName
,
boolean
has_head
,
String
head_len_type
,
int
head_len
,
boolean
is_contain_head_len
,
int
fill_len
,
boolean
is_contain_fill_len
,
int
body_offset
,
Object
[]
args
,
String
encoding
,
Logger
logger
)
{
this
.
socket
=
socket
;
this
.
interfaceName
=
interfaceName
;
this
.
transName
=
transName
;
this
.
has_head
=
has_head
;
this
.
head_len_type
=
head_len_type
;
this
.
head_len
=
head_len
;
this
.
is_contain_head_len
=
is_contain_head_len
;
this
.
fill_len
=
fill_len
;
this
.
is_contain_fill_len
=
is_contain_fill_len
;
this
.
body_offset
=
body_offset
;
this
.
args
=
args
;
this
.
encoding
=
encoding
;
this
.
logger
=
logger
;
}
@Override
public
void
run
()
{
if
(
has_head
)
{
handleWithHead
();
}
else
{
handleWithNoHead
();
}
}
public
void
handleWithHead
()
{
byte
[]
headLenBytes
=
new
byte
[
head_len
];
int
headLen
=
0
;
int
returnLen
=
0
;
try
{
IOUtils
.
readFully
(
socket
.
getInputStream
(),
headLenBytes
);
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_10
))
{
headLen
=
Integer
.
parseInt
(
new
String
(
headLenBytes
));
}
else
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_2
))
{
headLen
=
CommonFunctionUtils
.
bytesToInt
(
headLenBytes
);
}
if
(
is_contain_head_len
)
{
headLen
=
headLen
-
head_len
;
}
if
(
fill_len
!=
0
)
{
if
(!
is_contain_fill_len
)
{
headLen
=
headLen
+
fill_len
;
}
}
headLen
=
headLen
+
body_offset
;
byte
[]
databuffer
=
new
byte
[
headLen
];
IOUtils
.
readFully
(
socket
.
getInputStream
(),
databuffer
);
// logger.debug("socket接收");
Context
context
=
new
Context
();
context
.
addVariable
(
"transaction"
,
"__val"
,
databuffer
);
ResultMsg
resultMsg
=
new
Client
().
call
(
context
,
interfaceName
,
transName
,
args
);
byte
[]
returnBytes
=
null
;
Object
obj
=
resultMsg
.
getContent
();
if
(
obj
instanceof
String
)
{
returnBytes
=
((
String
)
obj
).
getBytes
(
encoding
);
}
else
{
returnBytes
=
(
byte
[])
obj
;
}
returnLen
=
returnBytes
.
length
;
byte
[]
header
=
null
;
if
(
is_contain_head_len
)
{
returnLen
=
returnLen
+
head_len
;
}
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_10
))
{
header
=
String
.
format
(
"%0"
+
head_len
+
"d"
,
returnLen
).
getBytes
();
}
else
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_2
))
{
header
=
CommonFunctionUtils
.
intToBytes
(
returnLen
);
}
IOUtils
.
write
(
header
,
socket
.
getOutputStream
());
IOUtils
.
write
(
returnBytes
,
socket
.
getOutputStream
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
IOUtils
.
closeQuietly
(
socket
);
}
finally
{
IOUtils
.
closeQuietly
(
socket
);
}
}
public
void
handleWithNoHead
()
{
}
private
Object
[]
args
;
private
Socket
socket
;
private
String
interfaceName
;
private
String
transName
;
private
boolean
has_head
=
true
;
// 是否有报文头
private
String
head_len_type
=
IServerInstance
.
HEAD_LEN_TYPE_10
;
// 报文头长度是二进制还是十进制
private
int
head_len
=
0
;
// 报文头长度
private
boolean
is_contain_head_len
=
false
;
// 报文头长度是否包含报文头
private
int
fill_len
=
0
;
// 默认为0
private
boolean
is_contain_fill_len
=
false
;
// 报文头长度是否包含报文头和报文体之间数据的长度 true
private
int
body_offset
=
0
;
// 报文体位移量 默认为0, -1为减去1个长度,+1为增加1个长度
private
String
encoding
=
"UTF-8"
;
private
Logger
logger
;
public
ShortSocketHandle
(
Socket
socket
,
String
interfaceName
,
String
transName
,
boolean
has_head
,
String
head_len_type
,
int
head_len
,
boolean
is_contain_head_len
,
int
fill_len
,
boolean
is_contain_fill_len
,
int
body_offset
,
Object
[]
args
,
String
encoding
,
Logger
logger
)
{
this
.
socket
=
socket
;
this
.
interfaceName
=
interfaceName
;
this
.
transName
=
transName
;
this
.
has_head
=
has_head
;
this
.
head_len_type
=
head_len_type
;
this
.
head_len
=
head_len
;
this
.
is_contain_head_len
=
is_contain_head_len
;
this
.
fill_len
=
fill_len
;
this
.
is_contain_fill_len
=
is_contain_fill_len
;
this
.
body_offset
=
body_offset
;
this
.
args
=
args
;
this
.
encoding
=
encoding
;
this
.
logger
=
logger
;
}
@Override
public
void
run
()
{
if
(
has_head
)
{
handleWithHead
();
}
else
{
handleWithNoHead
();
}
}
public
void
handleWithHead
()
{
byte
[]
headLenBytes
=
new
byte
[
head_len
];
int
headLen
=
0
;
int
returnLen
=
0
;
try
{
IOUtils
.
readFully
(
socket
.
getInputStream
(),
headLenBytes
);
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_10
))
{
headLen
=
Integer
.
parseInt
(
new
String
(
headLenBytes
));
}
else
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_2
))
{
headLen
=
CommonFunctionUtils
.
bytesToInt
(
headLenBytes
);
}
if
(
is_contain_head_len
)
{
headLen
=
headLen
-
head_len
;
}
if
(
fill_len
!=
0
)
{
if
(!
is_contain_fill_len
)
{
headLen
=
headLen
+
fill_len
;
}
}
headLen
=
headLen
+
body_offset
;
byte
[]
databuffer
=
new
byte
[
headLen
];
IOUtils
.
readFully
(
socket
.
getInputStream
(),
databuffer
);
Context
context
=
new
Context
();
context
.
addVariable
(
"transaction"
,
"__val"
,
databuffer
);
ResultMsg
resultMsg
=
new
Client
().
call
(
context
,
interfaceName
,
transName
,
args
);
byte
[]
returnBytes
=
null
;
Object
obj
=
resultMsg
.
getContent
();
if
(
obj
instanceof
String
)
{
returnBytes
=
((
String
)
obj
).
getBytes
(
encoding
);
}
else
{
returnBytes
=
(
byte
[])
obj
;
}
returnLen
=
returnBytes
.
length
;
byte
[]
header
=
null
;
if
(
is_contain_head_len
)
{
returnLen
=
returnLen
+
head_len
;
}
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_10
))
{
header
=
String
.
format
(
"%0"
+
head_len
+
"d"
,
returnLen
).
getBytes
();
}
else
if
(
head_len_type
.
equals
(
IServerInstance
.
HEAD_LEN_TYPE_2
))
{
header
=
CommonFunctionUtils
.
intToBytes
(
returnLen
);
}
IOUtils
.
write
(
header
,
socket
.
getOutputStream
());
IOUtils
.
write
(
returnBytes
,
socket
.
getOutputStream
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
logger
.
error
(
e
.
getMessage
(),
e
);
IOUtils
.
closeQuietly
(
socket
);
}
finally
{
IOUtils
.
closeQuietly
(
socket
);
}
}
public
void
handleWithNoHead
()
{
}
}
src/main/src/com/brilliance/eibs/server/socket/impl/SocketServerMode.java
View file @
e8a25b29
This diff is collapsed.
Click to expand it.
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