@ServerEndpoint("/echo") private static class EchoEndpoint { @SuppressWarnings("unused") private final EchoService service; @Autowired public EchoEndpoint(EchoService service) { this.service = service; } }
.create( WSQueryEndpoint.class, WSQueryEndpoint.class.getAnnotation(ServerEndpoint.class).value()
private ServerEndpointConfig createEndpointConfig(Class<?> endpointClass) throws DeploymentException { ServerEndpoint annotation = endpointClass.getAnnotation(ServerEndpoint.class); if (annotation == null) { throw new InvalidWebSocketException("Unsupported WebSocket object, missing @" + ServerEndpoint.class + " annotation"); } return ServerEndpointConfig.Builder.create(endpointClass, annotation.value()) .subprotocols(Arrays.asList(annotation.subprotocols())) .decoders(Arrays.asList(annotation.decoders())) .encoders(Arrays.asList(annotation.encoders())) .configurator(configurator) .build(); }
protected AnnotatedServerEndpointMetadata(WebSocketContainerScope containerScope, Class<?> websocket, ServerEndpointConfig baseConfig) throws DeploymentException { super(websocket); ServerEndpoint anno = websocket.getAnnotation(ServerEndpoint.class); if (anno == null) { throw new InvalidWebSocketException("Unsupported WebSocket object, missing @" + ServerEndpoint.class + " annotation"); } this.endpoint = anno; this.config = new AnnotatedServerEndpointConfig(containerScope,websocket,anno,baseConfig); getDecoders().addAll(anno.decoders()); getEncoders().addAll(anno.encoders()); }
/** * Provides the equivalent of {@link #addEndpoint(ServerEndpointConfig)} for publishing plain old java objects (POJOs) that have been annotated as WebSocket endpoints. * * @param pojo * The annotated POJO */ @Override public void addEndpoint(Class<?> pojo) throws DeploymentException { log.debug("addEndpoint: {}", pojo); ServerEndpoint annotation = pojo.getAnnotation(ServerEndpoint.class); if (annotation == null) { throw new DeploymentException(sm.getString("serverContainer.missingAnnotation", pojo.getName())); } String path = annotation.value(); // Validate encoders validateEncoders(annotation.encoders()); // ServerEndpointConfig ServerEndpointConfig sec; Class<? extends Configurator> configuratorClazz = annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString("serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); } } sec = ServerEndpointConfig.Builder.create(pojo, path).decoders(Arrays.asList(annotation.decoders())).encoders(Arrays.asList(annotation.encoders())).subprotocols(Arrays.asList(annotation.subprotocols())).configurator(configurator).build(); addEndpoint(sec); }
@ServerEndpoint("/echo") private static class PerConnectionEchoEndpoint { @SuppressWarnings("unused") private final EchoService service; @Autowired public PerConnectionEchoEndpoint(EchoService service) { this.service = service; } }
pojo.getName())); String path = annotation.value(); validateEncoders(annotation.encoders()); annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString( "serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); decoders(Arrays.asList(annotation.decoders())). encoders(Arrays.asList(annotation.encoders())). subprotocols(Arrays.asList(annotation.subprotocols())). configurator(configurator). build();
ServerEndpoint annotation = endpoint.getAnnotation(ServerEndpoint.class); if (annotation != null) { String path = annotation.value(); addManagementWebsocket(deploymentUnit, endpoint, path);
@ServerEndpoint("/path") private static class AnnotatedDummyEndpoint { }
pojo.getName())); String path = annotation.value(); validateEncoders(annotation.encoders()); annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString( "serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); decoders(Arrays.asList(annotation.decoders())). encoders(Arrays.asList(annotation.encoders())). subprotocols(Arrays.asList(annotation.subprotocols())). configurator(configurator). build();
/** * Extract the URI from the endpoint. * <b>Note that it is better use validateEndpointUri method to validate the endpoint uri * before getting it out if needed. Otherwise it will cause issues. Use this method only and only if * it is sure that endpoint contains {@link ServerEndpoint} defined.</b> * * @param webSocketEndpoint WebSocket endpoint which the URI should be extracted. * @return the URI of the Endpoint as a String. */ public String getUri(Object webSocketEndpoint) { return webSocketEndpoint.getClass().getAnnotation(ServerEndpoint.class).value(); }
@ServerEndpoint("/path") private static class AnnotatedDummyEndpointBean { }
pojo.getName())); String path = annotation.value(); validateEncoders(annotation.encoders()); annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().newInstance(); } catch (InstantiationException e) { throw new DeploymentException(sm.getString( "serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); } catch (IllegalAccessException e) { throw new DeploymentException(sm.getString( "serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); decoders(Arrays.asList(annotation.decoders())). encoders(Arrays.asList(annotation.encoders())). subprotocols(Arrays.asList(annotation.subprotocols())). configurator(configurator). build();
/** * Extract the URI from the endpoint. * <b>Note that it is better use validateEndpointUri method to validate the endpoint uri * before getting it out if needed. Otherwise it will cause issues. Use this method only and only if * it is sure that endpoint contains {@link ServerEndpoint} defined.</b> * * @param webSocketEndpoint WebSocket endpoint which the URI should be extracted. * @return the URI of the Endpoint as a String. */ public String getUri(Object webSocketEndpoint) { return webSocketEndpoint.getClass().getAnnotation(ServerEndpoint.class).value(); }
@Component("myComponentEchoEndpoint") @ServerEndpoint("/echo") private static class ComponentEchoEndpoint { @SuppressWarnings("unused") private final EchoService service; @Autowired public ComponentEchoEndpoint(EchoService service) { this.service = service; } }
pojo.getName())); String path = annotation.value(); validateEncoders(annotation.encoders()); annotation.decoders(), path); annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new DeploymentException(sm.getString( "serverContainer.configuratorFail", annotation.configurator().getName(), pojo.getClass().getName()), e); decoders(Arrays.asList(annotation.decoders())). encoders(Arrays.asList(annotation.encoders())). subprotocols(Arrays.asList(annotation.subprotocols())). configurator(configurator). build();
/** * Get the {@link URI} for the {@link ServerEndpoint} annotated class. * * @param serverClass the annotated class the {@link URI} is computed for. * @param scheme scheme of newly created {@link URI}. If {@code null}, "ws" will be used. * @return {@link URI} which is used to connect to the given endpoint. */ protected URI getURI(Class<?> serverClass, String scheme) { String endpointPath = serverClass.getAnnotation(ServerEndpoint.class).value(); return getURI(endpointPath, scheme); }
@ServerEndpoint("/") public class ChromeRDPDebuggerEndpoint implements ChromeRDPExchange { public static final int MAX_MESSAGE_SIZE = 65534;
throw new DeploymentException(MESSAGES.cannotDeployPojo(pojo.getName())); String path = annotation.value(); validateEncoders(annotation.encoders()); annotation.decoders(), path); annotation.configurator(); Configurator configurator = null; if (!configuratorClazz.equals(Configurator.class)) { try { configurator = annotation.configurator().newInstance(); } catch (InstantiationException e) { throw new DeploymentException(MESSAGES.configuratorFailed(annotation.configurator().getName(), pojo.getClass().getName()), e); } catch (IllegalAccessException e) { throw new DeploymentException(MESSAGES.configuratorFailed(annotation.configurator().getName(), pojo.getClass().getName()), e); decoders(Arrays.asList(annotation.decoders())). encoders(Arrays.asList(annotation.encoders())). subprotocols(Arrays.asList(annotation.subprotocols())). configurator(configurator). build();
/** * Get the {@link URI} for the {@link ServerEndpoint} annotated class. * * @param serverClass the annotated class the {@link URI} is computed for. * @param scheme scheme of newly created {@link URI}. If {@code null}, "ws" will be used. * @return {@link URI} which is used to connect to the given endpoint. */ protected URI getURI(Class<?> serverClass, String scheme) { String endpointPath = serverClass.getAnnotation(ServerEndpoint.class).value(); return getURI(endpointPath, scheme); }