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


Java SendTo類代碼示例

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


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

示例1: sendMessageToAllUsers

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
/**
 * Send the given message to all users after checking the authorization of the user.
 * @param message The message to be sent.
 * @param accessToken The oauth2 accessToken of the user.
 * @return the message to the topic
 * @throws Exception Thrown if not authorized for instance.
 */
@MessageMapping("/user-messages")
@SendTo("/topic/user-messages")
public MessageDto sendMessageToAllUsers(MessageDto message, 
    @Header("access_token") String accessToken) throws Exception {
  OAuth2AccessToken oauth2accessToken = tokenStore.readAccessToken(accessToken);
  if (oauth2accessToken != null) {
    OAuth2Authentication authentication = tokenStore.readAuthentication(oauth2accessToken);
    if (authentication != null && authentication.getAuthorities().contains(
        new SimpleGrantedAuthority("ROLE_ADMIN"))) {
      message.setSender(authentication.getUserAuthentication().getName());
      log.debug("Sending message from {} to all users", message.getSender()); 
      return message;        
    }
  }
  log.error("Unauthorized message from {} with content: {}", 
      message.getSender(), message.getText());
  throw new SessionAuthenticationException("No valid access token found!");
}
 
開發者ID:dzhw,項目名稱:metadatamanagement,代碼行數:26,代碼來源:UserMessagesController.java

示例2: echo

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@JmsListener(destination = "testQueue")
@SendTo("anotherQueue")
public Message<String> echo(String input, JmsMessageHeaderAccessor headerAccessor) {
	logger.info("Sending back: " + input + " (messageId=" + headerAccessor.getMessageId() + ")");
	return MessageBuilder.withPayload(input)
			.setHeader("myCustomHeader", "foo")
			.setHeader(JmsHeaders.TYPE, "myJmsType")
			.build();
}
 
開發者ID:snicoll,項目名稱:scratches,代碼行數:10,代碼來源:DemoService.java

示例3: logoutput

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
/**
 * Gets logs.
 *
 * @return the log output
 * @throws Exception the exception
 */

@SendTo("/logs/logoutput")
public String logoutput() throws Exception {
    synchronized (LOCK) {
        final String log = LOG_OUTPUT.toString();
        LOG_OUTPUT = new StringBuilder();
        return log;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:16,代碼來源:LoggingOutputSocketMessagingController.java

示例4: say

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/welcome")//
@SendTo("/topic/getResponse")//
public BroserResponse say(MyMessage message) throws Exception{
    Thread.sleep(3000);
    System.out.println(message.getName());
    return new BroserResponse("Welcome," + message.getName()+"!");
}
 
開發者ID:shuaishuaila,項目名稱:java_springboot,代碼行數:8,代碼來源:BMController.java

示例5: sendActivity

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(SecurityUtils.getCurrentUserLogin());
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    Instant instant = Instant.ofEpochMilli(Calendar.getInstance().getTimeInMillis());
    activityDTO.setTime(dateTimeFormatter.format(ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault())));
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:13,代碼來源:ActivityService.java

示例6: scoringNegative

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@StreamListener(CreditDecisionChannels.SCORING_NEGATIVE)
@SendTo(CreditDecisionChannels.APPLICATION_DECLINED_OUT)
public ApplicationDeclinedEvent scoringNegative(ScoringPerformedEvent event) {
	DecisionMemo decisionMemo = loadOrCreateDecisionMemo(event.getApplicationNumber());
	decisionMemo.setScoredPositive(false);
	decisionMemo.setApproved(false);
	decisionMemo.setLastUpdate(new Date());
	decisionMemoRepository.save(decisionMemo);
	return new ApplicationDeclinedEvent(event.getApplicationNumber(), "Scoring negative, auto declined");
}
 
開發者ID:mploed,項目名稱:event-driven-spring-boot,代碼行數:11,代碼來源:IncomingMessageListener.java

示例7: sendActivity

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    activityDTO.setTime(Instant.now());
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:11,代碼來源:ActivityService.java

示例8: send

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/chat")
@SendTo("/topic/messages")
public OutputMessage send(Message message) throws Exception {
    if(message.getFrom().toLowerCase().equals("mis bot") || message.getFrom().toLowerCase().equals("server")) {
        throw new Exception("Illegal sender username");
    }
    String time = new SimpleDateFormat("HH:mm").format(new Date());
    OutputMessage om = new OutputMessage(message.getFrom(), message.getText(), time);
    if(!om.getFrom().equals("Alert") && !om.getFrom().equals("MIS Bot") && !om.text.trim().equals("")) MongoDBInterface.addCollection(om);
    return new OutputMessage(message.getFrom(), message.getText(), time);
}
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:12,代碼來源:WebSocketController.java

示例9: getFeedback

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/chat_feedback")
@SendTo("/topic/messages")
public OutputMessage getFeedback(Message message) throws Exception {
    String time = new SimpleDateFormat("HH:mm").format(new Date());
    if(message.getText().trim().startsWith("!feedback ")) {
        String s = message.getText().substring(message.getText().indexOf(" "));
        RabbitSend.sendFeedback(message.getFrom(),s);
        Thread.sleep(1000);
        return new OutputMessage("MIS Bot","Thank you for your feedback :)",time);
    }
    else {
        Thread.sleep(1000);
        return new OutputMessage("MIS Bot","You can't leave a feedback without text :(",time);
        }
    }
 
開發者ID:LithiumSR,項目名稱:media_information_service,代碼行數:16,代碼來源:WebSocketController.java

示例10: showOffer

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/book")
@SendTo("/topic/showOffer")
public Result showOffer(MyBook myBook) throws Exception {
	System.out.println(myBook.getBookName());

	Result result = new Result();
	result.getOffer(myBook.getBookName());
	return result;
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-5.0,代碼行數:10,代碼來源:WebSocketController.java

示例11: createMesage

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/chat/{conversationId}")
@SendTo("/topic/chat/{conversationId}")
public ConversationMessage createMesage(
        @Payload CreateMessage message,
        @DestinationVariable String conversationId) {

    log.info("handleMessage {}", message);
    
    
    ConversationMessage conversationMessage = conversationService.create( message );
    if(conversationMessage.isUserMessage()){
        publisher.publishEvent(new UserMessageCreatedEvent(conversationMessage));
    }
    return conversationMessage;
}
 
開發者ID:peterjurkovic,項目名稱:travel-agency,代碼行數:16,代碼來源:ConversationController.java

示例12: send

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@MessageMapping("/chat/{topic}")
   @SendTo("/topic/messages")
   public OutputMessage send(@DestinationVariable("topic") String topic,
		      Message message) throws Exception
   {
return new OutputMessage(message.getFrom(), message.getText(), topic);
   }
 
開發者ID:jaysridhar,項目名稱:spring-websocket-server,代碼行數:8,代碼來源:ChatController.java

示例13: supportsReturnType

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	if (returnType.getMethodAnnotation(SendTo.class) != null ||
			returnType.getMethodAnnotation(SendToUser.class) != null) {
		return true;
	}
	return (!this.annotationRequired);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:9,代碼來源:SendToMethodReturnValueHandler.java

示例14: handleAndSendToJsonView

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
@SendTo("/dest")
@JsonView(MyJacksonView1.class)
public JacksonViewBean handleAndSendToJsonView() {
	JacksonViewBean payload = new JacksonViewBean();
	payload.setWithView1("with");
	payload.setWithView2("with");
	payload.setWithoutView("without");
	return payload;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:SendToMethodReturnValueHandlerTests.java

示例15: getDefaultResponseDestination

import org.springframework.messaging.handler.annotation.SendTo; //導入依賴的package包/類
/**
 * Return the default response destination, if any.
 */
protected String getDefaultResponseDestination() {
	Method specificMethod = getMostSpecificMethod();
	SendTo ann = AnnotationUtils.getAnnotation(specificMethod, SendTo.class);
	if (ann != null) {
		Object[] destinations = ann.value();
		if (destinations.length != 1) {
			throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" +
					specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
		}
		return resolve((String) destinations[0]);
	}
	return null;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:MethodJmsListenerEndpoint.java


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