Erweiterungen
This commit is contained in:
36
src/main/java/de/assecutor/votianlt/config/MailConfig.java
Normal file
36
src/main/java/de/assecutor/votianlt/config/MailConfig.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package de.assecutor.votianlt.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MailConfig {
|
||||
|
||||
@Value("${mail.smtp.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${mail.smtp.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${mail.smtp.host:smtp.gmail.com}")
|
||||
private String host;
|
||||
|
||||
@Value("${mail.smtp.port:587}")
|
||||
private int port;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package de.assecutor.votianlt.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
|
||||
/**
|
||||
* WebSocket configuration for STOMP messaging.
|
||||
* Enables real-time communication with client applications.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry config) {
|
||||
// Enable a simple memory-based message broker to carry messages back to client
|
||||
// on destinations prefixed with "/topic" and "/queue"
|
||||
config.enableSimpleBroker("/topic", "/queue");
|
||||
|
||||
// Designate the "/app" prefix for messages that are bound to methods
|
||||
// annotated with @MessageMapping
|
||||
config.setApplicationDestinationPrefixes("/app");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
// Register the "/ws" endpoint for WebSocket connections
|
||||
// withSockJS() enables SockJS fallback options for browsers that don't support WebSocket
|
||||
registry.addEndpoint("/ws").withSockJS();
|
||||
|
||||
// Also add a plain WebSocket endpoint without SockJS for native WebSocket clients
|
||||
registry.addEndpoint("/websocket");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package de.assecutor.votianlt.controller;
|
||||
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* STOMP message controller for handling real-time communication with apps.
|
||||
* Provides endpoints for sending and receiving messages via WebSocket/STOMP.
|
||||
*/
|
||||
@Controller
|
||||
public class MessageController {
|
||||
|
||||
@Autowired
|
||||
private SimpMessagingTemplate messagingTemplate;
|
||||
|
||||
/**
|
||||
* Handles messages sent to /app/message and broadcasts them to all subscribers of /topic/messages
|
||||
*/
|
||||
@MessageMapping("/message")
|
||||
@SendTo("/topic/messages")
|
||||
public Map<String, Object> handleMessage(Map<String, Object> message) {
|
||||
// Add timestamp to the message
|
||||
message.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
message.put("processed", true);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles job status updates from apps
|
||||
*/
|
||||
@MessageMapping("/job/status")
|
||||
@SendTo("/topic/job-updates")
|
||||
public Map<String, Object> handleJobStatusUpdate(Map<String, Object> jobUpdate) {
|
||||
jobUpdate.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
jobUpdate.put("source", "app");
|
||||
|
||||
return jobUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles device location updates from mobile apps
|
||||
*/
|
||||
@MessageMapping("/device/location")
|
||||
@SendTo("/topic/device-locations")
|
||||
public Map<String, Object> handleDeviceLocation(Map<String, Object> locationUpdate) {
|
||||
locationUpdate.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
locationUpdate.put("processed", true);
|
||||
|
||||
return locationUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification to specific user
|
||||
*/
|
||||
public void sendNotificationToUser(String username, String message) {
|
||||
Map<String, Object> notification = Map.of(
|
||||
"message", message,
|
||||
"timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||
"type", "notification"
|
||||
);
|
||||
|
||||
messagingTemplate.convertAndSendToUser(username, "/queue/notifications", notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send broadcast message to all connected clients
|
||||
*/
|
||||
public void sendBroadcastMessage(String message) {
|
||||
Map<String, Object> broadcast = Map.of(
|
||||
"message", message,
|
||||
"timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||
"type", "broadcast"
|
||||
);
|
||||
|
||||
messagingTemplate.convertAndSend("/topic/broadcasts", broadcast);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.assecutor.votianlt.util;
|
||||
|
||||
import de.assecutor.votianlt.config.MailConfig;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.PasswordAuthentication;
|
||||
@@ -7,15 +8,26 @@ import jakarta.mail.Session;
|
||||
import jakarta.mail.Transport;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class MailUtil {
|
||||
public static void sendMail(String to, String subject, String body) throws MessagingException {
|
||||
// SMTP-Konfiguration (hier Beispiel für Gmail, anpassen für Produktivsystem!)
|
||||
final String username = "your-email@gmail.com"; // TODO: ersetzen
|
||||
final String password = "your-password"; // TODO: ersetzen
|
||||
final String host = "smtp.gmail.com";
|
||||
final int port = 587;
|
||||
|
||||
private final MailConfig mailConfig;
|
||||
|
||||
@Autowired
|
||||
public MailUtil(MailConfig mailConfig) {
|
||||
this.mailConfig = mailConfig;
|
||||
}
|
||||
|
||||
public void sendMail(String to, String subject, String body) throws MessagingException {
|
||||
// SMTP-Konfiguration aus externalisierter Konfiguration
|
||||
final String username = mailConfig.getUsername();
|
||||
final String password = mailConfig.getPassword();
|
||||
final String host = mailConfig.getHost();
|
||||
final int port = mailConfig.getPort();
|
||||
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
@@ -12,4 +12,20 @@ vaadin.allowed-packages=com.vaadin,org.vaadin,de.assecutor.votianlt
|
||||
spring.jpa.open-in-view=false
|
||||
|
||||
# MongoDB
|
||||
spring.data.mongodb.uri=mongodb://192.168.180.25:27017/votianlt
|
||||
spring.data.mongodb.uri=mongodb://192.168.180.25:27017/votianlt
|
||||
|
||||
# Mail Configuration
|
||||
mail.smtp.username=your-email@gmail.com
|
||||
mail.smtp.password=your-password
|
||||
mail.smtp.host=smtp.gmail.com
|
||||
mail.smtp.port=587
|
||||
|
||||
# WebSocket and STOMP Configuration
|
||||
# WebSocket message size limits (in bytes)
|
||||
spring.websocket.servlet.max-text-message-buffer-size=8192
|
||||
spring.websocket.servlet.max-binary-message-buffer-size=8192
|
||||
# Enable STOMP over WebSocket
|
||||
spring.websocket.stomp.enabled=true
|
||||
# STOMP heartbeat settings (in milliseconds)
|
||||
spring.websocket.stomp.heartbeat.outgoing=10000
|
||||
spring.websocket.stomp.heartbeat.incoming=10000
|
||||
Reference in New Issue
Block a user