ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
Status
scanned
Type
file
Name
EchoEndpoint.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3345 (3.3 KB)
MD5
fd623af00d911a007581d76de8830f3a
SHA1
85c9a03be1743ae8c9c52a76082ddd546a57e17b
SHA256
ab02f9f9d4b5589dfef63aa5c3d7c3de0ea5780052aed9e0933c5f1ec8273c7b
SHA512

      
    
SHA1_git
a8f65283c93f38f41ae814661da3558bc0678b4d
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
EchoEndpoint.java | 3.3 KB |

/* * 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 websocket.echo; import java.io.IOException; import java.nio.ByteBuffer; import jakarta.websocket.Endpoint; import jakarta.websocket.EndpointConfig; import jakarta.websocket.MessageHandler; import jakarta.websocket.RemoteEndpoint; import jakarta.websocket.Session; public class EchoEndpoint extends Endpoint { @Override public void onOpen(Session session, EndpointConfig endpointConfig) { RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote(); session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic, session)); session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic, session)); } private static class EchoMessageHandlerText implements MessageHandler.Partial<String> { private final RemoteEndpoint.Basic remoteEndpointBasic; private final Session session; private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic, Session session) { this.remoteEndpointBasic = remoteEndpointBasic; this.session = session; } @Override public void onMessage(String message, boolean last) { try { if (remoteEndpointBasic != null) { remoteEndpointBasic.sendText(message, last); } } catch (IOException ioe) { try { session.close(); } catch (IOException ignore) { // Ignore } } } } private static class EchoMessageHandlerBinary implements MessageHandler.Partial<ByteBuffer> { private final RemoteEndpoint.Basic remoteEndpointBasic; private final Session session; private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic, Session session) { this.remoteEndpointBasic = remoteEndpointBasic; this.session = session; } @Override public void onMessage(ByteBuffer message, boolean last) { try { if (remoteEndpointBasic != null) { remoteEndpointBasic.sendBinary(message, last); } } catch (IOException ioe) { try { session.close(); } catch (IOException ignore) { // Ignore } } } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
41.32
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9