Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
springBoot
Project
Project
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
WitCloud
springBoot
Commits
f17d0e74
Commit
f17d0e74
authored
Apr 18, 2017
by
杨伊博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify Websocket package
parent
5e2d5fa2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
23 deletions
+18
-23
WebMvcConfig.java
...ket/src/main/java/com/us/example/config/WebMvcConfig.java
+0
-17
WebSecurityConfig.java
...rc/main/java/com/us/example/config/WebSecurityConfig.java
+2
-2
WebSocketController.java
...n/java/com/us/example/controller/WebSocketController.java
+15
-3
application.properties
springWebSocket/src/main/resources/application.properties
+1
-1
No files found.
springWebSocket/src/main/java/com/us/example/config/WebMvcConfig.java
deleted
100755 → 0
View file @
5e2d5fa2
package
com
.
us
.
example
.
config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
@Configuration
public
class
WebMvcConfig
extends
WebMvcConfigurerAdapter
{
//为ws.HTML 提供便捷的路径映射。
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
registry
.
addViewController
(
"/ws"
).
setViewName
(
"/ws"
);
registry
.
addViewController
(
"/login"
).
setViewName
(
"/login"
);
registry
.
addViewController
(
"/chat"
).
setViewName
(
"/chat"
);
}
}
springWebSocket/src/main/java/com/us/example/config/WebSecurityConfig.java
View file @
f17d0e74
...
...
@@ -31,9 +31,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
inMemoryAuthentication
()
.
withUser
(
"
wyf"
).
password
(
"wyf
"
).
roles
(
"USER"
)
.
withUser
(
"
admin"
).
password
(
"admin
"
).
roles
(
"USER"
)
.
and
()
.
withUser
(
"
wisely"
).
password
(
"wisely
"
).
roles
(
"USER"
);
.
withUser
(
"
abel"
).
password
(
"abel
"
).
roles
(
"USER"
);
}
//5忽略静态资源的拦截
@Override
...
...
springWebSocket/src/main/java/com/us/example/controller/WebSocketController.java
View file @
f17d0e74
...
...
@@ -29,6 +29,18 @@ public class WebSocketController {
private
SimpMessagingTemplate
messagingTemplate
;
@RequestMapping
(
value
=
"/login"
)
public
String
login
(){
return
"login"
;
}
@RequestMapping
(
value
=
"/ws"
)
public
String
ws
(){
return
"ws"
;
}
@RequestMapping
(
value
=
"/chat"
)
public
String
chat
(){
return
"chat"
;
}
//http://localhost:8080/ws
@MessageMapping
(
"/welcome"
)
//浏览器发送请求通过@messageMapping 映射/welcome 这个地址。
@SendTo
(
"/topic/getResponse"
)
//服务器端有消息时,会订阅@SendTo 中的路径的浏览器发送消息。
...
...
@@ -54,15 +66,15 @@ public class WebSocketController {
* 此处是一段硬编码。如果发送人是wyf 则发送给 wisely 如果发送人是wisely 就发送给 wyf。
* 通过当前用户,然后查找消息,如果查找到未读消息,则发送给当前用户。
*/
if
(
principal
.
getName
().
equals
(
"
wyf
"
))
{
if
(
principal
.
getName
().
equals
(
"
admin
"
))
{
//通过convertAndSendToUser 向用户发送信息,
// 第一个参数是接收消息的用户,第二个参数是浏览器订阅的地址,第三个参数是消息本身
messagingTemplate
.
convertAndSendToUser
(
"
wisely
"
,
messagingTemplate
.
convertAndSendToUser
(
"
abel
"
,
"/queue/notifications"
,
principal
.
getName
()
+
"-send:"
+
message
.
getName
());
}
else
{
messagingTemplate
.
convertAndSendToUser
(
"
wyf
"
,
messagingTemplate
.
convertAndSendToUser
(
"
admin
"
,
"/queue/notifications"
,
principal
.
getName
()
+
"-send:"
+
message
.
getName
());
}
...
...
springWebSocket/src/main/resources/application.properties
View file @
f17d0e74
server.port
=
8081
\ No newline at end of file
server.port
=
8090
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