Add config option for StompSubProtocolErrorHandler

Issue: SPR-13142
This commit is contained in:
Rossen Stoyanchev
2015-06-21 11:12:41 -04:00
parent 31a5434ea4
commit d1cc8bac5c
9 changed files with 73 additions and 12 deletions

View File

@@ -16,6 +16,9 @@
package org.springframework.web.socket.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
@@ -64,9 +67,6 @@ import org.springframework.web.socket.sockjs.transport.handler.XhrPollingTranspo
import org.springframework.web.socket.sockjs.transport.handler.XhrReceivingTransportHandler;
import org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Test fixture for HandlersBeanDefinitionParser.
* See test configuration files websocket-config-handlers-*.xml.

View File

@@ -73,6 +73,7 @@ import org.springframework.web.socket.handler.TestWebSocketSession;
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
import org.springframework.web.socket.messaging.DefaultSimpUserRegistry;
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
@@ -144,6 +145,8 @@ public class MessageBrokerBeanDefinitionParserTests {
StompSubProtocolHandler stompHandler = (StompSubProtocolHandler) handlerMap.get("v12.stomp");
assertNotNull(stompHandler);
assertEquals(128 * 1024, stompHandler.getMessageSizeLimit());
assertNotNull(stompHandler.getErrorHandler());
assertEquals(TestStompErrorHandler.class, stompHandler.getErrorHandler().getClass());
assertNotNull(new DirectFieldAccessor(stompHandler).getPropertyValue("eventPublisher"));
@@ -498,4 +501,8 @@ class TestWebSocketHandlerDecoratorFactory implements WebSocketHandlerDecoratorF
}
};
}
}
class TestStompErrorHandler extends StompSubProtocolErrorHandler {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@@ -17,16 +17,18 @@
package org.springframework.web.socket.config.annotation;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
import org.springframework.web.util.UrlPathHelper;
@@ -46,12 +48,12 @@ public class WebMvcStompEndpointRegistryTests {
@Before
public void setup() {
SubscribableChannel inChannel = Mockito.mock(SubscribableChannel.class);
SubscribableChannel outChannel = Mockito.mock(SubscribableChannel.class);
SubscribableChannel inChannel = mock(SubscribableChannel.class);
SubscribableChannel outChannel = mock(SubscribableChannel.class);
this.webSocketHandler = new SubProtocolWebSocketHandler(inChannel, outChannel);
WebSocketTransportRegistration transport = new WebSocketTransportRegistration();
TaskScheduler scheduler = Mockito.mock(TaskScheduler.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
this.endpointRegistry = new WebMvcStompEndpointRegistry(this.webSocketHandler, transport, null, scheduler);
}
@@ -87,4 +89,15 @@ public class WebMvcStompEndpointRegistryTests {
assertSame(pathHelper, hm.getUrlPathHelper());
}
@Test
public void errorHandler() throws Exception {
StompSubProtocolErrorHandler errorHandler = mock(StompSubProtocolErrorHandler.class);
this.endpointRegistry.setErrorHandler(errorHandler);
this.endpointRegistry.addEndpoint("/stompOverWebSocket");
Map<String, SubProtocolHandler> protocolHandlers = this.webSocketHandler.getProtocolHandlerMap();
StompSubProtocolHandler stompHandler = (StompSubProtocolHandler) protocolHandlers.get("v12.stomp");
assertSame(errorHandler, stompHandler.getErrorHandler());
}
}