-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Chat-Your-Way/CHAT-52--message-routing
Chat 52 message routing
- Loading branch information
Showing
26 changed files
with
516 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/chat/yourway/config/redis/RedisProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.chat.yourway.config.redis; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "spring.data.redis") | ||
@Getter | ||
@Setter | ||
public class RedisProperties { | ||
|
||
private String host; | ||
private int port; | ||
private String password; | ||
|
||
@Value("${spring.profiles.active}") | ||
private String profile; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/chat/yourway/config/websocket/WebsocketProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.chat.yourway.config.websocket; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "socket") | ||
@Getter | ||
@Setter | ||
public class WebsocketProperties { | ||
|
||
private String[] destPrefixes; | ||
private String appPrefix; | ||
private String endpoint; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/chat/yourway/dto/response/MessageErrorResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.chat.yourway.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@ToString | ||
public class MessageErrorResponseDto<T> { | ||
|
||
private final LocalDateTime timestamp = LocalDateTime.now(); | ||
private final String sentFrom = "Server"; | ||
private T message; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/chat/yourway/exception/handler/WebsocketExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.chat.yourway.exception.handler; | ||
|
||
import com.chat.yourway.dto.response.MessageErrorResponseDto; | ||
import com.chat.yourway.exception.TopicNotFoundException; | ||
import com.chat.yourway.exception.TopicSubscriberNotFoundException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.springframework.messaging.handler.annotation.MessageExceptionHandler; | ||
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; | ||
import org.springframework.messaging.simp.annotation.SendToUser; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
|
||
@ControllerAdvice | ||
public class WebsocketExceptionHandler { | ||
|
||
@MessageExceptionHandler({ | ||
TopicNotFoundException.class, | ||
TopicSubscriberNotFoundException.class | ||
}) | ||
@SendToUser("/specific") | ||
public MessageErrorResponseDto<String> handleException(RuntimeException e) { | ||
return new MessageErrorResponseDto<>(e.getMessage()); | ||
} | ||
|
||
@MessageExceptionHandler(MethodArgumentNotValidException.class) | ||
@SendToUser("/specific") | ||
public MessageErrorResponseDto<List<String>> handleValidationException( | ||
MethodArgumentNotValidException e) { | ||
List<FieldError> fieldErrors = Objects.requireNonNull(e.getBindingResult()).getFieldErrors(); | ||
List<String> errorMessages = fieldErrors.stream() | ||
.map(err -> String.format("Invalid '%s': %s", err.getField(), err.getDefaultMessage())) | ||
.toList(); | ||
return new MessageErrorResponseDto<>(errorMessages); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.