16
16
17
17
package org .springframework .web .socket .server .endpoint ;
18
18
19
- import javax .websocket .Endpoint ;
20
- import javax .websocket .EndpointConfig ;
21
- import javax .websocket .Session ;
19
+ import javax .websocket .server .ServerEndpoint ;
22
20
23
21
import org .junit .After ;
24
22
import org .junit .Before ;
@@ -65,22 +63,22 @@ public void destroy() {
65
63
66
64
67
65
@ Test
68
- public void getEndpointInstancePerConnection () throws Exception {
66
+ public void getEndpointPerConnection () throws Exception {
69
67
PerConnectionEchoEndpoint endpoint = this .configurator .getEndpointInstance (PerConnectionEchoEndpoint .class );
70
68
assertNotNull (endpoint );
71
69
}
72
70
73
71
@ Test
74
- public void getEndpointInstanceSingletonByType () throws Exception {
72
+ public void getEndpointSingletonByType () throws Exception {
75
73
EchoEndpoint expected = this .webAppContext .getBean (EchoEndpoint .class );
76
74
EchoEndpoint actual = this .configurator .getEndpointInstance (EchoEndpoint .class );
77
75
assertSame (expected , actual );
78
76
}
79
77
80
78
@ Test
81
- public void getEndpointInstanceSingletonByComponentName () throws Exception {
82
- AnotherEchoEndpoint expected = this .webAppContext .getBean (AnotherEchoEndpoint .class );
83
- AnotherEchoEndpoint actual = this .configurator .getEndpointInstance (AnotherEchoEndpoint .class );
79
+ public void getEndpointSingletonByComponentName () throws Exception {
80
+ ComponentEchoEndpoint expected = this .webAppContext .getBean (ComponentEchoEndpoint .class );
81
+ ComponentEchoEndpoint actual = this .configurator .getEndpointInstance (ComponentEchoEndpoint .class );
84
82
assertSame (expected , actual );
85
83
}
86
84
@@ -90,7 +88,7 @@ public void getEndpointInstanceSingletonByComponentName() throws Exception {
90
88
static class Config {
91
89
92
90
@ Bean
93
- public EchoEndpoint echoEndpoint () {
91
+ public EchoEndpoint javaConfigEndpoint () {
94
92
return new EchoEndpoint (echoService ());
95
93
}
96
94
@@ -100,7 +98,8 @@ public EchoService echoService() {
100
98
}
101
99
}
102
100
103
- private static class EchoEndpoint extends Endpoint {
101
+ @ ServerEndpoint ("/echo" )
102
+ private static class EchoEndpoint {
104
103
105
104
@ SuppressWarnings ("unused" )
106
105
private final EchoService service ;
@@ -109,29 +108,23 @@ private static class EchoEndpoint extends Endpoint {
109
108
public EchoEndpoint (EchoService service ) {
110
109
this .service = service ;
111
110
}
112
-
113
- @ Override
114
- public void onOpen (Session session , EndpointConfig config ) {
115
- }
116
111
}
117
112
118
- @ Component ("myEchoEndpoint" )
119
- private static class AnotherEchoEndpoint extends Endpoint {
113
+ @ Component ("myComponentEchoEndpoint" )
114
+ @ ServerEndpoint ("/echo" )
115
+ private static class ComponentEchoEndpoint {
120
116
121
117
@ SuppressWarnings ("unused" )
122
118
private final EchoService service ;
123
119
124
120
@ Autowired
125
- public AnotherEchoEndpoint (EchoService service ) {
121
+ public ComponentEchoEndpoint (EchoService service ) {
126
122
this .service = service ;
127
123
}
128
-
129
- @ Override
130
- public void onOpen (Session session , EndpointConfig config ) {
131
- }
132
124
}
133
125
134
- private static class PerConnectionEchoEndpoint extends Endpoint {
126
+ @ ServerEndpoint ("/echo" )
127
+ private static class PerConnectionEchoEndpoint {
135
128
136
129
@ SuppressWarnings ("unused" )
137
130
private final EchoService service ;
@@ -140,10 +133,6 @@ private static class PerConnectionEchoEndpoint extends Endpoint {
140
133
public PerConnectionEchoEndpoint (EchoService service ) {
141
134
this .service = service ;
142
135
}
143
-
144
- @ Override
145
- public void onOpen (Session session , EndpointConfig config ) {
146
- }
147
136
}
148
137
149
138
private static class EchoService { }
0 commit comments