|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.web.socket.server.jetty;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
| 20 | +import java.lang.reflect.Method; |
20 | 21 | import java.security.Principal;
|
21 | 22 | import java.util.ArrayList;
|
22 | 23 | import java.util.List;
|
|
28 | 29 |
|
29 | 30 | import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
30 | 31 | import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
| 32 | +import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory; |
31 | 33 | import org.eclipse.jetty.websocket.server.HandshakeRFC6455;
|
32 | 34 | import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
33 | 35 |
|
|
38 | 40 | import org.springframework.http.server.ServletServerHttpRequest;
|
39 | 41 | import org.springframework.http.server.ServletServerHttpResponse;
|
40 | 42 | import org.springframework.util.Assert;
|
| 43 | +import org.springframework.util.ClassUtils; |
41 | 44 | import org.springframework.util.CollectionUtils;
|
| 45 | +import org.springframework.util.ReflectionUtils; |
42 | 46 | import org.springframework.web.context.ServletContextAware;
|
43 | 47 | import org.springframework.web.socket.WebSocketExtension;
|
44 | 48 | import org.springframework.web.socket.WebSocketHandler;
|
@@ -167,14 +171,26 @@ public List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request
|
167 | 171 | }
|
168 | 172 |
|
169 | 173 | private List<WebSocketExtension> buildWebSocketExtensions() {
|
170 |
| - Set<String> names = this.factory.getExtensionFactory().getExtensionNames(); |
| 174 | + Set<String> names = getExtensionNames(); |
171 | 175 | List<WebSocketExtension> result = new ArrayList<>(names.size());
|
172 | 176 | for (String name : names) {
|
173 | 177 | result.add(new WebSocketExtension(name));
|
174 | 178 | }
|
175 | 179 | return result;
|
176 | 180 | }
|
177 | 181 |
|
| 182 | + @SuppressWarnings({"unchecked"}) |
| 183 | + private Set<String> getExtensionNames() { |
| 184 | + try { |
| 185 | + return this.factory.getExtensionFactory().getExtensionNames(); |
| 186 | + } |
| 187 | + catch (IncompatibleClassChangeError ex) { |
| 188 | + // 9.4.20.v20190813: ExtensionFactory (abstract class -> interface) |
| 189 | + Method method = ClassUtils.getMethod(ExtensionFactory.class, "getExtensionNames"); |
| 190 | + return (Set<String>) ReflectionUtils.invokeMethod(method, this.factory.getExtensionFactory()); |
| 191 | + } |
| 192 | + } |
| 193 | + |
178 | 194 | @Override
|
179 | 195 | public void upgrade(ServerHttpRequest request, ServerHttpResponse response,
|
180 | 196 | String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user,
|
|
0 commit comments