Skip to content

Commit 570e33d

Browse files
eelhazatiCalamarBicefalo
authored andcommitted
move sse-jaxrs module under apache-cxf module.
1 parent 5e8b350 commit 570e33d

20 files changed

Lines changed: 654 additions & 2 deletions

File tree

apache-cxf/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.baeldung</groupId>
55
<artifactId>apache-cxf</artifactId>
@@ -17,6 +17,7 @@
1717
<module>cxf-spring</module>
1818
<module>cxf-jaxrs-implementation</module>
1919
<module>cxf-aegis</module>
20+
<module>sse-jaxrs</module>
2021
</modules>
2122

2223
<build>

apache-cxf/sse-jaxrs/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>sse-jaxrs</artifactId>
8+
<packaging>pom</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>apache-cxf</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
</parent>
15+
16+
<modules>
17+
<module>sse-jaxrs-server</module>
18+
<module>sse-jaxrs-client</module>
19+
</modules>
20+
21+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.baeldung</groupId>
9+
<artifactId>sse-jaxrs</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>sse-jaxrs-client</artifactId>
14+
15+
<properties>
16+
<cxf-version>3.2.0</cxf-version>
17+
</properties>
18+
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.codehaus.mojo</groupId>
23+
<artifactId>exec-maven-plugin</artifactId>
24+
<version>1.6.0</version>
25+
<executions>
26+
<execution>
27+
<id>singleEvent</id>
28+
<goals>
29+
<goal>java</goal>
30+
</goals>
31+
<configuration>
32+
<mainClass>com.baeldung.sse.jaxrs.client.SseClientApp</mainClass>
33+
</configuration>
34+
</execution>
35+
<execution>
36+
<id>broadcast</id>
37+
<goals>
38+
<goal>java</goal>
39+
</goals>
40+
<configuration>
41+
<mainClass>com.baeldung.sse.jaxrs.client.SseClientBroadcastApp</mainClass>
42+
</configuration>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.apache.cxf</groupId>
52+
<artifactId>cxf-rt-rs-client</artifactId>
53+
<version>${cxf-version}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.apache.cxf</groupId>
57+
<artifactId>cxf-rt-rs-sse</artifactId>
58+
<version>${cxf-version}</version>
59+
</dependency>
60+
</dependencies>
61+
62+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.baeldung.sse.jaxrs.client;
2+
3+
import javax.ws.rs.client.Client;
4+
import javax.ws.rs.client.ClientBuilder;
5+
import javax.ws.rs.client.WebTarget;
6+
import javax.ws.rs.sse.InboundSseEvent;
7+
import javax.ws.rs.sse.SseEventSource;
8+
import java.util.function.Consumer;
9+
10+
public class SseClientApp {
11+
12+
private static final String url = "http://127.0.0.1:9080/sse-jaxrs-server/sse/stock/prices";
13+
14+
public static void main(String... args) throws Exception {
15+
16+
Client client = ClientBuilder.newClient();
17+
WebTarget target = client.target(url);
18+
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
19+
20+
eventSource.register(onEvent, onError, onComplete);
21+
eventSource.open();
22+
23+
//Consuming events for one hour
24+
Thread.sleep(60 * 60 * 1000);
25+
} catch (InterruptedException e) {
26+
e.printStackTrace();
27+
}
28+
client.close();
29+
System.out.println("End");
30+
}
31+
32+
// A new event is received
33+
private static Consumer<InboundSseEvent> onEvent = (inboundSseEvent) -> {
34+
String data = inboundSseEvent.readData();
35+
System.out.println(data);
36+
};
37+
38+
//Error
39+
private static Consumer<Throwable> onError = (throwable) -> {
40+
throwable.printStackTrace();
41+
};
42+
43+
//Connection close and there is nothing to receive
44+
private static Runnable onComplete = () -> {
45+
System.out.println("Done!");
46+
};
47+
48+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.sse.jaxrs.client;
2+
3+
import javax.ws.rs.client.Client;
4+
import javax.ws.rs.client.ClientBuilder;
5+
import javax.ws.rs.client.WebTarget;
6+
import javax.ws.rs.sse.InboundSseEvent;
7+
import javax.ws.rs.sse.SseEventSource;
8+
import java.util.concurrent.TimeUnit;
9+
import java.util.function.Consumer;
10+
11+
public class SseClientBroadcastApp {
12+
13+
private static final String subscribeUrl = "http://localhost:9080/sse-jaxrs-server/sse/stock/subscribe";
14+
15+
16+
public static void main(String... args) throws Exception {
17+
18+
Client client = ClientBuilder.newClient();
19+
WebTarget target = client.target(subscribeUrl);
20+
try (final SseEventSource eventSource = SseEventSource.target(target)
21+
.reconnectingEvery(5, TimeUnit.SECONDS)
22+
.build()) {
23+
eventSource.register(onEvent, onError, onComplete);
24+
eventSource.open();
25+
System.out.println("Wainting for incoming event ...");
26+
27+
//Consuming events for one hour
28+
Thread.sleep(60 * 60 * 1000);
29+
} catch (InterruptedException e) {
30+
e.printStackTrace();
31+
}
32+
client.close();
33+
System.out.println("End");
34+
}
35+
36+
// A new event is received
37+
private static Consumer<InboundSseEvent> onEvent = (inboundSseEvent) -> {
38+
String data = inboundSseEvent.readData();
39+
System.out.println(data);
40+
};
41+
42+
//Error
43+
private static Consumer<Throwable> onError = (throwable) -> {
44+
throwable.printStackTrace();
45+
};
46+
47+
//Connection close and there is nothing to receive
48+
private static Runnable onComplete = () -> {
49+
System.out.println("Done!");
50+
};
51+
52+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.baeldung</groupId>
9+
<artifactId>sse-jaxrs</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>sse-jaxrs-server</artifactId>
14+
<packaging>war</packaging>
15+
16+
<properties>
17+
<liberty-maven-plugin.version>2.4.2</liberty-maven-plugin.version>
18+
<failOnMissingWebXml>false</failOnMissingWebXml>
19+
<openliberty-version>18.0.0.2</openliberty-version>
20+
</properties>
21+
22+
<build>
23+
<finalName>${artifactId}</finalName>
24+
<plugins>
25+
<plugin>
26+
<groupId>net.wasdev.wlp.maven.plugins</groupId>
27+
<artifactId>liberty-maven-plugin</artifactId>
28+
<version>${liberty-maven-plugin.version}</version>
29+
<configuration>
30+
<assemblyArtifact>
31+
<groupId>io.openliberty</groupId>
32+
<artifactId>openliberty-webProfile8</artifactId>
33+
<version>${openliberty-version}</version>
34+
<type>zip</type>
35+
</assemblyArtifact>
36+
<installAppPackages>project</installAppPackages>
37+
<looseApplication>true</looseApplication>
38+
<configFile>src/main/liberty/config/server.xml</configFile>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<id>install-server</id>
43+
<phase>prepare-package</phase>
44+
<goals>
45+
<goal>install-server</goal>
46+
<goal>create-server</goal>
47+
<goal>install-feature</goal>
48+
</goals>
49+
</execution>
50+
<execution>
51+
<id>install-apps</id>
52+
<phase>package</phase>
53+
<goals>
54+
<goal>install-apps</goal>
55+
</goals>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
<dependencies>
63+
64+
<dependency>
65+
<groupId>javax.ws.rs</groupId>
66+
<artifactId>javax.ws.rs-api</artifactId>
67+
<version>2.1</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>javax.enterprise</groupId>
72+
<artifactId>cdi-api</artifactId>
73+
<version>2.0</version>
74+
<scope>provided</scope>
75+
</dependency>
76+
<dependency>
77+
<groupId>javax.json.bind</groupId>
78+
<artifactId>javax.json.bind-api</artifactId>
79+
<version>1.0</version>
80+
<scope>provided</scope>
81+
</dependency>
82+
83+
</dependencies>
84+
85+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.sse.jaxrs;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
6+
@ApplicationPath("sse")
7+
public class AppConfig extends Application {
8+
}

0 commit comments

Comments
 (0)