View Javadoc
1   /*-
2    * #%L
3    * Spring Stomp Server
4    * ===============================================================
5    * Copyright (C) 2020 Brabenetz Harald, Austria
6    * ===============================================================
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package net.brabenetz.app.springstompserver.testtools;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.springframework.lang.Nullable;
25  import org.springframework.messaging.simp.stomp.StompCommand;
26  import org.springframework.messaging.simp.stomp.StompHeaders;
27  import org.springframework.messaging.simp.stomp.StompSession;
28  import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
29  
30  public class WebSocketStompSessionHandler extends StompSessionHandlerAdapter {
31  
32      private static final Logger LOG = LoggerFactory.getLogger(WebSocketStompSessionHandler.class);
33  
34      private String name;
35  
36      public WebSocketStompSessionHandler(String name) {
37          this.name = name;
38      }
39  
40      @Override
41      public void afterConnected(StompSession stompSession, StompHeaders connectedHeaders) {
42          LOG.info(name + " afterConnected: " + stompSession.getSessionId());
43      }
44  
45      @Override
46      public void handleFrame(StompHeaders headers, Object payload) {
47          LOG.info(name + " StompSessionHandler got new Payload: " + payload);
48      }
49  
50      @Override
51      public void handleException(StompSession stompSession, @Nullable StompCommand command,
52              StompHeaders headers, byte[] payload, Throwable e) {
53          LOG.error(name + " handleException {}", e.getMessage(), e);
54      }
55  
56      @Override
57      public void handleTransportError(StompSession stompSession, Throwable e) {
58          LOG.error(name + " handleTransportError {}", e.getMessage(), e);
59      }
60  
61  
62  }