forked from Atmosphere/atmosphere-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
18,603 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
### Using the sample | ||
|
||
This sample can be installed on any OSGi container. In the following, | ||
Apache Karaf is used as the OSGi container. | ||
|
||
If you do not have Karaf installed, download apache-karaf-3.0.4.tar.gz from one of the [mirror sites](http://www.apache.org/dyn/closer.cgi/karaf/3.0.4/apache-karaf-3.0.4.tar.gz) and unpack the archive. | ||
|
||
```bash | ||
$ wget -N http://ftp.halifax.rwth-aachen.de/apache/karaf/3.0.4/apache-karaf-3.0.4.tar.gz | ||
$ tar -zxf apache-karaf-3.0.4.tar.gz | ||
$ cd apache-karaf-3.0.4 | ||
``` | ||
|
||
#### Starting Karaf | ||
|
||
```bash | ||
$ bin/karaf | ||
__ __ ____ | ||
/ //_/____ __________ _/ __/ | ||
/ ,< / __ `/ ___/ __ `/ /_ | ||
/ /| |/ /_/ / / / /_/ / __/ | ||
/_/ |_|\__,_/_/ \__,_/_/ | ||
|
||
Apache Karaf (3.0.4) | ||
|
||
Hit '<tab>' for a list of available commands | ||
and '[cmd] --help' for help on a specific command. | ||
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf. | ||
|
||
karaf@root()> | ||
``` | ||
|
||
#### Install the required bundles | ||
|
||
Install the required bundles by executing the following commands. | ||
|
||
```bash | ||
feature:install war | ||
feature:install cxf-jaxrs | ||
feature:repo-add cxf 3.1.7 | ||
install -s mvn:org.atmosphere/atmosphere-runtime/2.4.3 | ||
install -s mvn:com.fasterxml.jackson.core/jackson-core/2.6.6 | ||
install -s mvn:com.fasterxml.jackson.core/jackson-annotations/2.6.6 | ||
install -s mvn:com.fasterxml.jackson.core/jackson-databind/2.6.6 | ||
install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/2.6.6 | ||
install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/2.6.6 | ||
``` | ||
|
||
The above commands will install the required bundles for this sample. Finally, | ||
install this sample (TODO use a released 2.4.x version number once it is released) | ||
|
||
``` | ||
install -s mvn:org.atmosphere.samples/atmosphere-cxf-chat-osgi/2.5.0-SNAPSHOT | ||
``` | ||
|
||
Shown below is the output from running the above Karaf console commands. | ||
|
||
``` | ||
karaf@root()> feature:install war | ||
karaf@root()> feature:repo-add cxf 3.1.7 | ||
Adding feature url mvn:org.apache.cxf.karaf/apache-cxf/3.1.7/xml/features | ||
karaf@root()> feature:install cxf-jaxrs | ||
Refreshing bundles org.eclipse.jetty.aggregate.jetty-all-server (70), org.apache.geronimo.specs.geronimo-jaspic_1.0_spec (69) | ||
karaf@root()> install -s mvn:org.atmosphere/atmosphere-runtime/2.4.3 | ||
Bundle ID: 121 | ||
karaf@root()> install -s mvn:com.fasterxml.jackson.core/jackson-core/2.6.6 | ||
Bundle ID: 122 | ||
karaf@root()> install -s mvn:com.fasterxml.jackson.core/jackson-annotations/2.6.6 | ||
Bundle ID: 123 | ||
karaf@root()> install -s mvn:com.fasterxml.jackson.core/jackson-databind/2.6.6 | ||
Bundle ID: 124 | ||
karaf@root()> install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/2.6.6 | ||
Bundle ID: 125 | ||
karaf@root()> install -s mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/2.6.6 | ||
Bundle ID: 126 | ||
karaf@root()> install -s mvn:org.atmosphere.samples/atmosphere-cxf-chat-osgi/2.5.0-SNAPSHOT | ||
Bundle ID: 127 | ||
karaf@root()> | ||
``` | ||
|
||
You can verify the bundles are started and the sample application is registered by | ||
running commands list and web:list. | ||
|
||
```bash | ||
karaf@root()> list | ||
START LEVEL 100 , List Threshold: 50 | ||
ID | State | Lvl | Version | Name | ||
---------------------------------------------------------- | ||
121 | Active | 80 | 2.4.3 | atmosphere-runtime | ||
122 | Active | 80 | 2.6.6 | Jackson-core | ||
123 | Active | 80 | 2.6.6 | Jackson-annotations | ||
124 | Active | 80 | 2.6.6 | jackson-databind | ||
125 | Active | 80 | 2.6.6 | Jackson-JAXRS-base | ||
126 | Active | 80 | 2.6.6 | Jackson-JAXRS-JSON | ||
127 | Active | 80 | 2.5.0.SNAPSHOT | atmosphere-rest-chat | ||
karaf@root()> web:list | ||
ID | State | Web-State | Level | Web-ContextPath | Name | ||
------------------------------------------------------------------------------------------------------ | ||
127 | Active | Deployed | 80 | /atmosphere-cxf-chat | atmosphere-rest-chat (2.5.0.SNAPSHOT) | ||
karaf@root()> | ||
``` | ||
|
||
Using Browser, open [http://localhost:8181/atmosphere-cxf-chat](http://localhost:8181/atmosphere-cxf-chat) to visit this sample's chat page. | ||
|
||
You can also use the node.js client of sample [chat-node-client](../chat-node-client/README.md) with the target URL: http://localhost:8181/atmosphere-cxf-chat/chat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.atmosphere.samples</groupId> | ||
<artifactId>atmosphere-samples</artifactId> | ||
<version>2.5.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.atmosphere.samples</groupId> | ||
<artifactId>atmosphere-cxf-chat-osgi</artifactId> | ||
<packaging>bundle</packaging> | ||
<version>2.5.0-SNAPSHOT</version> | ||
<name>atmosphere-rest-chat</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<cxf-version>3.1.7</cxf-version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-runtime</artifactId> | ||
<version>${atmosphere-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-annotations</artifactId> | ||
<version>${atmosphere-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-servlet_3.0_spec</artifactId> | ||
</dependency> | ||
|
||
<!-- jaxrs using cxf --> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-frontend-jaxrs</artifactId> | ||
<version>${cxf-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.jaxrs</groupId> | ||
<artifactId>jackson-jaxrs-json-provider</artifactId> | ||
<version>${jackson-version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>${logback-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.atmosphere.client</groupId> | ||
<artifactId>javascript</artifactId> | ||
<version>${client-version}</version> | ||
<type>war</type> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.9</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>unpack</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>org.atmosphere.client</groupId> | ||
<artifactId>javascript</artifactId> | ||
<version>${client-version}</version> | ||
<type>war</type> | ||
<overWrite>true</overWrite> | ||
<outputDirectory>${project.build.directory}/webapp</outputDirectory> | ||
<includes>javascript/*</includes> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.6</version> | ||
<executions> | ||
<execution> | ||
<id>copy-resources</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/webapp</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${project.basedir}/src/main/webapp</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Export-Package> | ||
</Export-Package> | ||
<Import-Package> | ||
org.atmosphere.cpr;version="[2.4,3)", | ||
org.apache.cxf.jaxrs.provider;version="[3.0,4)", | ||
org.apache.cxf.jaxrs.servlet;version="[3.0,4)", | ||
com.fasterxml.jackson.jaxrs.json;version="[2.4,3)", | ||
org.apache.catalina;resolution:=optional, | ||
org.apache.catalina.comet;resolution:=optional, | ||
org.apache.catalina.websocket;resolution:=optional, | ||
org.apache.coyote.http11.upgrade;resolution:=optional, | ||
org.eclipse.jetty.continuation;resolution:=optional, | ||
org.eclipse.jetty.server;resolution:=optional, | ||
org.eclipse.jetty.util.ssl;resolution:=optional, | ||
* | ||
</Import-Package> | ||
<_wab>${basedir}/target/webapp/</_wab> | ||
<Web-ContextPath>atmosphere-cxf-chat</Web-ContextPath> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
70 changes: 70 additions & 0 deletions
70
samples/cxf-chat-osgi/src/main/java/org/atmosphere/samples/chat/cxf/ChatResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2016 Async-IO.org | ||
* | ||
* Licensed 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 org.atmosphere.samples.chat.cxf; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.atmosphere.cpr.AtmosphereResource; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
|
||
/** | ||
* Simple chat resource demonstrating the power of Atmosphere with Apache CXF. This resource supports transport like WebSocket, Streaming, JSONP and Long-Polling. | ||
* | ||
*/ | ||
@Path("/") | ||
public class ChatResource { | ||
@Context | ||
HttpServletRequest req; | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
/** | ||
* Suspend the response without writing anything back to the client. | ||
* | ||
* @return a white space | ||
*/ | ||
@GET | ||
public String suspend() { | ||
AtmosphereResource r = (AtmosphereResource)req.getAttribute("org.atmosphere.cpr.AtmosphereResource"); | ||
r.setBroadcaster(r.getAtmosphereConfig().getBroadcasterFactory().lookup("/cxf-chat", true)).suspend(); | ||
return ""; | ||
} | ||
|
||
/** | ||
* Broadcast the received message object to all suspended response. Do not write back the message to the calling connection. | ||
* | ||
* @param message a {@link Message} | ||
* @return a {@link Response} | ||
*/ | ||
@POST | ||
@Produces("application/json") | ||
public String broadcast(Message message) { | ||
try { | ||
Response msg = new Response(message.author, message.message); | ||
AtmosphereResource r = (AtmosphereResource)req.getAttribute("org.atmosphere.cpr.AtmosphereResource"); | ||
r.getAtmosphereConfig().getBroadcasterFactory().lookup("/cxf-chat").broadcast(mapper.writeValueAsString(msg)); | ||
} catch (JsonProcessingException e) { | ||
//ignore | ||
} | ||
return ""; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
samples/cxf-chat-osgi/src/main/java/org/atmosphere/samples/chat/cxf/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2016 Async-IO.org | ||
* | ||
* Licensed 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 org.atmosphere.samples.chat.cxf; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
//@XmlRootElement | ||
public class Message { | ||
public String author = ""; | ||
public String message = ""; | ||
|
||
public Message(){ | ||
} | ||
|
||
public Message(String author, String message) { | ||
this.author = author; | ||
this.message = message; | ||
} | ||
} |
Oops, something went wrong.