Skip to content

Commit 5feac07

Browse files
committed
Add getLastHandler to WebSocketHandlerDecorator
1 parent d20dabf commit 5feac07

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/support/WebSocketHandlerDecorator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public WebSocketHandler getDelegate() {
4242
return this.delegate;
4343
}
4444

45+
public WebSocketHandler getLastHandler() {
46+
WebSocketHandler result = delegate;
47+
while (result instanceof WebSocketHandlerDecorator) {
48+
result = ((WebSocketHandlerDecorator) result).getDelegate();
49+
}
50+
return result;
51+
}
52+
4553
@Override
4654
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
4755
this.delegate.afterConnectionEstablished(session);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.socket.support;
18+
19+
import org.junit.Test;
20+
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
21+
22+
import static org.junit.Assert.*;
23+
24+
25+
/**
26+
* Test fixture for {@link WebSocketHandlerDecorator}.
27+
*
28+
* @author Rossen Stoyanchev
29+
*/
30+
public class WebSocketHandlerDecoratorTests {
31+
32+
33+
@Test
34+
public void getLastHandler() {
35+
WebSocketHandlerAdapter h1 = new WebSocketHandlerAdapter();
36+
WebSocketHandlerDecorator h2 = new WebSocketHandlerDecorator(h1);
37+
WebSocketHandlerDecorator h3 = new WebSocketHandlerDecorator(h2);
38+
39+
assertSame(h1, h3.getLastHandler());
40+
}
41+
42+
}

0 commit comments

Comments
 (0)