问题描述
我在一个项目上设置了 Spring Stomp,一切正常,但我一直在服务器日志中收到错误消息。
2021-02-17 05:02:26.875 ERROR 23773 --- [oundChannel-914] o.s.w.s.m.StompSubProtocolHandler : Error publishing SessionConnectedEvent[Genericmessage [payload=byte[0],headers={simpMessageType=CONNECT_ACK,simpConnectMessage=Genericmessage [payload=byte[0],headers={simpMessageType=CONNECT,stompCommand=CONNECT,nativeHeaders={x_from_wss=[true],accept-version=[1.1,1.0],heart-beat=[0,0]},simpSessionAttributes={},simpHeartbeat=[J@1dbcdf26,simpuser=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@cda212a8: Principal: me.xxxx.xxx.user.security.UserLoginDetails@325d7812; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Not granted any authorities,simpSessionId=ml2gvecs}],simpSessionId=ml2gvecs}]]
我也尝试为 websocket 设置事件处理程序,但它仍然继续显示在日志中。我知道它是来自客户端的连接确认消息,但它不应该失败。任何建议将不胜感激。
解决方法
错误说:
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken= new UsernamePasswordAuthenticationToken(
"AuthenticatedUserName","Credentials",Collections.singleton((GrantedAuthority) () -> "USER")
);
如果您使用的是 Spring Security 之类的东西,请确保在通过身份验证后传递一组授权机构。
你可以这样做
//
collectionview.isPaging = false
//
class CollectionLayoutSubclass: UICollectionViewFlowLayout {
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint,withScrollingVelocity velocity: CGPoint) -> CGPoint {
var point = super.targetContentOffset(forProposedContentOffset: proposedContentOffset,withScrollingVelocity: velocity)
guard let collectionView = collectionView else {
return point
}
let cells = collectionView.visibleCells
let centerPoint = collectionView.center
var cellFrame: CGRect = CGRect.zero
for cell in cells {
cellFrame = collectionView.convert(cell.frame,to: collectionView.superview)
var newCenterPoint: CGPoint = centerPoint
if velocity.x > 0 {
newCenterPoint = CGPoint(x: centerPoint.x * 1.5,y: centerPoint.y)
} else if velocity.x < 0 {
newCenterPoint = CGPoint(x: centerPoint.x * 0.5,y: centerPoint.y)
}
guard cellFrame.contains(newCenterPoint) else {
continue
}
let x = collectionView.frame.width / 2 - cell.frame.width / 2
point.x = cell.frame.origin.x - x
break
}
return point
}
}
如果您没有使用 Spring Security,您可以通过 Channel Interceptor 设置一个 Authenticated User Token。
点击以下链接,了解如何为您的 WebSocket 连接设置通道拦截器