Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有Spring Web套接字和STOMP的自定义Jetty WebSocketPolicy_Java_Spring_Jetty_Spring Websocket - Fatal编程技术网

Java 带有Spring Web套接字和STOMP的自定义Jetty WebSocketPolicy

Java 带有Spring Web套接字和STOMP的自定义Jetty WebSocketPolicy,java,spring,jetty,spring-websocket,Java,Spring,Jetty,Spring Websocket,我想在将SpringWebSockets与STOMP一起使用时自定义JettyWebSocketPolicy 这是我的配置类: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer { @Override public void configureWebSocketTran

我想在将SpringWebSockets与STOMP一起使用时自定义Jetty
WebSocketPolicy

这是我的配置类:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {

    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
        registration.setMessageSizeLimit(128 * 1024);
    }

}
当通过
WebSocketTransportRegistration
设置消息大小限制时,它无法解决问题,因为Jetty在涉及Spring之前进行了文本消息大小检查。您可以通过以下堆栈跟踪查看它:

org.eclipse.jetty.websocket.api.MessageTooLargeException: Text message size [70412] exceeds maximum size [65536]
    at org.eclipse.jetty.websocket.api.WebSocketPolicy.assertValidTextMessageSize(WebSocketPolicy.java:140) ~[websocket-api-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.websocket.common.Parser.assertSanePayloadLength(Parser.java:127) ~[websocket-common-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.websocket.common.Parser.parseFrame(Parser.java:485) ~[websocket-common-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:241) ~[websocket-common-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:560) [websocket-common-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:391) [websocket-common-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281) [jetty-io-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102) [jetty-io-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [jetty-io-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680) [jetty-util-9.4.11.v20180605.jar:9.4.11.v20180605]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
因此,我正在寻找一种方法来提供一个定制的
WebSocketPolicy
,并在创建
JettyRequestUpgradeStrategy
时传递它,但我找不到一种方法

当使用以下配置类时,这似乎是可能的,但它会错过message broker配置:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

}

解决方案很简单,但没有文档记录

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {

  @Override
  public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/ws").setHandshakeHandler(handshakeHandler());
    registry.addEndpoint("/ws").setHandshakeHandler(handshakeHandler()).withSockJS();
  }

  @Bean
  public DefaultHandshakeHandler handshakeHandler() {
    WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
    policy.setMaxTextMessageSize(128 * 1024);

    return new DefaultHandshakeHandler(new JettyRequestUpgradeStrategy(policy));
  }
}