@Override public InetSocketAddress call() throws Exception { return (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_LOCAL_ADDRESS); } })
annotatedClass, configuration.getEncoders(), configuration.getDecoders(), collector);
protected void setEncoders(EndpointConfig endpointConfig) throws DeploymentException { encoderEntries.clear(); for (Class<? extends Encoder> encoderClazz : endpointConfig.getEncoders()) { Encoder instance; try { instance = encoderClazz.getConstructor().newInstance(); instance.init(endpointConfig); } catch (ReflectiveOperationException e) { throw new DeploymentException( sm.getString("wsRemoteEndpoint.invalidEncoder", encoderClazz.getName()), e); } EncoderEntry entry = new EncoderEntry( Util.getEncoderType(encoderClazz), instance); encoderEntries.add(entry); } }
private static DecoderMatch matchDecoders(Class<?> target, EndpointConfig endpointConfig) { DecoderMatch decoderMatch; try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); List<DecoderEntry> decoderEntries = getDecoders(decoders); decoderMatch = new DecoderMatch(target, decoderEntries); } catch (DeploymentException e) { throw new IllegalArgumentException(e); } return decoderMatch; }
annotatedClass, configuration.getEncoders(), configuration.getDecoders(), collector);
protected void setEncoders(EndpointConfig endpointConfig) throws DeploymentException { encoderEntries.clear(); for (Class<? extends Encoder> encoderClazz : endpointConfig.getEncoders()) { Encoder instance; try { instance = encoderClazz.getConstructor().newInstance(); instance.init(endpointConfig); } catch (ReflectiveOperationException e) { throw new DeploymentException( sm.getString("wsRemoteEndpoint.invalidEncoder", encoderClazz.getName()), e); } EncoderEntry entry = new EncoderEntry( Util.getEncoderType(encoderClazz), instance); encoderEntries.add(entry); } }
private static DecoderMatch matchDecoders(Class<?> target, EndpointConfig endpointConfig) { DecoderMatch decoderMatch; try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); List<DecoderEntry> decoderEntries = getDecoders(decoders); decoderMatch = new DecoderMatch(target, decoderEntries); } catch (DeploymentException e) { throw new IllegalArgumentException(e); } return decoderMatch; }
@Override public InetSocketAddress call() throws Exception { return (InetSocketAddress) endpointConfig.getUserProperties().get(JAVAX_WEBSOCKET_ENDPOINT_REMOTE_ADDRESS); } })
for (Class<? extends Decoder> decoderClass : this.configuration.getDecoders()) { Class<?> type = getDecoderClassType(decoderClass); if (getDefaultDecoders().contains(decoderClass)) { for (Class<? extends Encoder> encoderClass : this.configuration.getEncoders()) { Class<?> type = getEncoderClassType(encoderClass); encoders.add(new CoderWrapper<Encoder>(encoderClass, type));
protected void setEncoders(EndpointConfig endpointConfig) throws DeploymentException { encoderEntries.clear(); for (Class<? extends Encoder> encoderClazz : endpointConfig.getEncoders()) { Encoder instance; try { instance = encoderClazz.newInstance(); instance.init(endpointConfig); } catch (InstantiationException | IllegalAccessException e) { throw new DeploymentException( sm.getString("wsRemoteEndpoint.invalidEncoder", encoderClazz.getName()), e); } EncoderEntry entry = new EncoderEntry( Util.getEncoderType(encoderClazz), instance); encoderEntries.add(entry); } }
try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); @SuppressWarnings("unchecked") List<DecoderEntry> decoderEntries = getDecoders(
@OnOpen public void onOpen(Session session, EndpointConfig config) { User user = (User) config.getUserProperties().get("user"); // ... }
for (Class<? extends Decoder> decoderClass : this.configuration.getDecoders()) { Class<?> type = getDecoderClassType(decoderClass); if (getDefaultDecoders().contains(decoderClass)) { for (Class<? extends Encoder> encoderClass : this.configuration.getEncoders()) { Class<?> type = getEncoderClassType(encoderClass); encoders.add(new CoderWrapper<Encoder>(encoderClass, type));
protected void setEncoders(EndpointConfig endpointConfig) throws DeploymentException { encoderEntries.clear(); for (Class<? extends Encoder> encoderClazz : endpointConfig.getEncoders()) { Encoder instance; try { instance = encoderClazz.newInstance(); instance.init(endpointConfig); } catch (InstantiationException e) { throw new DeploymentException( MESSAGES.cannotInstatiateEncoder(encoderClazz.getName()), e); } catch (IllegalAccessException e) { throw new DeploymentException( MESSAGES.cannotInstatiateEncoder(encoderClazz.getName()), e); } EncoderEntry entry = new EncoderEntry( Util.getEncoderType(encoderClazz), instance); encoderEntries.add(entry); } }
try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); @SuppressWarnings("unchecked") List<DecoderEntry> decoderEntries = getDecoders(
@ServerEndpoint(value="/push", configurator=UserAwareConfigurator.class) public class PushEndpoint { @Inject private PushContext pushContext; @OnOpen public void onOpen(Session session, EndpointConfig config) { User user = (User) config.getUserProperties().get("user"); pushContext.add(session, user); } @OnClose public void onClose(Session session) { pushContext.remove(session); } }
protected void setEncoders(EndpointConfig endpointConfig) throws DeploymentException { encoderEntries.clear(); for (Class<? extends Encoder> encoderClazz : endpointConfig.getEncoders()) { Encoder instance; try { instance = encoderClazz.newInstance(); instance.init(endpointConfig); } catch (InstantiationException e) { throw new DeploymentException( sm.getString("wsRemoteEndpoint.invalidEncoder", encoderClazz.getName()), e); } catch (IllegalAccessException e) { throw new DeploymentException( sm.getString("wsRemoteEndpoint.invalidEncoder", encoderClazz.getName()), e); } EncoderEntry entry = new EncoderEntry( Util.getEncoderType(encoderClazz), instance); encoderEntries.add(entry); } }
@OnOpen public void onOpen(final Session session, EndpointConfig config) { Principal userPrincipal = (Principal) config.getUserProperties().get("UserPrincipal"); Boolean userInRole = (Boolean) config.getUserProperties().get("userInRole"); //do what ever you like with it }
import javax.websocket.EndpointConfig; import javax.websocket.OnClose; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; @ServerEndpoint(value = "/foo", configurator = MyServerEndpointConfigurator.class) public class MyEndpoint { @OnOpen public void onOpen(Session session, EndpointConfig endpointConfig) throws Exception { String ip = ((TyrusSession) session).getRemoteAddr(); String userAgent = (String) endpointConfig.getUserProperties().get("user-agent"); ... } }
@SuppressWarnings("unchecked") @Override public final void init(final EndpointConfig config) { this.unmarshaller = (Supplier<Unmarshaller>) config.getUserProperties().get(UserProperties.UNMARSHALLER); this.onRead = (BiConsumer<String, StreamElement>) config.getUserProperties().get(UserProperties.ON_READ); }