CXF-5855: Introduce support for Server Sent Events. Initial implementation 
based on Atmosphere


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/bd8aff66
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/bd8aff66
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/bd8aff66

Branch: refs/heads/master
Commit: bd8aff6652eef048513571b96c703f4333f24dfb
Parents: 922152c
Author: reta <drr...@gmail.com>
Authored: Sun Apr 17 21:44:28 2016 -0400
Committer: reta <drr...@gmail.com>
Committed: Fri Sep 16 19:12:38 2016 -0400

----------------------------------------------------------------------
 .../release/samples/jax_rs/sse_cdi/README.txt   |  35 +++
 .../main/release/samples/jax_rs/sse_cdi/pom.xml | 143 ++++++++++
 .../src/main/java/demo/jaxrs/sse/Stats.java     |  56 ++++
 .../java/demo/jaxrs/sse/StatsApplication.java   |  44 +++
 .../demo/jaxrs/sse/StatsRestServiceImpl.java    |  80 ++++++
 .../main/java/demo/jaxrs/sse/StatsServer.java   |  63 +++++
 .../src/main/resources/META-INF/beans.xml       |  10 +
 .../META-INF/cxf/org.apache.cxf.Logger          |   1 +
 .../sse_cdi/src/main/resources/log.properties   |   3 +
 .../sse_cdi/src/main/resources/logback.xml      |  16 ++
 .../src/main/resources/web-ui/index.html        |  49 ++++
 .../resources/web-ui/javascripts/highcharts.js  | 270 +++++++++++++++++++
 .../web-ui/javascripts/jquery-1.9.0.min.js      |   4 +
 .../samples/jax_rs/sse_spring/README.txt        |  35 +++
 .../release/samples/jax_rs/sse_spring/pom.xml   | 142 ++++++++++
 .../src/main/java/demo/jaxrs/sse/Stats.java     |  56 ++++
 .../java/demo/jaxrs/sse/StatsApplication.java   |  26 ++
 .../main/java/demo/jaxrs/sse/StatsConfig.java   |  56 ++++
 .../demo/jaxrs/sse/StatsRestServiceImpl.java    |  83 ++++++
 .../main/java/demo/jaxrs/sse/StatsServer.java   |  63 +++++
 .../src/main/resources/META-INF/beans.xml       |  10 +
 .../META-INF/cxf/org.apache.cxf.Logger          |   1 +
 .../src/main/resources/log.properties           |   2 +
 .../sse_spring/src/main/resources/logback.xml   |  16 ++
 .../src/main/resources/web-ui/index.html        |  49 ++++
 .../resources/web-ui/javascripts/highcharts.js  | 270 +++++++++++++++++++
 .../web-ui/javascripts/jquery-1.9.0.min.js      |   4 +
 .../samples/jax_rs/sse_tomcat/README.txt        |  35 +++
 .../release/samples/jax_rs/sse_tomcat/pom.xml   | 140 ++++++++++
 .../src/main/java/demo/jaxrs/sse/Stats.java     |  56 ++++
 .../demo/jaxrs/sse/StatsRestServiceImpl.java    |  80 ++++++
 .../main/java/demo/jaxrs/sse/StatsServer.java   |  74 +++++
 .../META-INF/cxf/org.apache.cxf.Logger          |   1 +
 .../resources/WEB-INF/applicationContext.xml    |  42 +++
 .../src/main/resources/log.properties           |   2 +
 .../sse_tomcat/src/main/resources/logback.xml   |  16 ++
 .../src/main/resources/web-ui/index.html        |  49 ++++
 .../resources/web-ui/javascripts/highcharts.js  | 270 +++++++++++++++++++
 .../web-ui/javascripts/jquery-1.9.0.min.js      |   4 +
 distribution/src/main/release/samples/pom.xml   |   3 +
 .../cxf/cdi/JAXRSCdiResourceExtension.java      |  23 ++
 ...AXRSServerFactoryCustomizationExtension.java |  34 +++
 parent/pom.xml                                  |  17 +-
 .../cxf/jaxrs/JAXRSServerFactoryBean.java       |   9 +
 .../org/apache/cxf/jaxrs/impl/RequestImpl.java  |  23 ++
 .../cxf/jaxrs/impl/ResponseBuilderImpl.java     |  14 +
 .../cxf/jaxrs/impl/tl/ThreadLocalRequest.java   |  23 ++
 .../client/spec/InvocationBuilderImpl.java      |  33 +++
 rt/rs/pom.xml                                   |   1 +
 rt/rs/sse/pom.xml                               |  76 ++++++
 .../jaxrs/sse/OutboundSseEventBodyWriter.java   | 139 ++++++++++
 .../cxf/jaxrs/sse/OutboundSseEventImpl.java     | 171 ++++++++++++
 .../cxf/jaxrs/sse/SseBroadcasterImpl.java       |  65 +++++
 .../cxf/jaxrs/sse/SseEventOutputProvider.java   |  53 ++++
 .../org/apache/cxf/jaxrs/sse/SseFeature.java    |  41 +++
 .../SseAtmosphereContextProvider.java           |  57 ++++
 .../SseAtmosphereEventOutputImpl.java           | 117 ++++++++
 .../atmosphere/SseAtmosphereInterceptor.java    | 181 +++++++++++++
 .../SseAtmosphereInterceptorWriter.java         |  31 +++
 .../SseAtmosphereResourceContext.java           |  60 +++++
 .../cdi/SseTransportCustomizationExtension.java |  30 +++
 .../transport/sse/SseHttpTransportFactory.java  |  57 ++++
 .../AtmosphereSseServletDestination.java        | 100 +++++++
 rt/rs/sse/src/main/resources/META-INF/beans.xml |   5 +
 .../resources/META-INF/cxf/bus-extensions.txt   |   1 +
 .../transport/http/HTTPTransportFactory.java    |   8 +-
 .../transport/servlet/CXFNonSpringServlet.java  |  12 +-
 systests/pom.xml                                |   1 +
 systests/rs-sse/pom.xml                         | 166 ++++++++++++
 .../cxf/systest/jaxrs/sse/AbstractSseTest.java  | 147 ++++++++++
 .../org/apache/cxf/systest/jaxrs/sse/Book.java  |  65 +++++
 .../apache/cxf/systest/jaxrs/sse/BookStore.java | 128 +++++++++
 .../jaxrs/sse/jetty/AbstractJettyServer.java    |  98 +++++++
 .../jaxrs/sse/jetty/JettyEmbeddedTest.java      |  49 ++++
 .../systest/jaxrs/sse/jetty/JettyWarTest.java   |  48 ++++
 .../jaxrs/sse/tomcat/AbstractTomcatServer.java  | 111 ++++++++
 .../jaxrs/sse/tomcat/TomcatEmbeddedTest.java    |  49 ++++
 .../systest/jaxrs/sse/tomcat/TomcatWarTest.java |  49 ++++
 .../test/resources/jaxrs_sse/WEB-INF/web.xml    |  28 ++
 79 files changed, 4673 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/README.txt
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/sse_cdi/README.txt 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/README.txt
new file mode 100644
index 0000000..6917376
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/sse_cdi/README.txt
@@ -0,0 +1,35 @@
+JAX-RS SSE Demo 
+=================
+
+This is a SSE version of JAX-RS Basic Demo using CDI.
+
+A SSE endpoint service is provided on URL 
http://localhost:8686/rest/api/stats/sse/{id}
+where {id} is any integer value, f.e.:
+
+  http://localhost:8686/rest/api/stats/sse/1
+
+This sample includes a simple web UI using Highcharts JavaScript library to 
show off
+randomly generated statistics about particular server, pushed to the client 
using
+SSE JAX-RS endpoint. The UI is available at
+
+  http://localhost:8686/static/ 
+
+Under the hood, embedded Jetty 9 container is being used.
+
+Building and running the demo using maven
+---------------------------------------
+
+From the base directory of this sample (i.e., where this README file is
+located), the maven pom.xml file can be used to build and run the demo. 
+
+Using either UNIX or Windows:
+
+  mvn install
+  mvn -Pserver
+
+To remove the target dir, run mvn clean".  
+
+Connecting to the SSE stream
+---------------------------------------
+
+Open a web browser at: http://localhost:8686/static/

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/sse_cdi/pom.xml 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/pom.xml
new file mode 100644
index 0000000..7311157
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/sse_cdi/pom.xml
@@ -0,0 +1,143 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
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";>
+    <modelVersion>4.0.0</modelVersion>
+    <name>JAX-RS SSE/CDI Demo (Jetty 9)</name>
+    <description>JAX-RS SSE/CDI Demo (Jetty 9)</description>
+    <artifactId>jax_rs_sse_cdi</artifactId>
+
+    <parent>
+        <groupId>org.apache.cxf.samples</groupId>
+        <artifactId>cxf-samples</artifactId>
+        <version>3.2.0-SNAPSHOT</version>
+        <relativePath>../..</relativePath>
+    </parent>
+    
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <cxf.jetty9.version>9.3.5.v20151012</cxf.jetty9.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-integration-cdi</artifactId>
+            <version>3.2.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+            <version>3.2.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-sse</artifactId>
+            <version>3.2.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jboss.weld.servlet</groupId>
+            <artifactId>weld-servlet</artifactId>
+            <version>2.2.16.Final</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jboss.weld</groupId>
+            <artifactId>weld-core</artifactId>
+            <version>2.2.16.Final</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-plus</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>apache-jsp</artifactId>
+            <version>${cxf.jetty9.version}</version>
+        </dependency>
+
+         <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-webapp</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.jetty.websocket</groupId>
+            <artifactId>websocket-server</artifactId>
+            <version>${cxf.jetty9.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.atmosphere</groupId>
+            <artifactId>atmosphere-runtime</artifactId>
+            <version>2.4.3</version>
+        </dependency>
+    </dependencies>
+    
+    <profiles>
+        <profile>
+            <id>server</id>
+            <build>
+                <defaultGoal>test</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    
<mainClass>demo.jaxrs.sse.StatsServer</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/Stats.java
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/Stats.java
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/Stats.java
new file mode 100644
index 0000000..874047c
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/Stats.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.sse;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+@JsonInclude(value = Include.NON_NULL)
+public class Stats implements Serializable {
+    private static final long serialVersionUID = -6705829915457870975L;
+
+    private long timestamp;
+    private int load;
+    
+    public Stats() {
+    }
+
+    public Stats(long timestamp, int load) {
+        this.timestamp = timestamp;
+        this.load = load;
+    }
+
+    public long getTimestamp() {
+        return timestamp;
+    }
+    
+    public void setTimestamp(long timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public int getLoad() {
+        return load;
+    }
+
+    public void setLoad(int load) {
+        this.load = load;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsApplication.java
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsApplication.java
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsApplication.java
new file mode 100644
index 0000000..edf8a2b
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsApplication.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.sse;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.jaxrs.sse.SseFeature;
+
+@ApplicationPath("api")
+public class StatsApplication extends Application {
+    @Inject private StatsRestServiceImpl statsRestService;
+    
+    @Override
+    public Set<Object> getSingletons() {
+        final Set<Object> singletons = new HashSet<>();
+        singletons.add(new SseFeature());
+        singletons.add(statsRestService);
+        singletons.add(new JacksonJsonProvider());
+        return singletons;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsRestServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsRestServiceImpl.java
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsRestServiceImpl.java
new file mode 100644
index 0000000..b8f8608
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsRestServiceImpl.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.sse;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Random;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.sse.OutboundSseEvent;
+import javax.ws.rs.sse.SseContext;
+import javax.ws.rs.sse.SseEventOutput;
+
+@Path("/stats")
+public class StatsRestServiceImpl {
+    private static final Random RANDOM = new Random();
+
+    private static OutboundSseEvent createStatsEvent(final 
OutboundSseEvent.Builder builder, final int eventId) {
+        return builder
+            .id("" + eventId)
+            .data(Stats.class, new Stats(new Date().getTime(), 
RANDOM.nextInt(100)))
+            .mediaType(MediaType.APPLICATION_JSON_TYPE)
+            .build();
+    }
+    
+    @GET
+    @Path("sse/{id}")
+    @Produces("text/event-stream")
+    public SseEventOutput stats(@Context SseContext sseContext, 
@PathParam("id") final String id) {
+        final SseEventOutput output = sseContext.newOutput();
+        
+        new Thread() {
+            public void run() {
+                try {
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 1));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 2));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 3));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 4));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 5));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 6));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 7));
+                    Thread.sleep(1000);
+                    
output.write(createStatsEvent(sseContext.newEvent().name("stats"), 8));
+                    output.close();
+                } catch (final InterruptedException | IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }.start();
+
+        return output;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsServer.java
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsServer.java
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsServer.java
new file mode 100644
index 0000000..c227718
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/java/demo/jaxrs/sse/StatsServer.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.sse;
+
+import org.apache.cxf.cdi.CXFCdiServlet;
+import org.apache.cxf.transport.sse.SseHttpTransportFactory;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener;
+import org.jboss.weld.environment.servlet.Listener;
+
+public final class StatsServer {
+    private StatsServer() {
+    }
+    
+    public static void main(final String[] args) throws Exception {
+        final Server server = new Server(8686);
+
+        final ServletHolder staticHolder = new ServletHolder(new 
DefaultServlet());
+        final ServletContextHandler staticContext = new 
ServletContextHandler();
+        staticContext.setContextPath("/static");
+        staticContext.addServlet(staticHolder, "/*");
+        
staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString());
+
+         // Register and map the dispatcher servlet
+        final CXFCdiServlet cxfServlet = new CXFCdiServlet();
+        final ServletHolder cxfServletHolder = new ServletHolder(cxfServlet);
+        cxfServletHolder.setInitParameter(CXFCdiServlet.TRANSPORT_ID, 
SseHttpTransportFactory.TRANSPORT_ID);
+        final ServletContextHandler context = new ServletContextHandler();
+        context.setContextPath("/");
+        context.addEventListener(new Listener());
+        context.addEventListener(new BeanManagerResourceBindingListener());
+        context.addServlet(cxfServletHolder, "/rest/*");
+
+        HandlerList handlers = new HandlerList();
+        handlers.addHandler(staticContext);
+        handlers.addHandler(context);
+        
+        server.setHandler(handlers);
+        server.start();
+        server.join();
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/beans.xml
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..7e2559b
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://jboss.org/schema/cdi/beans_1_1.xsd";        
+       version="1.1">  
+
+       <scan>
+               <exclude name="org.apache.cxf.**" />
+       </scan>
+</beans>

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/cxf/org.apache.cxf.Logger
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/cxf/org.apache.cxf.Logger
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/cxf/org.apache.cxf.Logger
new file mode 100644
index 0000000..27dd788
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/META-INF/cxf/org.apache.cxf.Logger
@@ -0,0 +1 @@
+org.apache.cxf.common.logging.Slf4jLogger
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/log.properties
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/log.properties
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/log.properties
new file mode 100644
index 0000000..63477d3
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/log.properties
@@ -0,0 +1,3 @@
+handlers=java.util.logging.ConsoleHandler
+org.jboss.weld.level=FINEST
+java.util.logging.ConsoleHandler.level=FINEST
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/logback.xml
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/logback.xml
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/logback.xml
new file mode 100644
index 0000000..1052186
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/logback.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="5 seconds">
+       <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+               <encoder>
+                       <pattern>[%level] %d{yyyy-MM-dd HH:mm:ss.SSS} 
%logger{36} - [%X] %msg%n</pattern>
+               </encoder>
+       </appender>
+
+       <root level="DEBUG">
+               <appender-ref ref="STDOUT" />
+       </root>
+       
+       <logger category="org.jboss.weld">  
+       <level name="DEBUG"/>  
+       </logger>
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/bd8aff66/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/web-ui/index.html
----------------------------------------------------------------------
diff --git 
a/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/web-ui/index.html
 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/web-ui/index.html
new file mode 100644
index 0000000..2aaed6e
--- /dev/null
+++ 
b/distribution/src/main/release/samples/jax_rs/sse_cdi/src/main/resources/web-ui/index.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>SSE: Apache CXF example</title>
+        <script src="javascripts/jquery-1.9.0.min.js" 
type="text/javascript"></script>
+        <script src="javascripts/highcharts.js" 
type="text/javascript"></script>
+    </head>
+    
+    <body>
+               <div id="content">
+                       <div id="chart">
+                       </div>
+               </div>
+       </body>
+</html>
+
+<script type="text/javascript">
+       var chart = new Highcharts.Chart({
+           chart: {
+               renderTo: 'chart',
+               defaultSeriesType: 'spline'
+           },           
+           xAxis: {
+               type: 'datetime'
+           },   
+           series: [{
+               name: "CPU",
+               data: []
+              }
+           ]
+       }); 
+
+       if( !!window.EventSource ) {
+           var event = new 
EventSource("http://localhost:8686/rest/api/stats/sse/1";);
+       
+           event.addEventListener('message', function( event ) {       
+               var datapoint = jQuery.parseJSON( event.data );
+                
+               chart.series[ 0 ].addPoint({
+                   x: datapoint.timestamp,
+                   y: datapoint.load
+               }, true, chart.series[ 0 ].data.length >= 50 );
+           } );
+
+           $('#content').bind('unload',function() {
+               event.close();
+               });                            
+       }       
+</script>
\ No newline at end of file

Reply via email to