Add config option for StompSubProtocolErrorHandler
Issue: SPR-13142
This commit is contained in:
@@ -271,6 +271,12 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
|
||||
RootBeanDefinition stompHandlerDef = new RootBeanDefinition(StompSubProtocolHandler.class);
|
||||
registerBeanDef(stompHandlerDef, context, source);
|
||||
|
||||
Element errorHandlerElem = DomUtils.getChildElementByTagName(element, "stomp-error-handler");
|
||||
if (errorHandlerElem != null) {
|
||||
RuntimeBeanReference errorHandlerRef = new RuntimeBeanReference(errorHandlerElem.getAttribute("ref"));
|
||||
stompHandlerDef.getPropertyValues().add("errorHandler", errorHandlerRef);
|
||||
}
|
||||
|
||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||
cavs.addIndexedArgumentValue(0, inChannel);
|
||||
cavs.addIndexedArgumentValue(1, outChannel);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.web.socket.config.annotation;
|
||||
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
|
||||
|
||||
/**
|
||||
* A contract for registering STOMP over WebSocket endpoints.
|
||||
*
|
||||
@@ -29,4 +31,11 @@ public interface StompEndpointRegistry {
|
||||
*/
|
||||
StompWebSocketEndpointRegistration addEndpoint(String... paths);
|
||||
|
||||
/**
|
||||
* Configure a handler for customizing or handling STOMP ERROR frames to clients.
|
||||
* @param errorHandler the error handler
|
||||
* @since 4.2
|
||||
*/
|
||||
WebMvcStompEndpointRegistry setErrorHandler(StompSubProtocolErrorHandler errorHandler);
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerMapping;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
@@ -134,6 +135,12 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
|
||||
return this.urlPathHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebMvcStompEndpointRegistry setErrorHandler(StompSubProtocolErrorHandler errorHandler) {
|
||||
this.stompHandler.setErrorHandler(errorHandler);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a handler mapping with the mapped ViewControllers; or {@code null} in case of no registrations.
|
||||
*/
|
||||
|
||||
@@ -30,9 +30,9 @@ public interface SubProtocolErrorHandler<P> {
|
||||
* opportunity to prepare the error message or to prevent one from being sent.
|
||||
*
|
||||
* <p>Note that the STOMP protocol requires a server to close the connection
|
||||
* after sending an ERROR frame. To prevent that, a handler could return
|
||||
* {@code null} and send a message through the broker instead, e.g. via a
|
||||
* user destination targeting the user.
|
||||
* after sending an ERROR frame. To prevent an ERROR frame from being sent,
|
||||
* a handler could return {@code null} and send a notification message
|
||||
* through the broker instead, e.g. via a user destination.
|
||||
*
|
||||
* @param clientMessage the client message related to the error, possibly
|
||||
* {@code null} if error occurred while parsing a WebSocket message
|
||||
|
||||
@@ -727,6 +727,22 @@
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="stomp-error-handler" minOccurs="0">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Configures a StompSubProtocolErrorHandler to customize or handle STOMP ERROR to clients.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="ref" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.web.socket.messaging.StompSubProtocolErrorHandler"><![CDATA[
|
||||
The bean name of a StompSubProtocolErrorHandler.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:choice>
|
||||
<xsd:element name="simple-broker" type="simple-broker"/>
|
||||
<xsd:element name="stomp-broker-relay" type="stomp-broker-relay"/>
|
||||
|
||||
Reference in New Issue
Block a user