File tree Expand file tree Collapse file tree 4 files changed +44
-4
lines changed
src/main/java/org/cecd/server Expand file tree Collapse file tree 4 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ dependencies {
3737 implementation(" software.amazon.awssdk:s3:2.21.0" )
3838 // actuator
3939 implementation ' org.springframework.boot:spring-boot-starter-actuator'
40- // Spring Security
40+ // Spring Security
4141 implementation ' org.springframework.boot:spring-boot-starter-security'
4242 testImplementation ' org.springframework.security:spring-security-test'
4343 // JWT Token
@@ -48,10 +48,13 @@ dependencies {
4848 implementation ' org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
4949 // Jsoup
5050 implementation ' org.jsoup:jsoup:1.18.1'
51- // JSON 라이브러리
51+ // JSON
5252 implementation ' org.json:json:20231013'
53- // Apache HttpClient 라이브러리
53+ // Apache HttpClient
5454 implementation ' org.apache.httpcomponents.client5:httpclient5:5.2.1'
55+ // Web Socket
56+ implementation ' org.springframework.boot:spring-boot-starter-websocket'
57+ implementation ' org.springframework.boot:spring-boot-starter-web'
5558}
5659
5760tasks. named(' test' ) {
Original file line number Diff line number Diff line change 44import org .cecd .server .dto .CommandRequest ;
55import org .cecd .server .service .CommandService ;
66import org .springframework .http .ResponseEntity ;
7+ import org .springframework .messaging .handler .annotation .MessageMapping ;
8+ import org .springframework .messaging .handler .annotation .SendTo ;
79import org .springframework .web .bind .annotation .*;
810
911@ RestController
@@ -23,4 +25,11 @@ public ResponseEntity<String> sendControlCommand(@RequestBody CommandRequest com
2325 public ResponseEntity <CommandRequest > echoControlCommand (@ RequestBody CommandRequest commandRequest ) {
2426 return ResponseEntity .ok (commandRequest );
2527 }
28+
29+ @ MessageMapping ("/socket/control" ) // 클라이언트가 이 경로로 메시지를 송신
30+ @ SendTo ("/topic/commands" ) // 이 경로를 구독 중인 모든 클라이언트에게 메시지 전달
31+ public CommandRequest sendCommand (CommandRequest commandRequest ) {
32+ System .out .println ("Received command: " + commandRequest ); // 로그 추가
33+ return commandRequest ; // command는 클라이언트로 전달할 메시지
34+ }
2635}
Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
4545 .authorizeHttpRequests (authorize -> authorize // 권한 설정
4646 .requestMatchers ("/jwt-login/info" ).authenticated ()
4747 .requestMatchers ("/jwt-login/admin/**" ).hasAuthority (MemberRole .ADMIN .name ())
48- .anyRequest ().permitAll ()
48+ .requestMatchers ("/ws/**" ).permitAll () // WebSocket 엔드포인트 허용
49+ .anyRequest ().permitAll () // 추후 수정 예정
4950 )
5051 .exceptionHandling (exceptionHandling ->
5152 exceptionHandling
Original file line number Diff line number Diff line change 1+ package org .cecd .server .external ;
2+
3+ import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .messaging .simp .config .MessageBrokerRegistry ;
5+ import org .springframework .web .socket .config .annotation .EnableWebSocketMessageBroker ;
6+ import org .springframework .web .socket .config .annotation .StompEndpointRegistry ;
7+ import org .springframework .web .socket .config .annotation .WebSocketMessageBrokerConfigurer ;
8+
9+ @ Configuration
10+ @ EnableWebSocketMessageBroker
11+ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
12+
13+ @ Override
14+ public void configureMessageBroker (MessageBrokerRegistry config ) {
15+ config .enableSimpleBroker ("/topic" );
16+ config .setApplicationDestinationPrefixes ("/app" );
17+ }
18+
19+ @ Override
20+ public void registerStompEndpoints (StompEndpointRegistry registry ) {
21+ registry .addEndpoint ("/ws" )
22+ .setAllowedOriginPatterns ("http://localhost:3000" ,"https://www.dgu1921.p-e.kr" )
23+ .withSockJS ();
24+ }
25+ }
26+
27+
You can’t perform that action at this time.
0 commit comments