001/* 002 * Copyright 2002-2015 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 at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * 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 and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.socket.messaging; 018 019import org.springframework.messaging.Message; 020 021/** 022 * A contract for handling sub-protocol errors sent to clients. 023 * 024 * @author Rossen Stoyanchev 025 * @since 4.2 026 */ 027public interface SubProtocolErrorHandler<P> { 028 029 /** 030 * Handle errors thrown while processing client messages providing an 031 * opportunity to prepare the error message or to prevent one from being sent. 032 * <p>Note that the STOMP protocol requires a server to close the connection 033 * after sending an ERROR frame. To prevent an ERROR frame from being sent, 034 * a handler could return {@code null} and send a notification message 035 * through the broker instead, e.g. via a user destination. 036 * @param clientMessage the client message related to the error, possibly 037 * {@code null} if error occurred while parsing a WebSocket message 038 * @param ex the cause for the error, never {@code null} 039 * @return the error message to send to the client, or {@code null} in which 040 * case no message will be sent. 041 */ 042 Message<P> handleClientMessageProcessingError(Message<P> clientMessage, Throwable ex); 043 044 /** 045 * Handle errors sent from the server side to clients, e.g. errors from the 046 * {@link org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler 047 * "broke relay"} because connectivity failed or the external broker sent an 048 * error message, etc. 049 * @param errorMessage the error message, never {@code null} 050 * @return the error message to send to the client, or {@code null} in which 051 * case no message will be sent. 052 */ 053 Message<P> handleErrorMessageToClient(Message<P> errorMessage); 054 055}