forked from kylinsoong/wildfly-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
1 parent
3754f6b
commit 2d02347
Showing
4 changed files
with
230 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?xml version="1.0"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.wildfly.undertow</groupId> | ||
<artifactId>undertow-websocket-chat</artifactId> | ||
<version>1.0</version> | ||
<packaging>war</packaging> | ||
<name>WildFly Undertow WebSocket Chat</name> | ||
|
||
<url>http://wildfly.org</url> | ||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<distribution>repo</distribution> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<!-- Explicitly declaring the source encoding eliminates the following message: --> | ||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered | ||
resources, i.e. build is platform dependent! --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<!-- JBoss dependency versions --> | ||
<version.wildfly.maven.plugin>1.0.0.Final</version.wildfly.maven.plugin> | ||
|
||
<!-- other plugin versions --> | ||
<version.compiler.plugin>3.1</version.compiler.plugin> | ||
<version.war.plugin>2.1.1</version.war.plugin> | ||
|
||
<!-- maven-compiler-plugin --> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
|
||
<!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. --> | ||
<version.jboss.bom>8.0.0.Final</version.jboss.bom> | ||
<version.jboss.spec.javaee.7.0>1.0.0.Final</version.jboss.spec.javaee.7.0> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<!-- JBoss distributes a complete set of Java EE 7 APIs including | ||
a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or | ||
a collection) of artifacts. We use this here so that we always get the correct | ||
versions of artifacts. Here we use the jboss-javaee-7.0 stack (you can read | ||
this as the JBoss stack of the Java EE 7 APIs) --> | ||
<dependency> | ||
<groupId>org.jboss.spec</groupId> | ||
<artifactId>jboss-javaee-all-7.0</artifactId> | ||
<version>${version.jboss.spec.javaee.7.0}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.websocket</groupId> | ||
<artifactId>jboss-websocket-api_1.0_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<!-- Set the name of the war, used as the context root when the app is deployed. --> | ||
<finalName>${artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>${version.war.plugin}</version> | ||
<configuration> | ||
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! --> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<!-- WildFly plugin to deploy war --> | ||
<plugin> | ||
<groupId>org.wildfly.plugins</groupId> | ||
<artifactId>wildfly-maven-plugin</artifactId> | ||
<version>${version.wildfly.maven.plugin}</version> | ||
</plugin> | ||
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation processors. --> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${version.compiler.plugin}</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<!-- When built in OpenShift the 'openshift' profile will be | ||
used when invoking mvn. --> | ||
<!-- Use this profile for any OpenShift specific customization | ||
your app will need. --> | ||
<!-- By default that is to put the resulting archive into the | ||
'deployments' folder. --> | ||
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> | ||
<id>openshift</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>${version.war.plugin}</version> | ||
<configuration> | ||
<outputDirectory>deployments</outputDirectory> | ||
<warName>ROOT</warName> | ||
<!-- Java EE 7 doesn't require web.xml, Maven | ||
needs to catch up! --> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> | ||
|
18 changes: 18 additions & 0 deletions
18
undertow/chat/src/main/java/org/wildfly/undertow/chat/ChatServerEndpoint.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,18 @@ | ||
package org.wildfly.undertow.chat; | ||
|
||
import javax.websocket.OnMessage; | ||
import javax.websocket.Session; | ||
import javax.websocket.server.ServerEndpoint; | ||
|
||
|
||
@ServerEndpoint("/chat") | ||
public class ChatServerEndpoint { | ||
|
||
@OnMessage | ||
public void chat(String text, Session client) { | ||
|
||
System.out.println(text); | ||
|
||
client.getAsyncRemote().sendText(text.toUpperCase()); | ||
} | ||
} |
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,85 @@ | ||
<html> | ||
<head><title>Undertow Chat</title> | ||
<script> | ||
var socket; | ||
if (window.WebSocket) { | ||
var url = 'ws://' + window.location.host + window.location.pathname + 'chat'; | ||
socket = new WebSocket(url); | ||
socket.onmessage = function (event) { | ||
var chat = document.getElementById('chat'); | ||
chat.innerHTML = chat.innerHTML + event.data + "<br />"; | ||
}; | ||
} else { | ||
alert("Your browser does not support Websockets. (Use Chrome)"); | ||
} | ||
|
||
function send(message) { | ||
if (!window.WebSocket) { | ||
return false; | ||
} | ||
if (socket.readyState == WebSocket.OPEN) { | ||
socket.send(message); | ||
} else { | ||
alert("The socket is not open."); | ||
} | ||
return false; | ||
} | ||
</script> | ||
<style type="text/css"> | ||
html,body {width:100%;height:100%;} | ||
html,body,ul,ol,dl,li,dt,dd,p,blockquote,fieldset,legend,img,form,h1,h2,h3,h4,h5,h6 {margin:0;padding:0;} | ||
body { | ||
font:normal 12px/1.5 Arial,Helvetica,'Bitstream Vera Sans',sans-serif; | ||
background: #c5deea; /* Old browsers */ | ||
background: -moz-linear-gradient(top, #c5deea 0%, #066dab 100%); /* FF3.6+ */ | ||
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #c5deea), color-stop(100%, #066dab)); /* Chrome,Safari4+ */ | ||
background: -webkit-linear-gradient(top, #c5deea 0%, #066dab 100%); /* Chrome10+,Safari5.1+ */ | ||
background: -o-linear-gradient(top, #c5deea 0%, #066dab 100%); /* Opera 11.10+ */ | ||
background: -ms-linear-gradient(top, #c5deea 0%, #066dab 100%); /* IE10+ */ | ||
background: linear-gradient(to bottom, #c5deea 0%, #066dab 100%); /* W3C */ | ||
height: 90%; | ||
} | ||
|
||
.center { | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 70%; | ||
background: white; | ||
} | ||
|
||
.chatform { | ||
margin-left: auto; | ||
margin-right: auto; | ||
margin-bottom: 0; | ||
width: 70%; | ||
} | ||
form{ | ||
width: 100%; | ||
} | ||
label{ | ||
display: inline; | ||
width: 100px; | ||
} | ||
#msg{ | ||
display: inline; | ||
width: 100%; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<div class="page"> | ||
<div class="center" > | ||
<div id="chat" style="height:100%;width: 100%; overflow: scroll;"> | ||
|
||
|
||
</div> | ||
|
||
<form onsubmit="return false;" class="chatform" action=""> | ||
<label for="msg">Message</label> | ||
<input type="text" name="message" id="msg" onkeypress="if(event.keyCode==13) { send(this.form.message.value); this.value='' } " /> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
<modules> | ||
<module>quickstart</module> | ||
<module>chat</module> | ||
</modules> | ||
|
||
</project> | ||
|