File tree Expand file tree Collapse file tree 5 files changed +110
-0
lines changed
java/org/javaee7/websocket/endpoint/wss Expand file tree Collapse file tree 5 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ <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" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <parent >
5+ <groupId >org.javaee7.websocket</groupId >
6+ <artifactId >websocket-samples</artifactId >
7+ <version >1.0-SNAPSHOT</version >
8+ <relativePath >../pom.xml</relativePath >
9+ </parent >
10+
11+ <groupId >org.javaee7.websocket</groupId >
12+ <artifactId >endpoint-wss</artifactId >
13+ <version >1.0-SNAPSHOT</version >
14+ <packaging >war</packaging >
15+ </project >
Original file line number Diff line number Diff line change 1+ package org .javaee7 .websocket .endpoint .wss ;
2+
3+ import javax .websocket .OnMessage ;
4+ import javax .websocket .server .ServerEndpoint ;
5+
6+ /**
7+ * @author Arun Gupta
8+ */
9+ @ ServerEndpoint ("/websocket" )
10+ public class MyEndpoint {
11+
12+ @ OnMessage
13+ public String echoText (String name ) {
14+ return name ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+
3+ <web-app xmlns =" http://xmlns.jcp.org/xml/ns/javaee"
4+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
5+ xsi : schemaLocation =" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
6+ version =" 3.1" >
7+
8+ <security-constraint >
9+ <web-resource-collection >
10+ <web-resource-name >Viewpoint Secure URLs</web-resource-name >
11+ <url-pattern >/*</url-pattern >
12+ </web-resource-collection >
13+ <user-data-constraint >
14+ <transport-guarantee >CONFIDENTIAL</transport-guarantee >
15+ </user-data-constraint >
16+ </security-constraint >
17+
18+ <session-config >
19+ <session-timeout >
20+ 30
21+ </session-timeout >
22+ </session-config >
23+ </web-app >
Original file line number Diff line number Diff line change 1+ <%@page contentType =" text/html" pageEncoding =" UTF-8" %>
2+ <!DOCTYPE html>
3+ <html >
4+ <head >
5+ <meta http-equiv =" Content-Type" content =" text/html; charset=UTF-8" >
6+ <title >WebSocket Security</title >
7+
8+ </head >
9+ <body >
10+ <h1 >WebSocket Security</h1 >
11+
12+ <div style =" text-align : center ;" >
13+ <form action =" " >
14+ <input id =" myField" value =" WebSocket" type =" text" ><br >
15+ <input onclick =" echo();" value =" Echo" type =" button" >
16+ </form >
17+ </div >
18+ <div id =" output" ></div >
19+ <script language =" javascript" type =" text/javascript" src =" websocket.js" >
20+ </script >
21+ </body >
22+ </html >
Original file line number Diff line number Diff line change 1+ var wsUri = "ws://" + document . location . host + document . location . pathname + "websocket" ;
2+ console . log ( "Connecting to " + wsUri ) ;
3+ var websocket = new WebSocket ( wsUri ) ;
4+ websocket . onopen = function ( evt ) { onOpen ( evt ) } ;
5+ websocket . onmessage = function ( evt ) { onMessage ( evt ) } ;
6+ websocket . onerror = function ( evt ) { onError ( evt ) } ;
7+
8+ var output = document . getElementById ( "output" ) ;
9+
10+ function echo ( ) {
11+ console . log ( "echo: " + myField . value ) ;
12+ websocket . send ( myField . value ) ;
13+ writeToScreen ( "SENT (text): " + myField . value ) ;
14+ }
15+
16+ function onOpen ( ) {
17+ console . log ( "onOpen" ) ;
18+ writeToScreen ( "CONNECTED" ) ;
19+ }
20+
21+ function onMessage ( evt ) {
22+ writeToScreen ( "RECEIVED (text): " + evt . data ) ;
23+ }
24+
25+ function onError ( evt ) {
26+ writeToScreen ( '<span style="color: red;">ERROR:</span> ' + evt . data ) ;
27+ }
28+
29+ function writeToScreen ( message ) {
30+ var pre = document . createElement ( "p" ) ;
31+ pre . style . wordWrap = "break-word" ;
32+ pre . innerHTML = message ;
33+ output . appendChild ( pre ) ;
34+ }
You can’t perform that action at this time.
0 commit comments