Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
1458c7ed
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1458c7ed
编写于
9月 24, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
UndertowRequestUpgradeStrategy auto-adapts to Undertow 1.3's different Pool API
Issue: SPR-13494
上级
0510329b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
30 deletion
+60
-30
spring-websocket/src/main/java/org/springframework/web/socket/server/standard/UndertowRequestUpgradeStrategy.java
...ocket/server/standard/UndertowRequestUpgradeStrategy.java
+60
-30
未找到文件。
spring-websocket/src/main/java/org/springframework/web/socket/server/standard/UndertowRequestUpgradeStrategy.java
浏览文件 @
1458c7ed
...
...
@@ -17,6 +17,7 @@
package
org.springframework.web.socket.server.standard
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -48,57 +49,84 @@ import io.undertow.websockets.jsr.handshake.HandshakeUtil;
import
io.undertow.websockets.jsr.handshake.JsrHybi07Handshake
;
import
io.undertow.websockets.jsr.handshake.JsrHybi08Handshake
;
import
io.undertow.websockets.jsr.handshake.JsrHybi13Handshake
;
import
io.undertow.websockets.spi.WebSocketHttpExchange
;
import
org.xnio.StreamConnection
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpResponse
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.socket.server.HandshakeFailureException
;
/**
* A {@link org.springframework.web.socket.server.RequestUpgradeStrategy} for use
* with WildFly and its underlying Undertow web server.
*
* <p>Compatible with Undertow 1.0
, 1.1, 1.2 - as included in WildFly 8.x and 9.
0.
* <p>Compatible with Undertow 1.0
to 1.3 - as included in WildFly 8.x, 9 and 1
0.
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @author Juergen Hoeller
* @since 4.0.1
*/
public
class
UndertowRequestUpgradeStrategy
extends
AbstractStandardUpgradeStrategy
{
private
static
final
Constructor
<
ServletWebSocketHttpExchange
>
exchangeConstructor
;
private
static
final
boolean
exchangeConstructorWithPeerConnections
;
private
static
final
Constructor
<
ConfiguredServerEndpoint
>
endpointConstructor
;
private
static
final
boolean
undertow10Present
;
private
static
final
boolean
endpointConstructorWithEndpointFactory
;
private
static
final
Method
getBufferPoolMethod
;
private
static
final
boolean
undertow11Present
;
private
static
final
Method
createChannelMethod
;
static
{
Class
<
ServletWebSocketHttpExchange
>
exchangeType
=
ServletWebSocketHttpExchange
.
class
;
Class
<?>[]
exchangeParamTypes
=
new
Class
<?>[]
{
HttpServletRequest
.
class
,
HttpServletResponse
.
class
,
Set
.
class
};
if
(
ClassUtils
.
hasConstructor
(
exchangeType
,
exchangeParamTypes
))
{
exchangeConstructor
=
ClassUtils
.
getConstructorIfAvailable
(
exchangeType
,
exchangeParamTypes
);
undertow10Present
=
false
;
}
else
{
exchangeParamTypes
=
new
Class
<?>[]
{
HttpServletRequest
.
class
,
HttpServletResponse
.
class
};
exchangeConstructor
=
ClassUtils
.
getConstructorIfAvailable
(
exchangeType
,
exchangeParamTypes
);
undertow10Present
=
true
;
}
try
{
Class
<
ServletWebSocketHttpExchange
>
exchangeType
=
ServletWebSocketHttpExchange
.
class
;
Class
<?>[]
exchangeParamTypes
=
new
Class
<?>[]
{
HttpServletRequest
.
class
,
HttpServletResponse
.
class
,
Set
.
class
};
Constructor
<
ServletWebSocketHttpExchange
>
exchangeCtor
=
ClassUtils
.
getConstructorIfAvailable
(
exchangeType
,
exchangeParamTypes
);
if
(
exchangeCtor
!=
null
)
{
// Undertow 1.1+
exchangeConstructor
=
exchangeCtor
;
exchangeConstructorWithPeerConnections
=
true
;
}
else
{
// Undertow 1.0
exchangeParamTypes
=
new
Class
<?>[]
{
HttpServletRequest
.
class
,
HttpServletResponse
.
class
};
exchangeConstructor
=
exchangeType
.
getConstructor
(
exchangeParamTypes
);
exchangeConstructorWithPeerConnections
=
false
;
}
Class
<
ConfiguredServerEndpoint
>
endpointType
=
ConfiguredServerEndpoint
.
class
;
Class
<?>[]
endpointParamTypes
=
new
Class
<?>[]
{
ServerEndpointConfig
.
class
,
InstanceFactory
.
class
,
PathTemplate
.
class
,
EncodingFactory
.
class
,
AnnotatedEndpointFactory
.
class
};
if
(
ClassUtils
.
hasConstructor
(
endpointType
,
endpointParamTypes
))
{
endpointConstructor
=
ClassUtils
.
getConstructorIfAvailable
(
endpointType
,
endpointParamTypes
);
undertow11Present
=
true
;
Class
<
ConfiguredServerEndpoint
>
endpointType
=
ConfiguredServerEndpoint
.
class
;
Class
<?>[]
endpointParamTypes
=
new
Class
<?>[]
{
ServerEndpointConfig
.
class
,
InstanceFactory
.
class
,
PathTemplate
.
class
,
EncodingFactory
.
class
,
AnnotatedEndpointFactory
.
class
};
Constructor
<
ConfiguredServerEndpoint
>
endpointCtor
=
ClassUtils
.
getConstructorIfAvailable
(
endpointType
,
endpointParamTypes
);
if
(
endpointCtor
!=
null
)
{
// Undertow 1.1+
endpointConstructor
=
endpointCtor
;
endpointConstructorWithEndpointFactory
=
true
;
}
else
{
// Undertow 1.0
endpointParamTypes
=
new
Class
<?>[]
{
ServerEndpointConfig
.
class
,
InstanceFactory
.
class
,
PathTemplate
.
class
,
EncodingFactory
.
class
};
endpointConstructor
=
endpointType
.
getConstructor
(
endpointParamTypes
);
endpointConstructorWithEndpointFactory
=
false
;
}
// Adapting between different Pool API types in Undertow 1.0-1.2 vs 1.3
getBufferPoolMethod
=
WebSocketHttpExchange
.
class
.
getMethod
(
"getBufferPool"
);
createChannelMethod
=
Handshake
.
class
.
getMethod
(
"createChannel"
,
WebSocketHttpExchange
.
class
,
StreamConnection
.
class
,
getBufferPoolMethod
.
getReturnType
());
}
else
{
endpointParamTypes
=
new
Class
<?>[]
{
ServerEndpointConfig
.
class
,
InstanceFactory
.
class
,
PathTemplate
.
class
,
EncodingFactory
.
class
};
endpointConstructor
=
ClassUtils
.
getConstructorIfAvailable
(
endpointType
,
endpointParamTypes
);
undertow11Present
=
false
;
catch
(
Throwable
ex
)
{
throw
new
IllegalStateException
(
"Incompatible Undertow API version"
,
ex
);
}
}
...
...
@@ -113,11 +141,11 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat
public
UndertowRequestUpgradeStrategy
()
{
if
(
undertow10Present
)
{
this
.
peerConnections
=
null
;
if
(
exchangeConstructorWithPeerConnections
)
{
this
.
peerConnections
=
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
WebSocketChannel
,
Boolean
>())
;
}
else
{
this
.
peerConnections
=
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
WebSocketChannel
,
Boolean
>())
;
this
.
peerConnections
=
null
;
}
}
...
...
@@ -149,7 +177,9 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat
exchange
.
upgradeChannel
(
new
HttpUpgradeListener
()
{
@Override
public
void
handleUpgrade
(
StreamConnection
connection
,
HttpServerExchange
serverExchange
)
{
WebSocketChannel
channel
=
handshake
.
createChannel
(
exchange
,
connection
,
exchange
.
getBufferPool
());
Object
bufferPool
=
ReflectionUtils
.
invokeMethod
(
getBufferPoolMethod
,
exchange
);
WebSocketChannel
channel
=
(
WebSocketChannel
)
ReflectionUtils
.
invokeMethod
(
createChannelMethod
,
handshake
,
exchange
,
connection
,
bufferPool
);
if
(
peerConnections
!=
null
)
{
peerConnections
.
add
(
channel
);
}
...
...
@@ -202,7 +232,7 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat
Collections
.<
Class
<?>,
List
<
InstanceFactory
<?
extends
Encoder
>>>
emptyMap
(),
Collections
.<
Class
<?>,
List
<
InstanceFactory
<?
extends
Decoder
>>>
emptyMap
());
try
{
return
(
undertow11Present
?
return
(
endpointConstructorWithEndpointFactory
?
endpointConstructor
.
newInstance
(
endpointRegistration
,
new
EndpointInstanceFactory
(
endpoint
),
null
,
encodingFactory
,
null
)
:
endpointConstructor
.
newInstance
(
endpointRegistration
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录