本文整理匯總了Java中org.springframework.web.socket.WebSocketSession.close方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketSession.close方法的具體用法?Java WebSocketSession.close怎麽用?Java WebSocketSession.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.socket.WebSocketSession
的用法示例。
在下文中一共展示了WebSocketSession.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
super.handleTextMessage(session, message);
try {
getClient(session,null);
if (this.terminalClient != null ) {
if ( !terminalClient.isClosed()) {
terminalClient.write(message.getPayload());
}else {
session.close();
}
}
} catch (Exception e) {
session.sendMessage(new TextMessage("Sorry! opencron Terminal was closed, please try again. "));
terminalClient.disconnect();
session.close();
}
}
示例2: close
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
public void close(WebSocketSession webSocketSession) {
Replicator replicator = replicatorMap.remove(webSocketSession.getId());
if (replicator != null) {
try {
replicator.close();
webSocketSession.close();
} catch (IOException e) {
logger.warn(e.getMessage());
}
}
RxClient rxClient = rxClientMap.get(webSocketSession.getId());
if (rxClient != null) {
rxClient.shutdown();
}
observableMap.remove(webSocketSession.getId());
authMap.remove(webSocketSession.getId());
}
示例3: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
try {
log.info("[{}] Processing {}", session.getId(), message);
SessionMetaData sessionMd = internalSessionMap.get(session.getId());
if (sessionMd != null) {
actorService.process(new TextPluginWebSocketMsg(sessionMd.sessionRef, message.getPayload()));
} else {
log.warn("[{}] Failed to find session", session.getId());
session.close(CloseStatus.SERVER_ERROR.withReason("Session not found!"));
}
session.sendMessage(message);
} catch (IOException e) {
log.warn("IO error", e);
}
}
示例4: process
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void process() {
BlockchainWebSocketHandler handler = new BlockchainWebSocketHandler();
WebSocketClient client = new StandardWebSocketClient();
try {
WebSocketSession session = client.doHandshake(handler, WS_URI).get();
session.sendMessage(new TextMessage("Hello World test."));
session.close();
} catch (Exception e) {
logger.info(e);
}
}
示例5: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {
if(webSocketSession.isOpen()){
webSocketSession.close();
}
logger.info("connenction error,close the connection...");
users.remove(webSocketSession);
}
示例6: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {
users.remove(webSocketSession);
// server.getLongActionManager().cancelLongActionByWebSocketSessionRelated(webSocketSession);
if(webSocketSession.isOpen()){
webSocketSession.close();
}
logger.info("connenction error,close the connection...");
}
示例7: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {
users.remove(webSocketSession);
// server.getLongActionManager().cancelLongActionByWebSocketSessionRelated(webSocketSession);
if (webSocketSession.isOpen()) {
webSocketSession.close();
}
logger.info("connenction error,close the connection...");
}
示例8: afterConnectionEstablished
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
super.afterConnectionEstablished(session);
String sshSessionId = (String) session.getAttributes().get(SSH_SESSION_ID);
if (sshSessionId != null) {
final Terminal terminal = TerminalContext.remove(sshSessionId);
if (terminal!=null) {
try {
session.sendMessage(new TextMessage("Welcome to opencron Terminal! Connect Starting."));
getClient(session,terminal);
int cols = Integer.parseInt(session.getAttributes().get("cols").toString());
int rows = Integer.parseInt(session.getAttributes().get("rows").toString());
int width = Integer.parseInt(session.getAttributes().get("width").toString());
int height = Integer.parseInt(session.getAttributes().get("height").toString());
terminalClient.openTerminal(cols,rows,width,height);
terminalService.login(terminal);
} catch (Exception e) {
if (e.getLocalizedMessage().replaceAll("\\s+", "").contentEquals("Operationtimedout")) {
session.sendMessage(new TextMessage("Sorry! Connect timed out, please try again. "));
} else {
session.sendMessage(new TextMessage("Sorry! Operation error, please try again. "));
}
terminalClient.disconnect();
session.close();
}
}else {
this.terminalClient.disconnect();
session.sendMessage(new TextMessage("Sorry! Connect failed, please try again. "));
session.close();
}
}
}
示例9: cleanSession
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
public static void cleanSession(String sessionId) throws IOException {
WebSocketSession browserSession = sessionsTable.get(sessionsTable);
if(browserSession != null){
browserSession.close(CloseStatus.NO_STATUS_CODE);
sessionsTable.remove(sessionId);
LOGGER.info("Session {} cleaned.", sessionId);
}
}
示例10: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession session, Throwable exception)
throws Exception {
session.close(CloseStatus.SERVER_ERROR);
logger.info("session closed: " + this);
}
示例11: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
super.handleTransportError(session, exception);
this.closeTerminal(session);
session.close();
}
示例12: handleMessageToClient
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
/**
* Handle WAMP messages going back out to WebSocket clients.
*/
@Override
public void handleMessageToClient(WebSocketSession session, Message<?> message) {
if (!(message instanceof WampMessage)) {
logger.error("Expected WampMessage. Ignoring " + message + ".");
return;
}
WampMessage wampMessage = (WampMessage) message;
JsonFactory useFactory = this.jsonFactory;
boolean isBinary = false;
String acceptedProtocol = session.getAcceptedProtocol();
if (acceptedProtocol != null) {
if (acceptedProtocol.equals(WampSubProtocolHandler.MSGPACK_PROTOCOL)) {
isBinary = true;
useFactory = this.msgpackFactory;
}
else if (acceptedProtocol.equals(WampSubProtocolHandler.SMILE_PROTOCOL)) {
isBinary = true;
useFactory = this.smileFactory;
}
else if (acceptedProtocol.equals(WampSubProtocolHandler.CBOR_PROTOCOL)) {
isBinary = true;
useFactory = this.cborFactory;
}
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
JsonGenerator generator = useFactory.createGenerator(bos)) {
generator.writeStartArray();
wampMessage.serialize(generator);
generator.writeEndArray();
generator.close();
if (isBinary) {
session.sendMessage(new BinaryMessage(bos.toByteArray()));
}
else {
session.sendMessage(new TextMessage(bos.toByteArray()));
}
}
catch (Throwable ex) {
// Could be part of normal workflow (e.g. browser tab closed)
if (logger.isDebugEnabled()) {
logger.debug("Failed to send WebSocket message to client in session "
+ session.getId(), ex);
}
// Is this an outbound invocation message. In that case we need to feed
// back
// an error message
if (message instanceof InvocationMessage) {
ErrorMessage errorMessage = new ErrorMessage(
(InvocationMessage) message, WampError.NETWORK_FAILURE);
this.clientInboundChannel.send(errorMessage);
}
try {
session.close(CloseStatus.PROTOCOL_ERROR);
}
catch (IOException e) {
// Ignore
}
}
}
else {
if (logger.isErrorEnabled()) {
logger.error(
"Failed to send WebSocket message to client because no accepted protocol "
+ session.getId());
}
}
}
示例13: handleTextMessage
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
protected void handleTextMessage(final WebSocketSession session, final TextMessage message) throws Exception {
RxClient rxClient = rxClientMap.get(session.getId());
if (rxClient == null) {
session.close();
return;
}
final String command = message.getPayload();
if (command.equalsIgnoreCase("sync")) {
sync(session);
} else {
String auth = authMap.get(session.getId());
observableMap.get(session.getId())
.subscribe(connection -> {
if (auth != null) {
connection.writeAndFlush("auth " + auth + "\r\n" + command + "\r\n");
} else {
connection.writeAndFlush(command + "\r\n");
}
connection.getInput()
.distinct()
.subscribe(response -> {
String requestMessage;
if (response instanceof DefaultLastBulkStringRedisContent) {
DefaultLastBulkStringRedisContent content = (DefaultLastBulkStringRedisContent) response;
byte[] bytes = new byte[content.content().readableBytes()];
content.content().readBytes(bytes);
requestMessage = new String(bytes);
} else if (response instanceof IntegerRedisMessage) {
requestMessage = String.valueOf(((IntegerRedisMessage) response).value());
} else if (response instanceof ErrorRedisMessage) {
requestMessage = ((ErrorRedisMessage) response).content();
} else if (response instanceof FullBulkStringRedisMessage) {
requestMessage = "nil";
} else if (response instanceof SimpleStringRedisMessage) {
requestMessage = ((SimpleStringRedisMessage) response).content();
} else if (response instanceof BulkStringHeaderRedisMessage || response instanceof DefaultBulkStringRedisContent || response instanceof ArrayHeaderRedisMessage) {
return;
} else {
requestMessage = response.toString();
}
try {
session.sendMessage(new TextMessage(requestMessage));
} catch (IOException e) {
logger.warn(e.getMessage());
}
});
});
}
}
示例14: handleTransportError
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
WebSocketSessionsTable.cleanSession("2");
session.close(CloseStatus.SERVER_ERROR);
LOGGER.info("...BrowserHandler connection {} closed for transportError.", session.getId());
}
示例15: afterConnectionClosed
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
WebSocketSessionsTable.cleanSession("2");
session.close(CloseStatus.NORMAL);
LOGGER.info("...BrowserHandler connection {} closed.", session.getId());
}