當前位置: 首頁>>代碼示例>>Java>>正文


Java PathParam類代碼示例

本文整理匯總了Java中javax.websocket.server.PathParam的典型用法代碼示例。如果您正苦於以下問題:Java PathParam類的具體用法?Java PathParam怎麽用?Java PathParam使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PathParam類屬於javax.websocket.server包,在下文中一共展示了PathParam類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onOpen

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
    UUID key = UUID.fromString(uuid);
    peers.put(key, session);
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (StatusEventType statusEventType : StatusEventType.values()) {
        JsonObjectBuilder object = Json.createObjectBuilder();
        builder.add(object.add(statusEventType.name(), statusEventType.getMessage()).build());
    }

    RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
    asyncRemote.sendText(builder.build().toString());
    // Send pending messages
    List<String> messages = messageBuffer.remove(key);
    if (messages != null) {
        messages.forEach(asyncRemote::sendText);
    }
}
 
開發者ID:fabric8-launcher,項目名稱:launcher-backend,代碼行數:19,代碼來源:MissionControlStatusEndpoint.java

示例2: onMessage

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnMessage
public void onMessage(Session session, String message, @PathParam("id") Long id, @PathParam("nickname") String nickname) {
    LOGGER.info("Received message: " + message + " from " + nickname + " and channel n°" + id);
    JsonObject json = GsonSingleton.getInstance().fromJson(message, JsonObject.class);
    if (json != null) {
        String content = json.get(JSON_KEY_CONTENT).getAsString();
        Long channelId = json.get(JSON_KEY_CHANNEL_ID).getAsLong();
        Long userId = json.get(JSON_KEY_USER_ID).getAsLong();

        Message mess = new Message.Builder()
                .setContent(content)
                .setChannelId(channelId)
                .setNickname(nickname)
                .setUserId(userId)
                .build();

        try (Connection c = DatabaseManager.getConnection()) {
            MessageDAO messageDAO = new MessageDAO(c);
            if (messageDAO.create(mess))
                manager.broadcast(id, mess, From.Type.CLIENT);
        } catch (SQLException | InsertionException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:YMonnier,項目名稱:docker-restful-java,代碼行數:26,代碼來源:ChannelEndPoint.java

示例3: closedConnection

import javax.websocket.server.PathParam; //導入依賴的package包/類
/**
 * Close the connection and decrement the number of writers and send a
 * message to notify all others writers.
 * 
 * @param session
 *            peer session
 * @param adocId
 *            unique id for this asciidoc file
 */
@OnClose
public void closedConnection(Session session,
							 @PathParam("projectId") String adocId) {
	if (session.getUserProperties().containsKey("writer")) {
		handleWriters(adocId, false, (String) session.getUserProperties()
				.get("writer"));
	} else {
		handleReaders(adocId, false);
	}

	peers.remove(session);
	logger.log(Level.INFO, "Connection closed for " + session.getId());
	// send a message to all peers to inform that someone is disonnected
	sendNotificationMessage(createNotification(adocId), adocId);
}
 
開發者ID:adoc-editor,項目名稱:editor-backend,代碼行數:25,代碼來源:RealtimeEndpoint.java

示例4: open

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void open(@PathParam("gametype") String gameID, Session session) throws IOException {
	type = GameType.getGameType(gameID);
	if(type == null) {
		session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, "Invalid game type"));
		return;
	}
	
	Basic sender = session.getBasicRemote();
	
	viewer = data -> {
			synchronized(session) {
				if(session.isOpen())
					try { sender.sendBinary(data); } catch (IOException e) {}
			}
	};
	
	DisplayHandler.addGlobalViewer(viewer);
}
 
開發者ID:Brownshome,項目名稱:script-wars,代碼行數:20,代碼來源:GameViewerSocket.java

示例5: userConnectedCallback

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void userConnectedCallback(@PathParam("user") String user, Session s) {
    if (USERS.contains(user)) {
        try {
            dupUserDetected = true;
            s.getBasicRemote().sendText("Username " + user + " has been taken. Retry with a different name");
            s.close();
            return;
        } catch (IOException ex) {
            Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    this.s = s;
    s.getUserProperties().put("user", user);
    this.user = user;
    USERS.add(user);

    welcomeNewJoinee();
    announceNewJoinee();
}
 
開發者ID:abhirockzz,項目名稱:websocket-chat,代碼行數:22,代碼來源:ChatServer.java

示例6: userConnectedCallback

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void userConnectedCallback(@PathParam("user") String user, Session s) {

    if (USERS.contains(user)) {
        try {
            dupUserDetected = true;
            s.getBasicRemote().sendObject(new DuplicateUserNotification(user));
            s.close();
            return;
        } catch (Exception ex) {
            Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    this.s = s;
    SESSIONS.add(s);
    s.getUserProperties().put("user", user);
    this.user = user;
    USERS.add(user);

    welcomeNewJoinee();
    announceNewJoinee();
}
 
開發者ID:abhirockzz,項目名稱:scalable-websocket-chat-with-hazelcast,代碼行數:25,代碼來源:ChatServer.java

示例7: onWebSocketText

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnMessage
public void onWebSocketText(final Session sess, final JSONRPC2Message msg, @PathParam(CCOWContextListener.PATH_NAME) final String applicationName) {
	if (msg instanceof JSONRPC2Request) {
		//All operations that are invokable on ContextManager that does not return void
		logger.debug("The message is a Request");
	}
	else if (msg instanceof JSONRPC2Notification) {
		//All operations that are invokable on ContextManager that does return void
		logger.debug("The message is a Notification");
	}
	else if (msg instanceof JSONRPC2Response) {
		//All operations that are invokable from ContextManager that does not return void and are initially called from ContextManager
		participant.onMessage((JSONRPC2Response) msg);
		logger.debug("The message is a Response");
	}
}
 
開發者ID:jkiddo,項目名稱:ccow,代碼行數:17,代碼來源:SubscriptionEndpoint.java

示例8: requestEventTracking

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnMessage
public void requestEventTracking(@PathParam("trackingPin") String trackingPin, String message, Session session) {
    myLog.debug("requestEventTracking: " + trackingPin);
    try {
        if (session.isOpen()) {
            SecqMeEventVO eventVO = eventManager.getEventByTrackingPin(trackingPin);
            FullEventInfoVO eventInfoVO = eventManager.getFullEventInfoOfContact(eventVO.getId());
            session.getBasicRemote().sendText(eventInfoVO.toJSON().toString());
        }
    } catch (IOException ex) {
        myLog.error("Tracking event web socket error: " + trackingPin, ex);
        try {
            session.close();
        } catch (IOException ex1) {
            // Ignore
        }
    }
}
 
開發者ID:SECQME,項目名稱:watchoverme-server,代碼行數:19,代碼來源:EventEndpoint.java

示例9: openSocket

import javax.websocket.server.PathParam; //導入依賴的package包/類
/**
 * Open a socket connection to a client from the web server
 *
 * @param session The session that just opened
 */
@OnOpen
public void openSocket(@PathParam(RT_COMPUTE_ENDPOINT_PARAM) ConnectionType type,
                       Session session) {
    session.setMaxIdleTimeout(0);
    String sessionId = session.getId();
    if (type == ConnectionType.SUBSCRIBER) {
        LOG.info("Got a new subscriber connection request with ID {}. Saving session", sessionId);
        // cleanup sessions
        Set<Session> closedSessions = Sets.newHashSet();
        for (Session existingSession : sessions) {
            if (!existingSession.isOpen()) {
                closedSessions.add(existingSession);
            }
        }
        sessions.removeAll(closedSessions);

        sessions.add(session);
        LOG.info("Active sessions {}. Collecting {} sessions",
                 sessions.size(), closedSessions.size());

    } else {
        LOG.info("Got a new publisher connection request with ID {}", sessionId);
    }
}
 
開發者ID:OpenChatAlytics,項目名稱:OpenChatAlytics,代碼行數:30,代碼來源:RealtimeResource.java

示例10: onOpen

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void onOpen(Session session,@PathParam("username") String username) {
	try{
		client.add(session);
		user.put(URLEncoder.encode(username, "UTF-8"),URLEncoder.encode(username, "UTF-8"));
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		//獲得在線用戶列表
		Set<String> key = user.keySet();
		for (String u : key) {
			ja.add(u);
		}
		jo.put("onlineUser", ja);
		session.getBasicRemote().sendText(jo.toString());
	}catch(Exception e){
		//do nothing
	}
}
 
開發者ID:tank2140896,項目名稱:JavaWeb,代碼行數:19,代碼來源:ChartController.java

示例11: onOpen

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
    UUID key = UUID.fromString(uuid);
    peers.put(key, session);
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (StatusMessage statusMessage : StatusMessage.values()) {
        JsonObjectBuilder object = Json.createObjectBuilder();
        builder.add(object.add(statusMessage.name(), statusMessage.getMessage()).build());
    }

    RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
    asyncRemote.sendText(builder.build().toString());
    // Send pending messages
    List<String> messages = messageBuffer.remove(key);
    if (messages != null) {
        messages.forEach(asyncRemote::sendText);
    }
}
 
開發者ID:fabric8-launcher,項目名稱:launchpad-missioncontrol,代碼行數:19,代碼來源:MissionControlStatusEndpoint.java

示例12: message

import javax.websocket.server.PathParam; //導入依賴的package包/類
@OnMessage
public void message(final Session session, BetMessage msg,  @PathParam("match-id") String matchId) {
    logger.log(Level.INFO, "Received: Bet Match Winner - {0}", msg.getWinner());
    //check if the user had already bet and save this bet
    boolean hasAlreadyBet = session.getUserProperties().containsKey("bet");
    session.getUserProperties().put("bet", msg.getWinner());
    
    //Send betMsg with bet count
    if (!nbBetsByMatch.containsKey(matchId)){
    	nbBetsByMatch.put(matchId, new AtomicInteger());
    }
    if (!hasAlreadyBet){
    	nbBetsByMatch.get(matchId).incrementAndGet();
    }
    sendBetMessages(null, matchId, false);
}
 
開發者ID:mgreau,項目名稱:docker4dev-tennistour-app,代碼行數:17,代碼來源:MatchEndpoint.java

示例13: validateOnOpenMethod

import javax.websocket.server.PathParam; //導入依賴的package包/類
private boolean validateOnOpenMethod(Object webSocketEndpoint)
        throws WebSocketMethodParameterException, WebSocketEndpointMethodReturnTypeException {
    EndpointDispatcher dispatcher = new EndpointDispatcher();
    Method method;
    if (dispatcher.getOnOpenMethod(webSocketEndpoint).isPresent()) {
        method = dispatcher.getOnOpenMethod(webSocketEndpoint).get();
    } else {
        return true;
    }
    validateReturnType(method);
    for (Parameter parameter: method.getParameters()) {
        Class<?> paraType = parameter.getType();
        if (paraType == String.class) {
            if (parameter.getAnnotation(PathParam.class) == null) {
                throw new WebSocketMethodParameterException("Invalid parameter found on open message method: " +
                                                                    "string parameter without " +
                                                                    "@PathParam annotation.");
            }
        } else if (paraType != Session.class) {
            throw new WebSocketMethodParameterException("Invalid parameter found on open message method: " +
                                                                paraType);
        }
    }
    return true;
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:26,代碼來源:EndpointValidator.java

示例14: validateOnCloseMethod

import javax.websocket.server.PathParam; //導入依賴的package包/類
private boolean validateOnCloseMethod(Object webSocketEndpoint)
        throws WebSocketMethodParameterException, WebSocketEndpointMethodReturnTypeException {
    EndpointDispatcher dispatcher = new EndpointDispatcher();
    Method method;
    if (dispatcher.getOnCloseMethod(webSocketEndpoint).isPresent()) {
        method = dispatcher.getOnCloseMethod(webSocketEndpoint).get();
    } else {
        return true;
    }
    validateReturnType(method);
    for (Parameter parameter: method.getParameters()) {
        Class<?> paraType = parameter.getType();
        if (paraType == String.class) {
            if (parameter.getAnnotation(PathParam.class) == null) {
                throw new WebSocketMethodParameterException("Invalid parameter found on close message method: " +
                                                                    "string parameter without " +
                                                                    "@PathParam annotation.");
            }
        } else if (paraType != CloseReason.class && paraType != Session.class) {
            throw new WebSocketMethodParameterException("Invalid parameter found on close message method: " +
                                                                paraType);
        }
    }
    return true;
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:26,代碼來源:EndpointValidator.java

示例15: getOnStringMessageMethod

import javax.websocket.server.PathParam; //導入依賴的package包/類
/**
 * Extract OnMessage method for String from the endpoint if exists.
 *
 * @param webSocketEndpoint Endpoint to extract method.
 * @return method optional to handle String messages.
 */
public Optional<Method> getOnStringMessageMethod(Object webSocketEndpoint) {
    Method[] methods = webSocketEndpoint.getClass().getMethods();
    Method returnMethod = null;
    for (Method method : methods) {
        if (method.isAnnotationPresent(OnMessage.class)) {
            Parameter[] parameters = method.getParameters();
            for (Parameter parameter: parameters) {
                if (!parameter.isAnnotationPresent(PathParam.class) &&
                        parameter.getType() == String.class) {
                    returnMethod = method;
                }

            }
        }
    }
    return Optional.ofNullable(returnMethod);
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:24,代碼來源:EndpointDispatcher.java


注:本文中的javax.websocket.server.PathParam類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。