Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
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
钱炳权
fuzzBackEnd
Commits
71336f1f
Commit
71336f1f
authored
Apr 29, 2024
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目分离成功,可以成功跑通所有测试
parent
97a834df
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
407 additions
and
329 deletions
+407
-329
pom.xml
fuzzIntegration/pom.xml
+18
-0
FuzzIntegration.java
...c/main/java/com/example/fuzzControll/FuzzIntegration.java
+2
-3
PathProperties.java
...in/java/com/example/fuzzControll/conf/PathProperties.java
+18
-0
TestControler.java
...va/com/example/fuzzControll/controller/TestControler.java
+5
-2
WebSocket.java
...n/java/com/example/fuzzControll/controller/WebSocket.java
+0
-110
WebsocketController.java
.../example/fuzzControll/controller/WebsocketController.java
+35
-0
websocketClientServiceImpl.java
...fuzzControll/service/impl/websocketClientServiceImpl.java
+58
-0
websocketClientService.java
.../example/fuzzControll/service/websocketClientService.java
+9
-0
CmdTools.java
...rc/main/java/com/example/fuzzControll/tools/CmdTools.java
+3
-7
application-dev.yml
fuzzIntegration/src/main/resources/application-dev.yml
+2
-1
application.yml
fuzzIntegration/src/main/resources/application.yml
+1
-1
spring.log
fuzzbackendmaster/log/spring.log
+0
-0
FuzzBackendMaster.java
...java/com/example/fuzzbackendmaster/FuzzBackendMaster.java
+3
-4
SpringContextUtil.java
...com/example/fuzzbackendmaster/conf/SpringContextUtil.java
+50
-0
WebsocketConf.java
...ava/com/example/fuzzbackendmaster/conf/WebsocketConf.java
+3
-8
KittyServerMessageController.java
...ackendmaster/controller/KittyServerMessageController.java
+57
-74
SeedFileController.java
...mple/fuzzbackendmaster/controller/SeedFileController.java
+1
-0
TestController.java
.../example/fuzzbackendmaster/controller/TestController.java
+6
-3
WebSocket.java
...a/com/example/fuzzbackendmaster/controller/WebSocket.java
+113
-110
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+21
-4
application.yml
fuzzbackendmaster/src/main/resources/application.yml
+1
-1
result.html
fuzzbackendmaster/src/main/resources/result.html
+1
-1
No files found.
fuzzIntegration/pom.xml
View file @
71336f1f
...
...
@@ -96,6 +96,12 @@
<artifactId>
lombok
</artifactId>
<version>
1.18.24
</version>
</dependency>
<!--WebSocket核心依赖包-->
<dependency>
<groupId>
org.java-websocket
</groupId>
<artifactId>
Java-WebSocket
</artifactId>
<version>
1.3.8
</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
...
...
@@ -141,6 +147,18 @@
</configuration>
</plugin>
</plugins>
<!-- 配置java版本 不配置的话默认父类配置的是1.7-->
<pluginManagement>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
fuzzIntegration/src/main/java/com/example/fuzzControll/Fuzz
ControlApplic
ation.java
→
fuzzIntegration/src/main/java/com/example/fuzzControll/Fuzz
Integr
ation.java
View file @
71336f1f
...
...
@@ -6,10 +6,9 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients
public
class
FuzzControlApplication
{
public
class
FuzzIntegration
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Fuzz
ControlApplic
ation
.
class
,
args
);
SpringApplication
.
run
(
Fuzz
Integr
ation
.
class
,
args
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/conf/PathProperties.java
0 → 100644
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
conf
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Component
(
"PathProperties"
)
@ConfigurationProperties
(
prefix
=
"path"
)
public
class
PathProperties
{
String
webSocketUri
;
public
String
getWebSocketUri
()
{
return
webSocketUri
;
}
public
void
setWebSocketUri
(
String
webSocketUri
)
{
this
.
webSocketUri
=
webSocketUri
;
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/TestControler.java
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
controller
;
import
com.example.fuzzControll.exception.AflnetException
;
import
com.example.fuzzControll.exception.BaseException
;
import
com.example.fuzzControll.exception.CmdException
;
import
com.example.fuzzControll.pojo.vo.AjaxResult
;
import
com.example.fuzzControll.pojo.vo.CmdStartParams
;
...
...
@@ -39,8 +40,10 @@ public class TestControler {
}
});
alfnet
.
start
();
}
catch
(
AflnetException
|
CmdException
e
)
{
log
.
error
(
e
.
getDefaultMessage
());
}
catch
(
Exception
e
)
{
if
(
e
instanceof
AflnetException
||
e
instanceof
CmdException
){
log
.
error
(((
BaseException
)
e
).
getDefaultMessage
());
}
return
AjaxResult
.
error
(
"测试启动失败!"
);
}
return
AjaxResult
.
success
(
"测试已启动!"
);
...
...
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/WebSocket.java
deleted
100644 → 0
View file @
97a834df
package
com
.
example
.
fuzzControll
.
controller
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.websocket.*
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
java.io.IOException
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* @author
*/
@Component
(
"WebSocket"
)
@ServerEndpoint
(
"/websocket/testResult/{name}"
)
@Slf4j
public
class
WebSocket
{
private
Session
session
;
//与某个客户端连接对话,通过此对客户端发送消息
private
static
final
ConcurrentHashMap
<
String
,
WebSocket
>
WEBSOCKET_CONCURRENTHASHMAP
=
new
ConcurrentHashMap
<
String
,
WebSocket
>();
//存放所有连接的客户端
@OnOpen
public
void
onOpen
(
Session
session
,
@PathParam
(
value
=
"name"
)
String
name
)
{
this
.
session
=
session
;
//默认客户端,没有重名
WEBSOCKET_CONCURRENTHASHMAP
.
put
(
name
,
this
);
log
.
info
(
"Websocket is connected! The man is {}.There are {} people in the connection "
,
name
,
WEBSOCKET_CONCURRENTHASHMAP
.
size
());
}
@OnClose
public
void
onClose
()
{
for
(
String
name
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
if
(
this
==
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
))
{
WEBSOCKET_CONCURRENTHASHMAP
.
remove
(
name
);
break
;
}
}
log
.
info
(
"Websocket is closed! There are {} people in the connection "
,
WEBSOCKET_CONCURRENTHASHMAP
.
size
());
}
@OnError
public
void
onError
(
Session
session
,
Throwable
throwable
)
{
System
.
out
.
println
(
"error:"
);
throwable
.
printStackTrace
();
}
@OnMessage
public
void
onMessage
(
Session
session
,
String
message
)
{
System
.
out
.
println
(
"【webSocket接收成功】内容为:"
+
message
);
//此处可以指定发送,或者群发,或者xxxx的
if
(
message
.
indexOf
(
"name:"
)
==
0
)
{
String
name
=
message
.
substring
(
message
.
indexOf
(
"name"
)
+
5
,
message
.
indexOf
(
";"
));
for
(
String
senderStr
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
//获取sender的Stirng
if
(
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
senderStr
).
getSession
()
==
session
)
{
appointSending
(
senderStr
,
name
,
message
.
substring
(
message
.
indexOf
(
";"
)
+
1
));
}
}
}
else
{
groupSending
(
message
,
session
);
}
}
public
void
groupSending
(
String
message
,
Session
exIncludeSession
)
{
for
(
String
name
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
try
{
if
(
exIncludeSession
==
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
)
{
continue
;
}
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
name
+
":"
+
message
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
public
void
appointSending
(
String
sender
,
String
name
,
String
message
)
{
try
{
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(sender + ":" + message);
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
Session
getSession
()
{
return
session
;
}
}
\ No newline at end of file
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/WebsocketController.java
0 → 100644
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
controller
;
import
com.example.fuzzControll.service.websocketClientService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
@Slf4j
@RestController
@RequestMapping
(
"/websocket"
)
public
class
WebsocketController
{
@Autowired
websocketClientService
websocketClientService
;
@RequestMapping
(
value
=
"/connect"
,
method
=
RequestMethod
.
GET
)
public
void
connect
(){
try
{
websocketClientService
.
connect
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"Connect success!"
);
}
@RequestMapping
(
value
=
"/disConnect"
,
method
=
RequestMethod
.
GET
)
public
void
disConnect
(){
try
{
websocketClientService
.
disconnect
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"Disconnect success!"
);
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/websocketClientServiceImpl.java
0 → 100644
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.example.fuzzControll.conf.PathProperties
;
import
com.example.fuzzControll.service.websocketClientService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.java_websocket.client.WebSocketClient
;
import
org.java_websocket.handshake.ServerHandshake
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
@Slf4j
@Service
(
"websocketClientService"
)
public
class
websocketClientServiceImpl
implements
websocketClientService
{
public
static
WebSocketClient
webSocketClient
=
null
;
@Autowired
PathProperties
properties
;
@Override
public
void
connect
()
{
try
{
webSocketClient
=
new
WebSocketClient
(
new
URI
(
properties
.
getWebSocketUri
()+
"fuzzIntegration"
))
{
@Override
public
void
onOpen
(
ServerHandshake
serverHandshake
)
{
log
.
info
(
"connect..."
);
}
@Override
public
void
onMessage
(
String
s
)
{
log
.
info
(
"get message:{}"
,
s
);
}
@Override
public
void
onClose
(
int
i
,
String
s
,
boolean
b
)
{
log
.
info
(
"disconnect code:{} reason:{} {}"
,
i
,
s
,
b
);
}
@Override
public
void
onError
(
Exception
e
)
{
log
.
info
(
"connect error!"
);
}
};
webSocketClient
.
connect
();
}
catch
(
URISyntaxException
e
){
e
.
printStackTrace
();
}
}
@Override
public
void
disconnect
()
{
try
{
webSocketClient
.
close
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
fuzzIntegration/src/main/java/com/example/fuzzControll/service/websocketClientService.java
0 → 100644
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
service
;
import
org.java_websocket.client.WebSocketClient
;
public
interface
websocketClientService
{
void
connect
();
void
disconnect
();
}
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/CmdTools.java
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
tools
;
import
com.alibaba.fastjson.JSONObject
;
import
com.example.fuzzControll.conf.SpringContextUtil
;
import
com.example.fuzzControll.controller.WebSocket
;
import
com.example.fuzzControll.exception.AflnetException
;
import
com.example.fuzzControll.exception.CmdException
;
import
com.example.fuzzControll.exception.FuzzException
;
import
com.example.fuzzControll.pojo.vo.CmdStartParams
;
import
com.example.fuzzControll.pojo.vo.TestReturnEntity
;
import
com.example.fuzzControll.service.impl.websocketClientServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.*
;
import
java.util.*
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.locks.ReentrantLock
;
//todo need modify
@Slf4j
public
class
CmdTools
{
Boolean
send
=
false
;
WebSocket
socket
=
(
WebSocket
)
SpringContextUtil
.
getBean
(
"WebSocket"
);
Boolean
show
=
true
;
...
...
@@ -134,7 +130,7 @@ public class CmdTools {
if
(
send
)
{
String
data
=
JSONObject
.
toJSONString
(
returnEntity
);
try
{
socket
.
appointSending
(
"backend"
,
"web"
,
data
);
websocketClientServiceImpl
.
webSocketClient
.
send
(
data
);
}
catch
(
Exception
ignored
)
{
}
}
...
...
fuzzIntegration/src/main/resources/application-dev.yml
View file @
71336f1f
...
...
@@ -34,4 +34,5 @@ spring:
nacos
:
discovery
:
server-addr
:
http://192.168.50.247:8848
path
:
webSocketUri
:
"
ws://192.168.50.247:8101/websocket/testResult/"
fuzzIntegration/src/main/resources/application.yml
View file @
71336f1f
...
...
@@ -5,6 +5,6 @@ spring:
active
:
dev
#默认为开发环境
server
:
port
:
810
1
port
:
810
2
fuzzbackendmaster/log/spring.log
View file @
71336f1f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/Fuzz
backendmasterApplication
.java
→
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/Fuzz
BackendMaster
.java
View file @
71336f1f
...
...
@@ -3,12 +3,11 @@ package com.example.fuzzbackendmaster;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
@EnableFeignClients
@SpringBootApplication
public
class
FuzzbackendmasterApplication
{
@EnableFeignClients
public
class
FuzzBackendMaster
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Fuzz
backendmasterApplication
.
class
,
args
);
SpringApplication
.
run
(
Fuzz
BackendMaster
.
class
,
args
);
}
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/conf/SpringContextUtil.java
0 → 100644
View file @
71336f1f
/********************************************************************
* 版权所有(C)2023,中国电子科技集团公司第五十研究所。 *
* 文件名称: SpringContextUtil.java//文件名称
* 文件标识: QN2.489.437
* 内容摘要: 获取spring上下文//简要描述本文件的内容,包括主要模块、函数及其功能的说明
* 其它说明: 无
* 当前版本: V1.00.00
* 作者: 张思湛 中国电子科技集团公司电子科学研究院
* 完成日期: 2023年9月18日
* 修改记录1: // 修改历史记录,包括修改日期、修改者及修改内容
* 修改日期:
* 版本号:
* 修改人:
* 修改内容:
* 修改记录2: ……
********************************************************************/
package
com
.
example
.
fuzzbackendmaster
.
conf
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
@Component
public
class
SpringContextUtil
implements
ApplicationContextAware
{
private
static
ApplicationContext
applicationContext
;
public
SpringContextUtil
()
{
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
if
(
SpringContextUtil
.
applicationContext
==
null
)
{
SpringContextUtil
.
applicationContext
=
applicationContext
;
}
}
public
static
Object
getBean
(
String
name
)
{
return
applicationContext
.
getBean
(
name
);
}
public
static
Object
getBean
(
Class
<?>
requiredType
)
{
return
applicationContext
.
getBean
(
requiredType
);
}
}
fuzz
Integration/src/main/java/com/example/fuzzControll/conf/WebSocketConfig
.java
→
fuzz
backendmaster/src/main/java/com/example/fuzzbackendmaster/conf/WebsocketConf
.java
View file @
71336f1f
package
com
.
example
.
fuzzControll
.
conf
;
package
com
.
example
.
fuzzbackendmaster
.
conf
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.socket.server.standard.ServerEndpointExporter
;
@Configuration
public
class
WebSocketConfig
{
public
class
WebsocketConf
{
@Bean
public
ServerEndpointExporter
serverEndpointExporter
()
{
return
new
ServerEndpointExporter
();
}
}
\ No newline at end of file
}
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/KittyServerMessageController.java
View file @
71336f1f
//package com.example.fuzzbackendmaster.controller;
//
//
//import com.example.fuzzbackendmaster.exception.ServerException;
//import com.example.fuzzbackendmaster.pojo.vo.AjaxResult;
//import com.example.fuzzbackendmaster.service.KittyServerMessageApi;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//
//
///**
// * kitty服务器信息
// */
//@RestController
//@RequestMapping("/kittyServer")
//@Slf4j
//public class KittyServerMessageController {
//
// @Autowired
// KittyServerMessageApi kittyServerMessageApi;
// /**
// * 获取服务器stats信息
// */
// @RequestMapping(value = "/stats", method = RequestMethod.GET)
// public AjaxResult getStats( ) {
// try {
// return AjaxResult.success(kittyServerMessageApi.getStats());
// } catch (ServerException e) {
// log.error(e.getDefaultMessage());
// return AjaxResult.error("stats信息获取失败!");
// }
// }
// /**
// * 获取服务器templateInfo信息
// */
// @RequestMapping(value = "/templateInfo", method = RequestMethod.GET)
// public AjaxResult getTemplateInfo( ) {
// try {
// return AjaxResult.success(getServerMessageService.getTemplateInfo());
// } catch (ServerException e) {
// log.error(e.getDefaultMessage());
// return AjaxResult.error("templateInfo信息获取失败!");
// }
// }
// /**
// * 获取服务器stages信息
// */
// @RequestMapping(value = "/stages", method = RequestMethod.GET)
// public AjaxResult getStages( ) {
// try {
// return AjaxResult.success(getServerMessageService.getStages());
// } catch (ServerException e) {
// log.error(e.getDefaultMessage());
// return AjaxResult.error("stages信息获取失败!");
// }
// }
// /**
// * 获取服务器report信息
// */
// @RequestMapping(value = "/report", method = RequestMethod.GET)
// public AjaxResult getReport( ) {
// try {
// return AjaxResult.success(getServerMessageService.getReport());
// } catch (ServerException e) {
// log.error(e.getDefaultMessage());
// return AjaxResult.error("report信息获取失败!");
// }
// }
//}
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* kitty服务器信息
*/
@RestController
@RequestMapping
(
"/kittyServer"
)
@Slf4j
public
class
KittyServerMessageController
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
/**
* 获取服务器stats信息
*/
@RequestMapping
(
value
=
"/stats"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getStats
()
{
return
fuzzIntegrationFileApi
.
getStats
();
}
/**
* 获取服务器templateInfo信息
*/
@RequestMapping
(
value
=
"/templateInfo"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getTemplateInfo
()
{
return
fuzzIntegrationFileApi
.
getTemplateInfo
();
}
/**
* 获取服务器stages信息
*/
@RequestMapping
(
value
=
"/stages"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getStages
()
{
return
fuzzIntegrationFileApi
.
getStages
();
}
/**
* 获取服务器report信息
*/
//todo 了解该功能使用方式
@RequestMapping
(
value
=
"/report"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getReport
()
{
return
fuzzIntegrationFileApi
.
getReport
();
}
}
\ No newline at end of file
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/SeedFileController.java
View file @
71336f1f
...
...
@@ -29,6 +29,7 @@ public class SeedFileController {
*/
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
list
()
{
return
fuzzIntegrationFileApi
.
list
();
}
...
...
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/TestControler.java
→
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/TestControl
l
er.java
View file @
71336f1f
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.exception.AflnetException
;
import
com.example.fuzzbackendmaster.pojo.vo.AjaxResult
;
import
com.example.fuzzbackendmaster.pojo.vo.CmdStartParams
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
...
...
@@ -17,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping
(
"/test"
)
public
class
TestControler
{
public
class
TestControl
l
er
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
...
...
@@ -25,7 +24,9 @@ public class TestControler {
* 测试启动
*/
@RequestMapping
(
value
=
"/testStart"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
list
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
public
AjaxResult
testStart
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
//启动时就开始连接
fuzzIntegrationFileApi
.
connect
();
return
fuzzIntegrationFileApi
.
testStart
(
cmdStartParams
);
}
...
...
@@ -34,6 +35,8 @@ public class TestControler {
*/
@RequestMapping
(
value
=
"/testStop"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
testStop
()
{
//停止时就开始关闭
fuzzIntegrationFileApi
.
disconnect
();
return
fuzzIntegrationFileApi
.
testStop
();
}
...
...
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/WebSocket.java
View file @
71336f1f
//package com.example.fuzzbackendmaster.controller;
//
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.websocket.*;
//import javax.websocket.server.PathParam;
//import javax.websocket.server.ServerEndpoint;
//import java.io.IOException;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @author
// */
//@Component("WebSocket")
//@ServerEndpoint("/websocket/testResult/{name}")
//@Slf4j
//public class WebSocket {
//
// private Session session; //与某个客户端连接对话,通过此对客户端发送消息
// private static final ConcurrentHashMap<String, WebSocket> WEBSOCKET_CONCURRENTHASHMAP = new ConcurrentHashMap<String, WebSocket>(); //存放所有连接的客户端
//
//
// @OnOpen
// public void onOpen(Session session, @PathParam(value = "name") String name) {
// this.session = session; //默认客户端,没有重名
// WEBSOCKET_CONCURRENTHASHMAP.put(name, this);
// log.info("Websocket is connected! The man is {}.There are {} people in the connection ",name,WEBSOCKET_CONCURRENTHASHMAP.size());
// }
//
//
// @OnClose
// public void onClose() {
//
// for (String name : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {
//
// if (this == WEBSOCKET_CONCURRENTHASHMAP.get(name)) {
//
// WEBSOCKET_CONCURRENTHASHMAP.remove(name);
// break;
// }
// }
//
// log.info("Websocket is closed! There are {} people in the connection ",WEBSOCKET_CONCURRENTHASHMAP.size());
// }
//
// @OnError
// public void onError(Session session, Throwable throwable) {
//
// System.out.println("error:");
// throwable.printStackTrace();
// }
//
// @OnMessage
// public void onMessage(Session session, String message) {
//
// System.out.println("【webSocket接收成功】内容为:" + message); //此处可以指定发送,或者群发,或者xxxx的
//
// if (message.indexOf("name:") == 0) {
//
// String name = message.substring(message.indexOf("name") + 5, message.indexOf(";"));
//
//
// for (String senderStr : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {//获取sender的Stirng
//
// if (WEBSOCKET_CONCURRENTHASHMAP.get(senderStr).getSession() == session) {
//
// appointSending(senderStr, name, message.substring(message.indexOf(";") + 1));
// }
// }
// } else {
//
// groupSending(message, session);
// }
// }
//
//
// public void groupSending(String message, Session exIncludeSession) {
//
// for (String name : WEBSOCKET_CONCURRENTHASHMAP.keySet()) {
//
// try {
// if (exIncludeSession == WEBSOCKET_CONCURRENTHASHMAP.get(name).session) {
// continue;
// }
//
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(name + ":" + message);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
//
//
// public void appointSending(String sender, String name, String message) {
// try {
//// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(sender + ":" + message);
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(message);
//
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// public Session getSession() {
// return session;
// }
//}
\ No newline at end of file
package
com
.
example
.
fuzzbackendmaster
.
controller
;
import
com.example.fuzzbackendmaster.conf.SpringContextUtil
;
import
com.example.fuzzbackendmaster.service.FuzzIntegrationFileApi
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.messaging.handler.annotation.SendTo
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.socket.client.WebSocketClient
;
import
javax.websocket.*
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* @author
*/
@Component
@ServerEndpoint
(
"/websocket/testResult/{name}"
)
@Slf4j
public
class
WebSocket
{
private
Session
session
;
//与某个客户端连接对话,通过此对客户端发送消息
private
static
final
ConcurrentHashMap
<
String
,
WebSocket
>
WEBSOCKET_CONCURRENTHASHMAP
=
new
ConcurrentHashMap
<
String
,
WebSocket
>();
//存放所有连接的客户端
private
static
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
@Autowired
public
void
setOrderService
(
FuzzIntegrationFileApi
fuzzIntegrationFileApi
)
{
WebSocket
.
fuzzIntegrationFileApi
=
fuzzIntegrationFileApi
;
}
@OnOpen
public
void
onOpen
(
Session
session
,
@PathParam
(
value
=
"name"
)
String
name
)
{
this
.
session
=
session
;
//默认客户端,没有重名
WEBSOCKET_CONCURRENTHASHMAP
.
put
(
name
,
this
);
log
.
info
(
"Websocket is connected! The man is {}.There are {} people in the connection "
,
name
,
WEBSOCKET_CONCURRENTHASHMAP
.
size
());
}
@OnClose
public
void
onClose
()
{
for
(
String
name
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
if
(
this
==
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
))
{
WEBSOCKET_CONCURRENTHASHMAP
.
remove
(
name
);
break
;
}
}
log
.
info
(
"Websocket is closed! There are {} people in the connection "
,
WEBSOCKET_CONCURRENTHASHMAP
.
size
());
}
@OnError
public
void
onError
(
Session
session
,
Throwable
throwable
)
{
System
.
out
.
println
(
"error:"
);
throwable
.
printStackTrace
();
}
@OnMessage
// @SendTo("")
public
void
onMessage
(
Session
session
,
String
message
)
{
for
(
String
senderStr
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
//获取sender的Stirng
if
(
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
senderStr
).
getSession
()
==
session
)
{
appointSending
(
"fuzzMaster"
,
"web"
,
message
.
substring
(
message
.
indexOf
(
";"
)
+
1
));
}
}
}
public
void
groupSending
(
String
message
,
Session
exIncludeSession
)
{
for
(
String
name
:
WEBSOCKET_CONCURRENTHASHMAP
.
keySet
())
{
try
{
if
(
exIncludeSession
==
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
)
{
continue
;
}
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
name
+
":"
+
message
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
public
void
appointSending
(
String
sender
,
String
name
,
String
message
)
{
try
{
// WEBSOCKET_CONCURRENTHASHMAP.get(name).session.getBasicRemote().sendText(sender + ":" + message);
WEBSOCKET_CONCURRENTHASHMAP
.
get
(
name
).
session
.
getBasicRemote
().
sendText
(
message
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
Session
getSession
()
{
return
session
;
}
}
\ No newline at end of file
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
71336f1f
...
...
@@ -6,17 +6,17 @@ import com.example.fuzzbackendmaster.pojo.vo.TestEntity;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
@Component
@FeignClient
(
value
=
"fuzz-backend-integration"
)
public
interface
FuzzIntegrationFileApi
{
/**
* seedFlole
*
*/
@RequestMapping
(
value
=
"/seedFile/list"
,
method
=
RequestMethod
.
GET
)
AjaxResult
list
();
...
...
@@ -26,9 +26,9 @@ public interface FuzzIntegrationFileApi {
@RequestMapping
(
value
=
"/seedFile/delete"
,
method
=
RequestMethod
.
GET
,
consumes
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
AjaxResult
delFile
(
@RequestPart
(
"fileName"
)
String
fileName
);
/**
* testclass
*
*/
@RequestMapping
(
value
=
"/testClass/protocolTemplate"
,
method
=
RequestMethod
.
POST
)
AjaxResult
protocolTemplate
(
@RequestBody
TestEntity
testEntity
);
...
...
@@ -43,11 +43,28 @@ public interface FuzzIntegrationFileApi {
AjaxResult
vulnerability
(
@RequestBody
TestEntity
testEntity
);
/**
*
* Aflnet
*/
@RequestMapping
(
value
=
"/test/testStop"
,
method
=
RequestMethod
.
GET
)
AjaxResult
testStop
();
@RequestMapping
(
value
=
"/test/testStart"
,
method
=
RequestMethod
.
POST
)
AjaxResult
testStart
(
@RequestBody
final
CmdStartParams
cmdStartParams
);
@RequestMapping
(
value
=
"/kittyServer/stats"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getStats
();
@RequestMapping
(
value
=
"/kittyServer/templateInfo"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getTemplateInfo
();
@RequestMapping
(
value
=
"/kittyServer/stages"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getStages
();
@RequestMapping
(
value
=
"/kittyServer/report"
,
method
=
RequestMethod
.
GET
)
AjaxResult
getReport
();
/**
* websocket
*/
@RequestMapping
(
value
=
"/websocket/connect"
,
method
=
RequestMethod
.
GET
)
void
connect
();
@RequestMapping
(
value
=
"/websocket/disConnect"
,
method
=
RequestMethod
.
GET
)
void
disconnect
();
}
fuzzbackendmaster/src/main/resources/application.yml
View file @
71336f1f
...
...
@@ -5,6 +5,6 @@ spring:
active
:
dev
#默认为开发环境
server
:
port
:
810
2
port
:
810
1
fuzzbackendmaster/src/main/resources/result.html
View file @
71336f1f
...
...
@@ -8,7 +8,7 @@
var
ws1
=
null
;
var
ws2
=
null
;
function
myFunction
()
{
ws1
=
new
WebSocket
(
"ws://
localhost:8200/websocket/testResult/"
+
"
web"
);
ws1
=
new
WebSocket
(
"ws://
192.168.50.247:8101/websocket/testResult/
web"
);
ws1
.
onmessage
=
function
(
evt
)
{
console
.
log
(
evt
);
var
received_msg
=
JSON
.
parse
(
evt
.
data
)
;
...
...
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