001/*002 * Copyright 2002-2017 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.messaging.simp.stomp;018019import org.springframework.lang.Nullable;020021/**022 * A contract for client STOMP session lifecycle events including a callback023 * when the session is established and notifications of transport or message024 * handling failures.025 *026 * <p>This contract also extends {@link StompFrameHandler} in order to handle027 * STOMP ERROR frames received from the broker.028 *029 * <p>Implementations of this interface should consider extending030 * {@link StompSessionHandlerAdapter}.031 *032 * @author Rossen Stoyanchev033 * @since 4.2034 * @see StompSessionHandlerAdapter035 */036public interface StompSessionHandler extends StompFrameHandler {037038 /**039 * Invoked when the session is ready to use, i.e. after the underlying040 * transport (TCP, WebSocket) is connected and a STOMP CONNECTED frame is041 * received from the broker.042 * @param session the client STOMP session043 * @param connectedHeaders the STOMP CONNECTED frame headers044 */045 void afterConnected(StompSession session, StompHeaders connectedHeaders);046047 /**048 * Handle any exception arising while processing a STOMP frame such as a049 * failure to convert the payload or an unhandled exception in the050 * application {@code StompFrameHandler}.051 * @param session the client STOMP session052 * @param command the STOMP command of the frame053 * @param headers the headers054 * @param payload the raw payload055 * @param exception the exception056 */057 void handleException(StompSession session, @Nullable StompCommand command,058 StompHeaders headers, byte[] payload, Throwable exception);059060 /**061 * Handle a low level transport error which could be an I/O error or a062 * failure to encode or decode a STOMP message.063 * <p>Note that064 * {@link org.springframework.messaging.simp.stomp.ConnectionLostException065 * ConnectionLostException} will be passed into this method when the066 * connection is lost rather than closed normally via067 * {@link StompSession#disconnect()}.068 * @param session the client STOMP session069 * @param exception the exception that occurred070 */071 void handleTransportError(StompSession session, Throwable exception);072073}