Skip to content

Commit

Permalink
Fixes #4056 - Update Piranha Servlet - Create a WebSocket application…
Browse files Browse the repository at this point in the history
… guide (#4058)
  • Loading branch information
mnriem authored Oct 17, 2024
1 parent 806f9ba commit ed3c5d1
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
<module>hello</module>
<module>helloworld</module>
<module>pages</module>
<module>websocket</module>
</modules>
</project>
83 changes: 83 additions & 0 deletions test/servlet/websocket/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--
WARNING - Do not remove the versions in the properties section as this
particular project is used as a basis for the guide content at
docs/src/site/markdown/servlet/create_a_websocket_application.md.
When updating the guide do the following:
1. Change the name of the project to read 'Create a WebSocket Chat application on Piranha Servlet'
2. Add groupId 'guide'
3. Add version '1-SNAPSHOT'
4. Drop the parent section below
5. Change the piranha.version to the latest released version of Piranha
-->
<parent>
<groupId>cloud.piranha.test.servlet</groupId>
<artifactId>project</artifactId>
<version>24.11.0-SNAPSHOT</version>
</parent>
<artifactId>websocket</artifactId>
<packaging>war</packaging>
<name>Piranha - Test - Servlet - WebSocket application</name>
<properties>
<!-- dependencies -->
<jakarta.websocket.version>2.1.1</jakarta.websocket.version>
<piranha.version>${project.version}</piranha.version>
<!-- other -->
<java.version>21</java.version>
<piranha.distribution>servlet</piranha.distribution>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- plugins -->
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta.websocket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<version>${jakarta.websocket.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>websocket</finalName>
<plugins>
<plugin>
<groupId>cloud.piranha.maven.plugins</groupId>
<artifactId>piranha-maven-plugin</artifactId>
<version>${piranha.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
48 changes: 48 additions & 0 deletions test/servlet/websocket/src/main/java/chat/ChatEndpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package chat;

import jakarta.websocket.OnMessage;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;

@ServerEndpoint("/chat")
public class ChatEndpoint {

/**
* Handle the message coming in.
*
* @param message the message.
* @param session the session.
* @return the response.
*/
@OnMessage
public String onMessage(String message, Session session) {
return message;
}
}

0 comments on commit ed3c5d1

Please sign in to comment.