In SimpMessageHeaderAccessor it cannot find the function getSessionAttributes().

I was using this code block. But the getSessionAttributes() was showing error. I used library "spring-messaging.jar-4.0.0 Release". I found on their website that this function exists in this class. But the library I've used doesn't contain this class. How can this be solved? I cannot update the class file and add the function!

 

@MessageMapping("/chat.addUser")
@SendTo("/topic/public")
public ChatMessage addUser(@Payload ChatMessage chatMessage,
                           SimpMessageHeaderAccessor headerAccessor) {
    // Add username in web socket session
    headerAccessor.getSessionAttributes().put("username", chatMessage.getSender());
    return chatMessage;
}

  Topic Computer Software & Hardware Subtopic Networking (deprecated and moved to "Internet Connectivity") Tags java networking websocket
3 Years 1 Answer 1.9k views

S.M. Raihanul Alam Hridoy

Reputation Score: 28

Submit An Answer

Answers ( 1 )

 
  1. Atik Shakil 45 Accepted Answer Community Answer

    You can use Spring Messaging version 4.1.6 in your pom.xML file. Hopefully it will be okay.


    <!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>4.1.6</version>
    </dependency>

    You will find all versions here

    https://mvnrepository.com/artifact/org.springframework/spring-messaging

    UTC 2021-02-01 03:14 AM 1 Comment

To answer this question, you must be logged in.

Create an account

Already have an account? Login.

By Signing up, you indicate that you have read and agree to Sage's Terms and Conditions and Privacy Policy