Java 类javax.websocket.EndpointConfig 实例源码

项目:lazycat    文件:PojoEndpointServer.java   
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {

    ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;

    Object pojo;
    try {
        pojo = sec.getConfigurator().getEndpointInstance(sec.getEndpointClass());
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(
                sm.getString("pojoEndpointServer.getPojoInstanceFail", sec.getEndpointClass().getName()), e);
    }
    setPojo(pojo);

    @SuppressWarnings("unchecked")
    Map<String, String> pathParameters = (Map<String, String>) sec.getUserProperties().get(POJO_PATH_PARAM_KEY);
    setPathParameters(pathParameters);

    PojoMethodMapping methodMapping = (PojoMethodMapping) sec.getUserProperties().get(POJO_METHOD_MAPPING_KEY);
    setMethodMapping(methodMapping);

    doOnOpen(session, endpointConfig);
}
项目:lazycat    文件:PojoMethodMapping.java   
private static Object[] buildArgs(PojoPathParam[] pathParams, Map<String, String> pathParameters, Session session,
        EndpointConfig config, Throwable throwable, CloseReason closeReason) throws DecodeException {
    Object[] result = new Object[pathParams.length];
    for (int i = 0; i < pathParams.length; i++) {
        Class<?> type = pathParams[i].getType();
        if (type.equals(Session.class)) {
            result[i] = session;
        } else if (type.equals(EndpointConfig.class)) {
            result[i] = config;
        } else if (type.equals(Throwable.class)) {
            result[i] = throwable;
        } else if (type.equals(CloseReason.class)) {
            result[i] = closeReason;
        } else {
            String name = pathParams[i].getName();
            String value = pathParameters.get(name);
            try {
                result[i] = Util.coerceToType(type, value);
            } catch (Exception e) {
                throw new DecodeException(value, sm.getString("pojoMethodMapping.decodePathParamFail", value, type),
                        e);
            }
        }
    }
    return result;
}
项目:belling-admin    文件:OnlineNoticeServer.java   
/**
 * 连接建立成功调用的方法-与前端JS代码对应
 * 
 * @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据
 */
@OnOpen
public void onOpen(Session session, EndpointConfig config) {
    // 单个会话对象保存
    this.session = session;
    webSocketSet.add(this); // 加入set中
    this.httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
    String uId = (String) httpSession.getAttribute("userid"); // 获取当前用户
    String sessionId = httpSession.getId();
    this.userid = uId + "|" + sessionId;
    if (!OnlineUserlist.contains(this.userid)) {
        OnlineUserlist.add(userid); // 将用户名加入在线列表
    }
    routetabMap.put(userid, session); // 将用户名和session绑定到路由表
    System.out.println(userid + " -> 已上线");
    String message = getMessage(userid + " -> 已上线", "notice", OnlineUserlist);
    broadcast(message); // 广播
}
项目:flow-platform    文件:LogEventHandler.java   
private void initWebSocketSession(String url, int wsConnectionTimeout) throws Exception {
    CountDownLatch wsLatch = new CountDownLatch(1);
    ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
    ClientManager client = ClientManager.createClient();

    client.connectToServer(new Endpoint() {
        @Override
        public void onOpen(Session session, EndpointConfig endpointConfig) {
            wsSession = session;
            wsLatch.countDown();
        }
    }, cec, new URI(url));

    if (!wsLatch.await(wsConnectionTimeout, TimeUnit.SECONDS)) {
        throw new TimeoutException("Web socket connection timeout");
    }
}
项目:BasicsProject    文件:WSMI.java   
/**连接建立成功调用的方法*/
@OnOpen
public void onOpen(Session session,EndpointConfig config){
    HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
    if(StorageUtil.init(httpSession).getLoginMemberId()!=ReturnUtil.NOT_LOGIN_CODE){
        long userId = StorageUtil.init(httpSession).getLoginMemberId();
        mapUS.put(userId,session);
        mapSU.put(session,userId);
        //上线通知由客户端自主发起
        onlineCount++;           //在线数加1
        System.out.println("用户"+userId+"进入WebSocket!当前在线人数为" + onlineCount);
        getUserKey(userId);
    }else{
        try {
            session.close();
            System.out.println("未获取到用户信息,关闭WebSocket!");
        } catch (IOException e) {
            System.out.println("关闭WebSocket失败!");
        }
    }
}
项目:websocket    文件:java7Ws.java   
@Override
public void onOpen(Session session, EndpointConfig arg1) {
    final RemoteEndpoint.Basic remote = session.getBasicRemote();
    session.addMessageHandler(new MessageHandler.Whole<String>() {
        public void onMessage(String text) {
            try {
                remote.sendText(text.toUpperCase());
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    });
}
项目:tomcat7    文件:PojoEndpointServer.java   
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {

    ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;

    Object pojo;
    try {
        pojo = sec.getConfigurator().getEndpointInstance(
                sec.getEndpointClass());
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(sm.getString(
                "pojoEndpointServer.getPojoInstanceFail",
                sec.getEndpointClass().getName()), e);
    }
    setPojo(pojo);

    @SuppressWarnings("unchecked")
    Map<String,String> pathParameters =
            (Map<String, String>) sec.getUserProperties().get(
                    POJO_PATH_PARAM_KEY);
    setPathParameters(pathParameters);

    PojoMethodMapping methodMapping =
            (PojoMethodMapping) sec.getUserProperties().get(
                    POJO_METHOD_MAPPING_KEY);
    setMethodMapping(methodMapping);

    doOnOpen(session, endpointConfig);
}
项目:tomcat7    文件:PojoMethodMapping.java   
public Set<MessageHandler> getMessageHandlers(Object pojo,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config) {
    Set<MessageHandler> result = new HashSet<MessageHandler>();
    for (MessageHandlerInfo messageMethod : onMessage) {
        result.addAll(messageMethod.getMessageHandlers(pojo, pathParameters,
                session, config));
    }
    return result;
}
项目:tomcat7    文件:PojoMethodMapping.java   
private static Object[] buildArgs(PojoPathParam[] pathParams,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config, Throwable throwable, CloseReason closeReason)
        throws DecodeException {
    Object[] result = new Object[pathParams.length];
    for (int i = 0; i < pathParams.length; i++) {
        Class<?> type = pathParams[i].getType();
        if (type.equals(Session.class)) {
            result[i] = session;
        } else if (type.equals(EndpointConfig.class)) {
            result[i] = config;
        } else if (type.equals(Throwable.class)) {
            result[i] = throwable;
        } else if (type.equals(CloseReason.class)) {
            result[i] = closeReason;
        } else {
            String name = pathParams[i].getName();
            String value = pathParameters.get(name);
            try {
                result[i] = Util.coerceToType(type, value);
            } catch (Exception e) {
                throw new DecodeException(value, sm.getString(
                        "pojoMethodMapping.decodePathParamFail",
                        value, type), e);
            }
        }
    }
    return result;
}
项目:tomcat7    文件:Util.java   
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target,
        EndpointConfig endpointConfig, boolean binary) {
    DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
    if (binary) {
        if (decoderMatch.getBinaryDecoders().size() > 0) {
            return decoderMatch.getBinaryDecoders();
        }
    } else if (decoderMatch.getTextDecoders().size() > 0) {
        return decoderMatch.getTextDecoders();
    }
    return null;
}
项目:tomcat7    文件:Util.java   
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;
}
项目:tomcat7    文件:TestPojoEndpointBase.java   
@OnOpen
public void onOpen(@SuppressWarnings("unused") Session session,
        EndpointConfig config) {
    if (config == null) {
        throw new RuntimeException();
    }
}
项目:websocket-http-session    文件:WebSocketEndpointConcurrencyTest.java   
@Override
public void onOpen(Session sn, EndpointConfig ec) {
    try {
        sn.addMessageHandler(String.class, new MessageHandler.Whole<String>() {
            @Override
            public void onMessage(String m) {
                System.out.println("got message from server - " + m);
            }
        });
    } catch (Exception ex) {
        Logger.getLogger(WebSocketEndpointConcurrencyTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}
项目:acmeair-modular    文件:SupportWebSocket.java   
@OnOpen
public void onOpen(final Session session, EndpointConfig ec) {
    currentSession = session;
    agent = getRandomSupportAgent(); 

    String greeting = getGreeting(agent); 
    currentSession.getAsyncRemote().sendText(greeting);
}
项目:acmeair-modular    文件:SupportWebSocket.java   
@OnOpen
public void onOpen(final Session session, EndpointConfig ec) {
    currentSession = session;
    agent = getRandomSupportAgent(); 

    String greeting = getGreeting(agent); 
    currentSession.getAsyncRemote().sendText(greeting);
}
项目:lams    文件:WebsocketClient.java   
@Override
   public void onOpen(Session session, EndpointConfig endpointConfig) {
this.session = session;
if (messageHandler != null) {
    session.addMessageHandler(messageHandler);
}
   }
项目:websocket-http-session    文件:Service.java   
@OnOpen
public void opened(@PathParam("user") String user, Session session, EndpointConfig config) throws IOException{
    System.out.println("opened() Current thread "+ Thread.currentThread().getName());
    this.httpSession = (HttpSession) config.getUserProperties().get(user);
    System.out.println("User joined "+ user + " with http session id "+ httpSession.getId());
    String response = "User " + user + " | WebSocket session ID "+ session.getId() +" | HTTP session ID " + httpSession.getId();
    System.out.println(response);
    session.getBasicRemote().sendText(response);
}
项目:lazycat    文件:Util.java   
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target, EndpointConfig endpointConfig,
        boolean binary) {
    DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
    if (binary) {
        if (decoderMatch.getBinaryDecoders().size() > 0) {
            return decoderMatch.getBinaryDecoders();
        }
    } else if (decoderMatch.getTextDecoders().size() > 0) {
        return decoderMatch.getTextDecoders();
    }
    return null;
}
项目:websocket-chat    文件:ChatServerTest.java   
@Override
public void onOpen(Session sn, EndpointConfig ec) {
    this.sn = sn;
    controlLatch.countDown();
    sn.addMessageHandler(String.class, s -> {
        response = s;
        controlLatch.countDown();
    });
}
项目:lazycat    文件:Util.java   
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;
}
项目:lazycat    文件:WsHttpUpgradeHandler.java   
public void preInit(Endpoint ep, EndpointConfig endpointConfig, WsServerContainer wsc,
        WsHandshakeRequest handshakeRequest, List<Extension> negotiatedExtensionsPhase2, String subProtocol,
        Transformation transformation, Map<String, String> pathParameters, boolean secure) {
    this.ep = ep;
    this.endpointConfig = endpointConfig;
    this.webSocketContainer = wsc;
    this.handshakeRequest = handshakeRequest;
    this.negotiatedExtensions = negotiatedExtensionsPhase2;
    this.subProtocol = subProtocol;
    this.transformation = transformation;
    this.pathParameters = pathParameters;
    this.secure = secure;
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoEndpointServer.java   
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {

    ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;

    Object pojo;
    try {
        pojo = sec.getConfigurator().getEndpointInstance(
                sec.getEndpointClass());
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(sm.getString(
                "pojoEndpointServer.getPojoInstanceFail",
                sec.getEndpointClass().getName()), e);
    }
    setPojo(pojo);

    @SuppressWarnings("unchecked")
    Map<String,String> pathParameters =
            (Map<String, String>) sec.getUserProperties().get(
                    POJO_PATH_PARAM_KEY);
    setPathParameters(pathParameters);

    PojoMethodMapping methodMapping =
            (PojoMethodMapping) sec.getUserProperties().get(
                    POJO_METHOD_MAPPING_KEY);
    setMethodMapping(methodMapping);

    doOnOpen(session, endpointConfig);
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoMethodMapping.java   
public Set<MessageHandler> getMessageHandlers(Object pojo,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config) {
    Set<MessageHandler> result = new HashSet<MessageHandler>();
    for (MessageHandlerInfo messageMethod : onMessage) {
        result.addAll(messageMethod.getMessageHandlers(pojo, pathParameters,
                session, config));
    }
    return result;
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoMethodMapping.java   
private static Object[] buildArgs(PojoPathParam[] pathParams,
        Map<String,String> pathParameters, Session session,
        EndpointConfig config, Throwable throwable, CloseReason closeReason)
        throws DecodeException {
    Object[] result = new Object[pathParams.length];
    for (int i = 0; i < pathParams.length; i++) {
        Class<?> type = pathParams[i].getType();
        if (type.equals(Session.class)) {
            result[i] = session;
        } else if (type.equals(EndpointConfig.class)) {
            result[i] = config;
        } else if (type.equals(Throwable.class)) {
            result[i] = throwable;
        } else if (type.equals(CloseReason.class)) {
            result[i] = closeReason;
        } else {
            String name = pathParams[i].getName();
            String value = pathParameters.get(name);
            try {
                result[i] = Util.coerceToType(type, value);
            } catch (Exception e) {
                throw new DecodeException(value, sm.getString(
                        "pojoMethodMapping.decodePathParamFail",
                        value, type), e);
            }
        }
    }
    return result;
}
项目:apache-tomcat-7.0.73-with-comment    文件:Util.java   
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target,
        EndpointConfig endpointConfig, boolean binary) {
    DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
    if (binary) {
        if (decoderMatch.getBinaryDecoders().size() > 0) {
            return decoderMatch.getBinaryDecoders();
        }
    } else if (decoderMatch.getTextDecoders().size() > 0) {
        return decoderMatch.getTextDecoders();
    }
    return null;
}
项目:apache-tomcat-7.0.73-with-comment    文件:Util.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:WsHttpUpgradeHandler.java   
public void preInit(Endpoint ep, EndpointConfig endpointConfig,
        WsServerContainer wsc, WsHandshakeRequest handshakeRequest,
        List<Extension> negotiatedExtensionsPhase2, String subProtocol,
        Transformation transformation, Map<String,String> pathParameters,
        boolean secure) {
    this.ep = ep;
    this.endpointConfig = endpointConfig;
    this.webSocketContainer = wsc;
    this.handshakeRequest = handshakeRequest;
    this.negotiatedExtensions = negotiatedExtensionsPhase2;
    this.subProtocol = subProtocol;
    this.transformation = transformation;
    this.pathParameters = pathParameters;
    this.secure = secure;
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestPojoEndpointBase.java   
@OnOpen
public void onOpen(@SuppressWarnings("unused") Session session,
        EndpointConfig config) {
    if (config == null) {
        throw new RuntimeException();
    }
}
项目:lazycat    文件:PojoMethodMapping.java   
public Set<MessageHandler> getMessageHandlers(Object pojo, Map<String, String> pathParameters, Session session,
        EndpointConfig config) {
    Set<MessageHandler> result = new HashSet<MessageHandler>();
    for (MessageHandlerInfo messageMethod : onMessage) {
        result.addAll(messageMethod.getMessageHandlers(pojo, pathParameters, session, config));
    }
    return result;
}
项目:redis-websocket-javaee    文件:MeetupRSVPsWebSocketClient.java   
@Override
    public void onOpen(Session session, EndpointConfig config) {
        System.out.println("Server session established");
        //conn to redis
        jedis = new Jedis("192.168.99.100", 6379, 10000);
        session.addMessageHandler(new MessageHandler.Whole<MeetupRSVP>() {
            @Override
            public void onMessage(MeetupRSVP message) {
                List<GroupTopic> groupTopics = message.getGroup().getGroupTopics();
                for (GroupTopic groupTopic : groupTopics) {
                    try {

                        if(GROUPS_IN_REDIS.contains(groupTopic.getTopicName())){
                            jedis.zincrby(LEADERBOARD_REDIS_KEY, 1, groupTopic.getTopicName());
                        }else{
                            //zscore = jedis.zscore(LEADERBOARD_REDIS_KEY, groupTopic.getTopicName());
                            jedis.zadd(LEADERBOARD_REDIS_KEY, 1, groupTopic.getTopicName());
                            GROUPS_IN_REDIS.add(groupTopic.getTopicName());
                        }

//                        Double zscore = jedis.zscore(LEADERBOARD_REDIS_KEY, groupTopic.getTopicName());;
//                        if(zscore == null){
//                            jedis.zadd(LEADERBOARD_REDIS_KEY, 1, groupTopic.getTopicName());
//                        }else{
//                            jedis.zincrby(LEADERBOARD_REDIS_KEY, 1, groupTopic.getTopicName());
//                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }
        });

    }
项目:websocket    文件:java7Ws.java   
public void onClose(Session arg0, EndpointConfig arg1) {
    System.out.println("close...");
}
项目:websocket    文件:java7Ws.java   
public void onError(Session arg0, EndpointConfig arg1) {
    System.out.println("error...");
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:SecureSocketClient.java   
@Override
public void onOpen(Session session, EndpointConfig config) {
    sessionClient = session;
    session.getAsyncRemote().sendText("hi");
}
项目:Clipcon-AndroidClient    文件:MessageDecoder.java   
public void init(EndpointConfig arg0) {
    tmp = new JSONObject();
}
项目:Clipcon-AndroidClient    文件:MessageEncoder.java   
public void init(EndpointConfig arg0) {
    tmp = new JSONObject();
}
项目:cf-java-client-sap    文件:LoggregatorEndpoint.java   
@Override
public void onOpen(Session session, EndpointConfig config) {
    session.addMessageHandler(new LoggregatorMessageHandler(listener));
}
项目:tomcat7    文件:PojoEndpointClient.java   
@Override
public void onOpen(Session session, EndpointConfig config) {
    doOnOpen(session, config);
}
项目:tomcat7    文件:PojoMethodMapping.java   
public Object[] getOnOpenArgs(Map<String,String> pathParameters,
        Session session, EndpointConfig config) throws DecodeException {
    return buildArgs(onOpenParams, pathParameters, session, config, null,
            null);
}
项目:tomcat7    文件:PojoMethodMapping.java   
private static PojoPathParam[] getPathParams(Method m,
        MethodType methodType) throws DeploymentException {
    if (m == null) {
        return new PojoPathParam[0];
    }
    boolean foundThrowable = false;
    Class<?>[] types = m.getParameterTypes();
    Annotation[][] paramsAnnotations = m.getParameterAnnotations();
    PojoPathParam[] result = new PojoPathParam[types.length];
    for (int i = 0; i < types.length; i++) {
        Class<?> type = types[i];
        if (type.equals(Session.class)) {
            result[i] = new PojoPathParam(type, null);
        } else if (methodType == MethodType.ON_OPEN &&
                type.equals(EndpointConfig.class)) {
            result[i] = new PojoPathParam(type, null);
        } else if (methodType == MethodType.ON_ERROR
                && type.equals(Throwable.class)) {
            foundThrowable = true;
            result[i] = new PojoPathParam(type, null);
        } else if (methodType == MethodType.ON_CLOSE &&
                type.equals(CloseReason.class)) {
            result[i] = new PojoPathParam(type, null);
        } else {
            Annotation[] paramAnnotations = paramsAnnotations[i];
            for (Annotation paramAnnotation : paramAnnotations) {
                if (paramAnnotation.annotationType().equals(
                        PathParam.class)) {
                    // Check that the type is valid. "0" coerces to every
                    // valid type
                    try {
                        Util.coerceToType(type, "0");
                    } catch (IllegalArgumentException iae) {
                        throw new DeploymentException(sm.getString(
                                "pojoMethodMapping.invalidPathParamType"),
                                iae);
                    }
                    result[i] = new PojoPathParam(type,
                            ((PathParam) paramAnnotation).value());
                    break;
                }
            }
            // Parameters without annotations are not permitted
            if (result[i] == null) {
                throw new DeploymentException(sm.getString(
                        "pojoMethodMapping.paramWithoutAnnotation",
                        type, m.getName(), m.getClass().getName()));
            }
        }
    }
    if (methodType == MethodType.ON_ERROR && !foundThrowable) {
        throw new DeploymentException(sm.getString(
                "pojoMethodMapping.onErrorNoThrowable",
                m.getName(), m.getDeclaringClass().getName()));
    }
    return result;
}
项目:tomcat7    文件:TestWsSubprotocols.java   
@OnOpen
public void processOpen(@SuppressWarnings("unused") Session session,
        EndpointConfig  epc) {
    subprotocols = ((ServerEndpointConfig)epc).getSubprotocols();
}