Merge branch 'eugenp:master' into master
This commit is contained in:
commit
cd55a1b532
@ -3,11 +3,11 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>project-b</artifactId>
|
<artifactId>module1</artifactId>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung.maven-parent-pom-resolution</groupId>
|
||||||
<artifactId>project-a</artifactId>
|
<artifactId>aggregator</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<!-- The parent pom is resolved to project a's pom.xml -->
|
<!-- The parent pom is resolved to project a's pom.xml -->
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
@ -3,11 +3,11 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>project-d</artifactId>
|
<artifactId>module3</artifactId>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung.maven-parent-pom-resolution</groupId>
|
||||||
<artifactId>project-a</artifactId>
|
<artifactId>aggregator</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<!-- removing relativePath won't work even if project-a is the aggregator project -->
|
<!-- removing relativePath won't work even if project-a is the aggregator project -->
|
||||||
<!-- it only works in IntelliJ IDEA when project-a is registered as a Maven Project -->
|
<!-- it only works in IntelliJ IDEA when project-a is registered as a Maven Project -->
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
@ -3,18 +3,18 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>project-c</artifactId>
|
<artifactId>module2</artifactId>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung.maven-parent-pom-resolution</groupId>
|
||||||
<artifactId>project-b</artifactId>
|
<artifactId>module1</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>../project-b/pom.xml</relativePath>
|
<relativePath>../module1/pom.xml</relativePath>
|
||||||
<!-- The parent pom is resolved to project a's pom.xml -->
|
<!-- The parent pom is resolved to project a's pom.xml -->
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>project-d</module>
|
<module>module3</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -3,18 +3,19 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>project-a</artifactId>
|
<groupId>com.baeldung.maven-parent-pom-resolution</groupId>
|
||||||
|
<artifactId>aggregator</artifactId>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>maven-parent-pom-resolution</artifactId>
|
<artifactId>maven-parent-pom-resolution</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<!-- The parent pom is resolved to ../pom.xml -->
|
<!-- The parent pom is resolved to ../pom.xml -->
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>project-b</module>
|
<module>module1</module>
|
||||||
<module>project-c</module>
|
<module>module2</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -5,11 +5,11 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>maven-parent-pom-resolution</artifactId>
|
<artifactId>maven-parent-pom-resolution</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>project-a</module>
|
<module>aggregator</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<!-- to detect the POM hierarchy, just type "mvn dependency:display-ancestors" -->
|
<!-- to detect the POM hierarchy, just type "mvn dependency:display-ancestors" -->
|
||||||
|
@ -8,5 +8,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||||||
### Relevant Articles
|
### Relevant Articles
|
||||||
- [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive)
|
- [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive)
|
||||||
- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors)
|
- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors)
|
||||||
- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc)
|
|
||||||
- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase)
|
|
||||||
|
@ -6,7 +6,5 @@ This module contains articles about reactive Spring 5 Data
|
|||||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
|
|
||||||
### Relevant Articles
|
### Relevant Articles
|
||||||
- [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive)
|
|
||||||
- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors)
|
|
||||||
- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc)
|
- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc)
|
||||||
- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase)
|
- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase)
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.rawwebsocket;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSocket
|
||||||
|
public class ServerWebSocketConfig implements WebSocketConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
|
registry.addHandler(webSocketHandler(), "/websocket");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebSocketHandler webSocketHandler() {
|
||||||
|
return new ServerWebSocketHandler();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.baeldung.rawwebsocket;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
import org.springframework.web.socket.SubProtocolCapable;
|
||||||
|
import org.springframework.web.socket.TextMessage;
|
||||||
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
|
import org.springframework.web.util.HtmlUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
|
public class ServerWebSocketHandler extends TextWebSocketHandler implements SubProtocolCapable {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ServerWebSocketHandler.class);
|
||||||
|
|
||||||
|
private final Set<WebSocketSession> sessions = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||||
|
logger.info("Server connection opened");
|
||||||
|
sessions.add(session);
|
||||||
|
|
||||||
|
TextMessage message = new TextMessage("one-time message from server");
|
||||||
|
logger.info("Server sends: {}", message);
|
||||||
|
session.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
|
||||||
|
logger.info("Server connection closed: {}", status);
|
||||||
|
sessions.remove(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(fixedRate = 10000)
|
||||||
|
void sendPeriodicMessages() throws IOException {
|
||||||
|
for (WebSocketSession session : sessions) {
|
||||||
|
if (session.isOpen()) {
|
||||||
|
String broadcast = "server periodic message " + LocalTime.now();
|
||||||
|
logger.info("Server sends: {}", broadcast);
|
||||||
|
session.sendMessage(new TextMessage(broadcast));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||||
|
String request = message.getPayload();
|
||||||
|
logger.info("Server received: {}", request);
|
||||||
|
|
||||||
|
String response = String.format("response from server to '%s'", HtmlUtils.htmlEscape(request));
|
||||||
|
logger.info("Server sends: {}", response);
|
||||||
|
session.sendMessage(new TextMessage(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleTransportError(WebSocketSession session, Throwable exception) {
|
||||||
|
logger.info("Server transport error: {}", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSubProtocols() {
|
||||||
|
return Collections.singletonList("subprotocol.demo.websocket");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user