title: How to send messages of offline user after getting online in java websocket?
body: <p>I am trying to write a chat using webcocket, for offline users I have used java Queue, If user is offline I keep messages in a Queue and when user gets online I check if Queue is empty and if it's not, using a loop i remove each messages from Queue. The problem is it just sends last message to user even though all messages are in queue,
  here is my onOpen method:</p>
  
  <pre><code>@ServerEndpoint(value = "/chat/{room}/{user}", encoders = ChatMessageEncoder.class, decoders = ChatMessageDecoder.class)
   public class ChatEndpoint {
  
  
  private final Logger log = Logger.getLogger(getClass().getName());
  private static final Map&lt;String, Queue&lt;ChatMessage&gt;&gt; userMessageBuffer = new HashMap&lt;&gt;();
  
  @OnOpen
  public void open(final Session session,
          @PathParam("room") final String room,
          @PathParam("user") final String userId) {
  
      log.info("session openend and bound to room: " + room);
      // session.getUserProperties().put("room", room);
      session.getUserProperties().put("user", userId);
  
      Queue&lt;ChatMessage&gt; userMsgs = userMessageBuffer.get(userId);
      ChatMessage sendChat = new ChatMessage();
  
      if (userMsgs != null &amp;&amp; !userMsgs.isEmpty()) {
  
          for (int i = 0; i &lt; userMsgs.size(); i++) {
  
              sendChat = userMsgs.remove();
              System.out.println("size!!!!!! " + sendChat.getMessage());
              try {
  
                      session.getBasicRemote().sendObject(sendChat);
  
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (EncodeException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          }
      }
  
  }}
  </code></pre>
  
  <p>Does any one knows where is the problem?</p>