This commit is contained in:
2025-09-14 12:09:13 +02:00
parent 03d5952652
commit ca34aec0ba
4 changed files with 28 additions and 207 deletions

View File

@@ -27,8 +27,8 @@ import java.util.List;
import java.util.Map;
/**
* STOMP message controller for handling real-time communication with apps.
* Provides endpoints for sending and receiving messages via WebSocket/STOMP.
* MQTT message controller for handling real-time communication with apps.
* Provides endpoints for sending and receiving messages via WebSocket/MQTT.
*/
@Component
@Slf4j
@@ -59,14 +59,14 @@ public class MessageController {
* Handles messages sent to /app/message and broadcasts them to all subscribers of /topic/messages
*/
public Map<String, Object> handleMessage(Map<String, Object> message) {
log.error("=== ANY MESSAGE RECEIVED === STOMP Endpoint '/app/message' called");
log.info("STOMP Endpoint '/app/message' called with data: {}", message);
log.error("=== ANY MESSAGE RECEIVED === MQTT Endpoint '/app/message' called");
log.info("MQTT Endpoint '/app/message' called with data: {}", message);
// Add timestamp to the message
message.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
message.put("processed", true);
log.info("STOMP Response for '/app/message' sent to '/topic/messages': {}", message);
log.info("MQTT Response for '/app/message' sent to '/topic/messages': {}", message);
return message;
}
@@ -74,12 +74,12 @@ public class MessageController {
* Handles job status updates from apps
*/
public Map<String, Object> handleJobStatusUpdate(Map<String, Object> jobUpdate) {
log.info("STOMP Endpoint '/app/job/status' called with data: {}", jobUpdate);
log.info("MQTT Endpoint '/app/job/status' called with data: {}", jobUpdate);
jobUpdate.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
jobUpdate.put("source", "app");
log.info("STOMP Response for '/app/job/status' sent to '/topic/job-updates': {}", jobUpdate);
log.info("MQTT Response for '/app/job/status' sent to '/topic/job-updates': {}", jobUpdate);
return jobUpdate;
}
@@ -87,12 +87,12 @@ public class MessageController {
* Handles device location updates from mobile apps
*/
public Map<String, Object> handleDeviceLocation(Map<String, Object> locationUpdate) {
log.info("STOMP Endpoint '/app/device/location' called with data: {}", locationUpdate);
log.info("MQTT Endpoint '/app/device/location' called with data: {}", locationUpdate);
locationUpdate.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
locationUpdate.put("processed", true);
log.info("STOMP Response for '/app/device/location' sent to '/topic/device-locations': {}", locationUpdate);
log.info("MQTT Response for '/app/device/location' sent to '/topic/device-locations': {}", locationUpdate);
return locationUpdate;
}
@@ -127,18 +127,18 @@ public class MessageController {
}
/**
* Authentication endpoint for mobile app users via STOMP.
* Authentication endpoint for mobile app users via MQTT.
* Client sends to /app/auth/login with payload { email, password }.
* The response is sent back to the requesting user on /user/queue/auth
*/
public AppLoginResponse handleAppLogin(AppLoginRequest request) {
log.info("STOMP Endpoint '/app/auth/login' called with email: {}",
log.info("MQTT Endpoint '/app/auth/login' called with email: {}",
request != null ? request.getEmail() : "null");
if (request == null || request.getEmail() == null || request.getPassword() == null
|| request.getEmail().isBlank() || request.getPassword().isBlank()) {
AppLoginResponse response = new AppLoginResponse(false, "E-Mail und Passwort sind erforderlich", null, null, null);
log.info("STOMP Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
log.info("MQTT Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
false, "E-Mail und Passwort sind erforderlich");
return response;
}
@@ -146,7 +146,7 @@ public class MessageController {
AppUser user = appUserRepository.findByEmail(request.getEmail());
if (user == null) {
AppLoginResponse response = new AppLoginResponse(false, "Benutzer nicht gefunden", null, null, null);
log.info("STOMP Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
log.info("MQTT Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
false, "Benutzer nicht gefunden");
return response;
}
@@ -154,13 +154,13 @@ public class MessageController {
boolean ok = appUserService.verifyPassword(request.getPassword(), user.getPassword());
if (!ok) {
AppLoginResponse response = new AppLoginResponse(false, "Ungültige Anmeldedaten", null, null, null);
log.info("STOMP Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
log.info("MQTT Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}'",
false, "Ungültige Anmeldedaten");
return response;
}
AppLoginResponse response = new AppLoginResponse(true, "Anmeldung erfolgreich", null, null, user.getIdAsString());
log.info("STOMP Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}', appUserId='{}'",
log.info("MQTT Response for '/app/auth/login' sent to '/user/queue/auth': success={}, message='{}', appUserId='{}'",
true, "Anmeldung erfolgreich", response.getAppUserId());
return response;
}
@@ -171,17 +171,17 @@ public class MessageController {
* The response is sent back to the requesting user on /user/queue/jobs
*/
public List<JobWithRelatedDataDTO> handleGetAssignedJobs(Map<String, Object> request) {
log.info("STOMP Endpoint '/app/jobs/assigned' called with data: {}", request);
log.debug("Starting to process jobs request for STOMP endpoint");
log.info("MQTT Endpoint '/app/jobs/assigned' called with data: {}", request);
log.debug("Starting to process jobs request for MQTT endpoint");
if (request == null || !request.containsKey("appUserId")) {
log.info("STOMP Response for '/app/jobs/assigned' sent to '/user/queue/jobs': empty list (no appUserId provided)");
log.info("MQTT Response for '/app/jobs/assigned' sent to '/user/queue/jobs': empty list (no appUserId provided)");
return List.of(); // Return empty list if no appUserId provided
}
String appUserId = request.get("appUserId").toString();
if (appUserId == null || appUserId.isBlank()) {
log.info("STOMP Response for '/app/jobs/assigned' sent to '/user/queue/jobs': empty list (appUserId is blank)");
log.info("MQTT Response for '/app/jobs/assigned' sent to '/user/queue/jobs': empty list (appUserId is blank)");
return List.of(); // Return empty list if appUserId is blank
}
@@ -205,7 +205,7 @@ public class MessageController {
})
.toList();
log.info("STOMP Response for '/app/jobs/assigned' sent to '/user/queue/jobs': {} jobs with related data found for appUserId='{}'",
log.info("MQTT Response for '/app/jobs/assigned' sent to '/user/queue/jobs': {} jobs with related data found for appUserId='{}'",
jobsWithRelatedData.size(), appUserId);
// Log complete JSON for debugging
@@ -214,7 +214,7 @@ public class MessageController {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
String jsonOutput = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jobsWithRelatedData);
log.info("=== COMPLETE JSON RESPONSE FOR STOMP CLIENT ===");
log.info("=== COMPLETE JSON RESPONSE FOR MQTT CLIENT ===");
log.info("AppUserId: {}", appUserId);
log.info("Number of jobs: {}", jobsWithRelatedData.size());
log.info("JSON Data:\n{}", jsonOutput);
@@ -233,7 +233,7 @@ public class MessageController {
* This endpoint accepts any task type (fallback for GENERIC or unknown types).
*/
public Map<String, Object> handleTaskCompleted(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/completed' called with data: {}", payload);
log.info("MQTT Endpoint '/app/task/completed' called with data: {}", payload);
return processTaskCompletion(payload, null); // null means accept any task type
}
@@ -243,7 +243,7 @@ public class MessageController {
* Broadcasts to /topic/task-updates and /topic/tasks/{taskId}.
*/
public Map<String, Object> handleTaskConfirmation(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/confirm' called with data: {}", payload);
log.info("MQTT Endpoint '/app/task/confirm' called with data: {}", payload);
return processTaskCompletion(payload, "CONFIRMATION");
}
@@ -254,7 +254,7 @@ public class MessageController {
* Broadcasts to /topic/task-updates and /topic/tasks/{taskId}.
*/
public Map<String, Object> handlePhotoTaskCompleted(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/photo/completed' called");
log.info("MQTT Endpoint '/app/task/photo/completed' called");
return processPhotoTaskCompletion(payload);
}
@@ -264,7 +264,7 @@ public class MessageController {
* Broadcasts to /topic/task-updates and /topic/tasks/{taskId}.
*/
public Map<String, Object> handleSignatureTaskCompleted(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/signature/completed' called with data: {}", payload);
log.info("MQTT Endpoint '/app/task/signature/completed' called with data: {}", payload);
return processTaskCompletion(payload, "SIGNATURE");
}
@@ -274,7 +274,7 @@ public class MessageController {
* Broadcasts to /topic/task-updates and /topic/tasks/{taskId}.
*/
public Map<String, Object> handleBarcodeTaskCompleted(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/barcode/completed' called with data: {}", payload);
log.info("MQTT Endpoint '/app/task/barcode/completed' called with data: {}", payload);
return processTaskCompletion(payload, "BARCODE");
}
@@ -284,7 +284,7 @@ public class MessageController {
* Broadcasts to /topic/task-updates and /topic/tasks/{taskId}.
*/
public Map<String, Object> handleTodolistTaskCompleted(Map<String, Object> payload) {
log.info("STOMP Endpoint '/app/task/todolist/completed' called with data: {}", payload);
log.info("MQTT Endpoint '/app/task/todolist/completed' called with data: {}", payload);
return processTaskCompletion(payload, "TODOLIST");
}

View File

@@ -45,7 +45,7 @@ public class SecurityConfig extends VaadinWebSecurity {
).permitAll()
);
// Standard-CSRF-Konfiguration (keine speziellen WebSocket/STOMP-Ausnahmen mehr notwendig)
// Standard-CSRF-Konfiguration
http.csrf(csrf -> csrf
.ignoringRequestMatchers(
new AntPathRequestMatcher("/h2-console/**")

View File

@@ -37,8 +37,6 @@ server.tomcat.max-swallow-size=64MB
# Multipart upload limits for photo HTTP uploads
spring.servlet.multipart.max-file-size=32MB
spring.servlet.multipart.max-request-size=64MB
# Additional WebSocket and messaging limits for large payloads
# STOMP broker relay limits
# Jackson message converter limits
spring.jackson.default-property-inclusion=non_null