Fuck it, no memory cleanse
This commit is contained in:
@@ -17,7 +17,9 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -26,7 +28,7 @@ public class ChatController {
|
|||||||
private final MessageService messageService;
|
private final MessageService messageService;
|
||||||
private final WebexService webexService;
|
private final WebexService webexService;
|
||||||
private final MqttService mqttService;
|
private final MqttService mqttService;
|
||||||
private final ConcurrentHashMap<String, Integer> expectedMessages;
|
private final Set<String> expectedMessages;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ChatController(
|
public ChatController(
|
||||||
@@ -36,7 +38,7 @@ public class ChatController {
|
|||||||
this.messageService = messageService;
|
this.messageService = messageService;
|
||||||
this.webexService = webexService;
|
this.webexService = webexService;
|
||||||
this.mqttService = mqttService;
|
this.mqttService = mqttService;
|
||||||
this.expectedMessages = new ConcurrentHashMap<>();
|
this.expectedMessages = ConcurrentHashMap.newKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/message/send")
|
@PostMapping("/message/send")
|
||||||
@@ -108,10 +110,11 @@ public class ChatController {
|
|||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
WebexWebhook payload = mapper.readValue(rawPayload, WebexWebhook.class);
|
WebexWebhook payload = mapper.readValue(rawPayload, WebexWebhook.class);
|
||||||
|
String messageId = payload.getData().getId();
|
||||||
|
|
||||||
boolean firstTime = expectedMessages.putIfAbsent(payload.getData().getId(), 1) == null;
|
boolean firstTime = expectedMessages.add(messageId);
|
||||||
if (!firstTime) {
|
if (!firstTime) {
|
||||||
Logger.displayInfo("Rejected message: " + payload.getData().getId());
|
Logger.displayInfo("Duplicate or already processed → Rejected: " + messageId);
|
||||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user