本文整理汇总了Java中org.springframework.web.socket.TextMessage.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Java TextMessage.getPayload方法的具体用法?Java TextMessage.getPayload怎么用?Java TextMessage.getPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.socket.TextMessage
的用法示例。
在下文中一共展示了TextMessage.getPayload方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws IOException {
String country = message.getPayload();
String reply="No data available";
if(country.equals("India"))
{
reply="DELHI";
}
else if(country.equals("USA"))
{
reply="Washington,D.C";
}
System.out.println("handling message");
for(WebSocketSession webSsession:sessions)
{
session.sendMessage(new TextMessage(reply));
}
}
示例2: handleMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
public void handleMessage(TextMessage message, WebSocketSession wsSession) throws Exception {
String payload = message.getPayload();
if (StringUtils.isEmpty(payload)) {
return;
}
String[] messages;
try {
messages = getSockJsServiceConfig().getMessageCodec().decode(payload);
}
catch (Throwable ex) {
logger.error("Broken data received. Terminating WebSocket connection abruptly", ex);
tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA);
return;
}
delegateMessages(messages);
}
示例3: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message)
throws Exception {
String payload = message.getPayload();
if ("west".equals(payload)) {
this.snake.setDirection(Direction.WEST);
}
else if ("north".equals(payload)) {
this.snake.setDirection(Direction.NORTH);
}
else if ("east".equals(payload)) {
this.snake.setDirection(Direction.EAST);
}
else if ("south".equals(payload)) {
this.snake.setDirection(Direction.SOUTH);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SnakeWebSocketHandler.java
示例4: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String logItem = message.getPayload();
if (logItem.length() < MIN_LENGTH_LOG) {
return;
}
// parse log item "category#index#zone#agent#cmdId#content" and send to event "zone:agent"
int categoryIndex = logItem.indexOf('#', 0);
String category = logItem.substring(0, categoryIndex);
int numberIndex = logItem.indexOf('#', categoryIndex + 1);
String number = logItem.substring(categoryIndex + 1, numberIndex);
int zoneIndex = logItem.indexOf('#', numberIndex + 1);
String zone = logItem.substring(numberIndex + 1, zoneIndex);
int agentIndex = logItem.indexOf('#', zoneIndex + 1);
String agent = logItem.substring(zoneIndex + 1, agentIndex);
int cmdIdIndex = logItem.indexOf('#', agentIndex + 1);
String cmdId = logItem.substring(agentIndex + 1, cmdIdIndex);
String content = logItem.substring(cmdIdIndex + 1);
if (category.equals(CmdType.RUN_SHELL.toString())) {
sendCmdLog(cmdId, content, number);
return;
}
if (category.equals(CmdType.SYSTEM_INFO.toString())) {
sendAgentSysInfo(content);
}
}
示例5: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
private void handleTextMessage(WebSocketSession session, TextMessage webSocketMessage) throws Exception {
String incomingString = webSocketMessage.getPayload();
String chargeBoxId = getChargeBoxId(session);
log.info("[chargeBoxId={}, sessionId={}] Received message: {}", chargeBoxId, session.getId(), incomingString);
CommunicationContext context = new CommunicationContext();
context.setSession(session);
context.setChargeBoxId(chargeBoxId);
context.setIncomingString(incomingString);
pipeline.process(context);
}
示例6: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String json = message.getPayload();
T t = JSON.parseObject(json, clazz);
onMessage(session, t);
}
示例7: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的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());
}
});
});
}
}
示例8: executeSendRequestInternal
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
public ResponseEntity<String> executeSendRequestInternal(URI url, HttpHeaders headers, TextMessage message) {
RequestCallback requestCallback = new XhrRequestCallback(headers, message.getPayload());
return this.restTemplate.execute(url, HttpMethod.POST, requestCallback, textResponseExtractor);
}
示例9: handleTextMessage
import org.springframework.web.socket.TextMessage; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
// TODO Auto-generated method stub
super.handleTextMessage(session, message);
message.getPayload();
}