All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.boot.starter.undertow.WebSocketSupport Maven / Gradle / Ivy

There is a newer version: 2.5.1.v20220215
Show newest version
package org.nutz.boot.starter.undertow;

import javax.websocket.server.ServerEndpoint;

import org.nutz.resource.Scans;

import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;

/**
 * websocket支持.
 * 如果项目中不需要使用websocket,则可以在自己项目的pom.xml中排除掉undertow-websockets-jsr即可
 * 
 * @author qinerg([email protected])
 */
public class WebSocketSupport {

	public static void addWebSocketSupport(DeploymentInfo deployment, String packageName) {
		WebSocketDeploymentInfo wsInfo = new WebSocketDeploymentInfo();
		for (Class klass : Scans.me().scanPackage(packageName)) {
			if (klass.getAnnotation(ServerEndpoint.class) != null) {
				wsInfo.addEndpoint(klass);
			}
		}

		deployment.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, wsInfo);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy