74 changed files with 2139 additions and 668 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompauthenticationtokenbased; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.Message; |
||||
import org.springframework.messaging.MessageChannel; |
||||
import org.springframework.messaging.simp.config.ChannelRegistration; |
||||
import org.springframework.messaging.simp.stomp.StompCommand; |
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; |
||||
import org.springframework.messaging.support.ChannelInterceptor; |
||||
import org.springframework.messaging.support.MessageHeaderAccessor; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureClientInboundChannel(ChannelRegistration registration) { |
||||
registration.interceptors(new ChannelInterceptor() { |
||||
@Override |
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) { |
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); |
||||
if (StompCommand.CONNECT.equals(accessor.getCommand())) { |
||||
// Access authentication header(s) and invoke accessor.setUser(user)
|
||||
} |
||||
return message; |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompconfigurationperformance; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class MessageSizeLimitWebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureWebSocketTransport(WebSocketTransportRegistration registration) { |
||||
registration.setMessageSizeLimit(128 * 1024); |
||||
} |
||||
|
||||
// ...
|
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompconfigurationperformance; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureWebSocketTransport(WebSocketTransportRegistration registration) { |
||||
registration.setSendTimeLimit(15 * 1000).setSendBufferSizeLimit(512 * 1024); |
||||
} |
||||
|
||||
// ...
|
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompdestinationseparator; |
||||
|
||||
import org.springframework.messaging.handler.annotation.DestinationVariable; |
||||
import org.springframework.messaging.handler.annotation.MessageMapping; |
||||
import org.springframework.stereotype.Controller; |
||||
|
||||
// tag::snippet[]
|
||||
@Controller |
||||
@MessageMapping("red") |
||||
public class RedController { |
||||
|
||||
@MessageMapping("blue.{green}") |
||||
public void handleGreen(@DestinationVariable String green) { |
||||
// ...
|
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompdestinationseparator; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.util.AntPathMatcher; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
// ...
|
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
registry.setPathMatcher(new AntPathMatcher(".")); |
||||
registry.enableStompBrokerRelay("/queue", "/topic"); |
||||
registry.setApplicationDestinationPrefixes("/app"); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompenable; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void registerStompEndpoints(StompEndpointRegistry registry) { |
||||
// /portfolio is the HTTP URL for the endpoint to which a WebSocket (or SockJS)
|
||||
// client needs to connect for the WebSocket handshake
|
||||
registry.addEndpoint("/portfolio"); |
||||
} |
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry config) { |
||||
// STOMP messages whose destination header begins with /app are routed to
|
||||
// @MessageMapping methods in @Controller classes
|
||||
config.setApplicationDestinationPrefixes("/app"); |
||||
// Use the built-in message broker for subscriptions and broadcasting and
|
||||
// route messages whose destination header begins with /topic or /queue to the broker
|
||||
config.enableSimpleBroker("/topic", "/queue"); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlebrokerrelay; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void registerStompEndpoints(StompEndpointRegistry registry) { |
||||
registry.addEndpoint("/portfolio").withSockJS(); |
||||
} |
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
registry.enableStompBrokerRelay("/topic", "/queue"); |
||||
registry.setApplicationDestinationPrefixes("/app"); |
||||
} |
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlebrokerrelayconfigure; |
||||
|
||||
import java.net.InetSocketAddress; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.messaging.simp.stomp.StompReactorNettyCodec; |
||||
import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
// ...
|
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
registry.enableStompBrokerRelay("/queue/", "/topic/").setTcpClient(createTcpClient()); |
||||
registry.setApplicationDestinationPrefixes("/app"); |
||||
} |
||||
|
||||
private ReactorNettyTcpClient<byte[]> createTcpClient() { |
||||
return new ReactorNettyTcpClient<>( |
||||
client -> client.addressSupplier(() -> new InetSocketAddress(0)), |
||||
new StompReactorNettyCodec()); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlesimplebroker; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Lazy; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.scheduling.TaskScheduler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
private TaskScheduler messageBrokerTaskScheduler; |
||||
|
||||
@Autowired |
||||
public void setMessageBrokerTaskScheduler(@Lazy TaskScheduler taskScheduler) { |
||||
this.messageBrokerTaskScheduler = taskScheduler; |
||||
} |
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
registry.enableSimpleBroker("/queue/", "/topic/") |
||||
.setHeartbeatValue(new long[] {10000, 20000}) |
||||
.setTaskScheduler(this.messageBrokerTaskScheduler); |
||||
|
||||
// ...
|
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompinterceptors; |
||||
|
||||
import org.springframework.messaging.Message; |
||||
import org.springframework.messaging.MessageChannel; |
||||
import org.springframework.messaging.simp.stomp.StompCommand; |
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; |
||||
import org.springframework.messaging.support.ChannelInterceptor; |
||||
|
||||
// tag::snippet[]
|
||||
public class MyChannelInterceptor implements ChannelInterceptor { |
||||
|
||||
@Override |
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) { |
||||
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); |
||||
StompCommand command = accessor.getCommand(); |
||||
// ...
|
||||
return message; |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompinterceptors; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.ChannelRegistration; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureClientInboundChannel(ChannelRegistration registration) { |
||||
registration.interceptors(new MyChannelInterceptor()); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompmessageflow; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.handler.annotation.MessageMapping; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Controller |
||||
public class GreetingController { |
||||
|
||||
@MessageMapping("/greeting") |
||||
public String handle(String greeting) { |
||||
return "[" + getTimestamp() + ": " + greeting; |
||||
} |
||||
|
||||
private String getTimestamp() { |
||||
return new SimpleDateFormat("MM/dd/yyyy h:mm:ss a").format(new Date()); |
||||
} |
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompmessageflow; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void registerStompEndpoints(StompEndpointRegistry registry) { |
||||
registry.addEndpoint("/portfolio"); |
||||
} |
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
registry.setApplicationDestinationPrefixes("/app"); |
||||
registry.enableSimpleBroker("/topic"); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomporderedmessages; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class PublishOrderWebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureMessageBroker(MessageBrokerRegistry registry) { |
||||
// ...
|
||||
registry.setPreservePublishOrder(true); |
||||
} |
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomporderedmessages; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class ReceiveOrderWebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void registerStompEndpoints(StompEndpointRegistry registry) { |
||||
registry.setPreserveReceiveOrder(true); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompserverconfig; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy; |
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class JettyWebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void registerStompEndpoints(StompEndpointRegistry registry) { |
||||
registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler()); |
||||
} |
||||
|
||||
@Bean |
||||
public DefaultHandshakeHandler handshakeHandler() { |
||||
JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy(); |
||||
strategy.addWebSocketConfigurer(configurable -> { |
||||
configurable.setInputBufferSize(4 * 8192); |
||||
configurable.setIdleTimeout(Duration.ofSeconds(600)); |
||||
}); |
||||
return new DefaultHandshakeHandler(strategy); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompserverconfig; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { |
||||
|
||||
@Override |
||||
public void configureWebSocketTransport(WebSocketTransportRegistration registry) { |
||||
registry.setMessageSizeLimit(4 * 8192); |
||||
registry.setTimeToFirstMessage(30000); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketfallbacksockjsenable; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler; |
||||
import org.springframework.web.socket.WebSocketHandler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocket |
||||
public class WebSocketConfiguration implements WebSocketConfigurer { |
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
||||
registry.addHandler(myHandler(), "/myHandler").withSockJS(); |
||||
} |
||||
|
||||
@Bean |
||||
public WebSocketHandler myHandler() { |
||||
return new MyHandler(); |
||||
} |
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverallowedorigins; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler; |
||||
import org.springframework.web.socket.WebSocketHandler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocket |
||||
public class WebSocketConfiguration implements WebSocketConfigurer { |
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
||||
registry.addHandler(myHandler(), "/myHandler").setAllowedOrigins("https://mydomain.com"); |
||||
} |
||||
|
||||
@Bean |
||||
public WebSocketHandler myHandler() { |
||||
return new MyHandler(); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandler; |
||||
|
||||
import org.springframework.web.socket.TextMessage; |
||||
import org.springframework.web.socket.WebSocketSession; |
||||
import org.springframework.web.socket.handler.TextWebSocketHandler; |
||||
|
||||
// tag::snippet[]
|
||||
public class MyHandler extends TextWebSocketHandler { |
||||
|
||||
@Override |
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) { |
||||
// ...
|
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandler; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.socket.WebSocketHandler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocket |
||||
public class WebSocketConfiguration implements WebSocketConfigurer { |
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
||||
registry.addHandler(myHandler(), "/myHandler"); |
||||
} |
||||
|
||||
@Bean |
||||
public WebSocketHandler myHandler() { |
||||
return new MyHandler(); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandshake; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocket |
||||
public class WebSocketConfiguration implements WebSocketConfigurer { |
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
||||
registry.addHandler(new MyHandler(), "/myHandler") |
||||
.addInterceptors(new HttpSessionHandshakeInterceptor()); |
||||
} |
||||
|
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverruntimeconfiguration; |
||||
|
||||
import java.time.Duration; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.socket.WebSocketHandler; |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy; |
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableWebSocket |
||||
public class JettyWebSocketConfiguration implements WebSocketConfigurer { |
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
||||
registry.addHandler(echoWebSocketHandler(), "/echo").setHandshakeHandler(handshakeHandler()); |
||||
} |
||||
|
||||
@Bean |
||||
public WebSocketHandler echoWebSocketHandler() { |
||||
return new MyEchoHandler(); |
||||
} |
||||
|
||||
@Bean |
||||
public DefaultHandshakeHandler handshakeHandler() { |
||||
JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy(); |
||||
strategy.addWebSocketConfigurer(configurable -> { |
||||
configurable.setInputBufferSize(8192); |
||||
configurable.setIdleTimeout(Duration.ofSeconds(600)); |
||||
}); |
||||
return new DefaultHandshakeHandler(strategy); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverruntimeconfiguration; |
||||
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler; |
||||
|
||||
public class MyEchoHandler extends AbstractWebSocketHandler { |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverruntimeconfiguration; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
public class WebSocketConfiguration { |
||||
|
||||
@Bean |
||||
public ServletServerContainerFactoryBean createWebSocketContainer() { |
||||
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); |
||||
container.setMaxTextMessageBufferSize(8192); |
||||
container.setMaxBinaryMessageBufferSize(8192); |
||||
return container; |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompauthenticationtokenbased |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.Message |
||||
import org.springframework.messaging.MessageChannel |
||||
import org.springframework.messaging.simp.config.ChannelRegistration |
||||
import org.springframework.messaging.simp.stomp.StompCommand |
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor |
||||
import org.springframework.messaging.support.ChannelInterceptor |
||||
import org.springframework.messaging.support.MessageHeaderAccessor |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureClientInboundChannel(registration: ChannelRegistration) { |
||||
registration.interceptors(object : ChannelInterceptor { |
||||
override fun preSend(message: Message<*>, channel: MessageChannel): Message<*> { |
||||
val accessor = MessageHeaderAccessor.getAccessor(message, |
||||
StompHeaderAccessor::class.java) |
||||
if (StompCommand.CONNECT == accessor!!.command) { |
||||
// Access authentication header(s) and invoke accessor.setUser(user) |
||||
} |
||||
return message |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompconfigurationperformance |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class MessageSizeLimitWebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureWebSocketTransport(registration: WebSocketTransportRegistration) { |
||||
registration.setMessageSizeLimit(128 * 1024) |
||||
} |
||||
|
||||
// ... |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompconfigurationperformance |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureWebSocketTransport(registration: WebSocketTransportRegistration) { |
||||
registration.setSendTimeLimit(15 * 1000).setSendBufferSizeLimit(512 * 1024) |
||||
} |
||||
|
||||
// ... |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompdestinationseparator |
||||
|
||||
import org.springframework.messaging.handler.annotation.DestinationVariable |
||||
import org.springframework.messaging.handler.annotation.MessageMapping |
||||
import org.springframework.stereotype.Controller |
||||
|
||||
// tag::snippet[] |
||||
@Controller |
||||
@MessageMapping("red") |
||||
class RedController { |
||||
|
||||
@MessageMapping("blue.{green}") |
||||
fun handleGreen(@DestinationVariable green: String?) { |
||||
// ... |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompdestinationseparator |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.util.AntPathMatcher |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
// ... |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
registry.setPathMatcher(AntPathMatcher(".")) |
||||
registry.enableStompBrokerRelay("/queue", "/topic") |
||||
registry.setApplicationDestinationPrefixes("/app") |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompenable |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { |
||||
// /portfolio is the HTTP URL for the endpoint to which a WebSocket (or SockJS) |
||||
// client needs to connect for the WebSocket handshake |
||||
registry.addEndpoint("/portfolio") |
||||
} |
||||
|
||||
override fun configureMessageBroker(config: MessageBrokerRegistry) { |
||||
// STOMP messages whose destination header begins with /app are routed to |
||||
// @MessageMapping methods in @Controller classes |
||||
config.setApplicationDestinationPrefixes("/app") |
||||
// Use the built-in message broker for subscriptions and broadcasting and |
||||
// route messages whose destination header begins with /topic or /queue to the broker |
||||
config.enableSimpleBroker("/topic", "/queue") |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlebrokerrelay |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { |
||||
registry.addEndpoint("/portfolio").withSockJS() |
||||
} |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
registry.enableStompBrokerRelay("/topic", "/queue") |
||||
registry.setApplicationDestinationPrefixes("/app") |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlebrokerrelayconfigure |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.messaging.simp.stomp.StompReactorNettyCodec |
||||
import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
import java.net.InetSocketAddress |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
// ... |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
registry.enableStompBrokerRelay("/queue/", "/topic/").setTcpClient(createTcpClient()) |
||||
registry.setApplicationDestinationPrefixes("/app") |
||||
} |
||||
|
||||
private fun createTcpClient(): ReactorNettyTcpClient<ByteArray> { |
||||
return ReactorNettyTcpClient({ it.addressSupplier { InetSocketAddress(0) } }, StompReactorNettyCodec()) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomphandlesimplebroker |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.context.annotation.Lazy |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.scheduling.TaskScheduler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
private lateinit var messageBrokerTaskScheduler: TaskScheduler |
||||
|
||||
@Autowired |
||||
fun setMessageBrokerTaskScheduler(@Lazy taskScheduler: TaskScheduler) { |
||||
this.messageBrokerTaskScheduler = taskScheduler |
||||
} |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
registry.enableSimpleBroker("/queue/", "/topic/") |
||||
.setHeartbeatValue(longArrayOf(10000, 20000)) |
||||
.setTaskScheduler(messageBrokerTaskScheduler) |
||||
|
||||
// ... |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompinterceptors |
||||
|
||||
import org.springframework.messaging.Message |
||||
import org.springframework.messaging.MessageChannel |
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor |
||||
import org.springframework.messaging.support.ChannelInterceptor |
||||
|
||||
// tag::snippet[] |
||||
class MyChannelInterceptor : ChannelInterceptor { |
||||
|
||||
override fun preSend(message: Message<*>, channel: MessageChannel): Message<*> { |
||||
val accessor = StompHeaderAccessor.wrap(message) |
||||
val command = accessor.command |
||||
// ... |
||||
return message |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompinterceptors |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.ChannelRegistration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureClientInboundChannel(registration: ChannelRegistration) { |
||||
registration.interceptors(MyChannelInterceptor()) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompmessageflow |
||||
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping |
||||
import org.springframework.stereotype.Controller |
||||
import java.text.SimpleDateFormat |
||||
import java.util.* |
||||
|
||||
// tag::snippet[] |
||||
@Controller |
||||
class GreetingController { |
||||
|
||||
@MessageMapping("/greeting") |
||||
fun handle(greeting: String): String { |
||||
return "[${getTimestamp()}: $greeting" |
||||
} |
||||
|
||||
private fun getTimestamp(): String { |
||||
return SimpleDateFormat("MM/dd/yyyy h:mm:ss a").format(Date()) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompmessageflow |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { |
||||
registry.addEndpoint("/portfolio") |
||||
} |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
registry.setApplicationDestinationPrefixes("/app") |
||||
registry.enableSimpleBroker("/topic") |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomporderedmessages |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class PublishOrderWebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureMessageBroker(registry: MessageBrokerRegistry) { |
||||
// ... |
||||
registry.setPreservePublishOrder(true) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstomporderedmessages |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class ReceiveOrderWebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { |
||||
registry.setPreserveReceiveOrder(true) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompserverconfig |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy |
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler |
||||
import java.time.Duration |
||||
import java.util.function.Consumer |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class JettyWebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) { |
||||
registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler()) |
||||
} |
||||
|
||||
@Bean |
||||
fun handshakeHandler(): DefaultHandshakeHandler { |
||||
val strategy = JettyRequestUpgradeStrategy() |
||||
strategy.addWebSocketConfigurer { |
||||
it.inputBufferSize = 4 * 8192 |
||||
it.idleTimeout = Duration.ofSeconds(600) |
||||
} |
||||
return DefaultHandshakeHandler(strategy) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.stomp.websocketstompserverconfig |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker |
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocketMessageBroker |
||||
class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { |
||||
|
||||
override fun configureWebSocketTransport(registry: WebSocketTransportRegistration) { |
||||
registry.setMessageSizeLimit(4 * 8192) |
||||
registry.setTimeToFirstMessage(30000) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.docs.web.websocket.websocketfallbacksockjsenable |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler |
||||
import org.springframework.web.socket.WebSocketHandler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocket |
||||
class WebSocketConfiguration : WebSocketConfigurer { |
||||
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) { |
||||
registry.addHandler(myHandler(), "/myHandler").withSockJS() |
||||
} |
||||
|
||||
@Bean |
||||
fun myHandler(): WebSocketHandler { |
||||
return MyHandler() |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.docs.web.websocket.websocketserverallowedorigins |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler |
||||
import org.springframework.web.socket.WebSocketHandler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocket |
||||
class WebSocketConfiguration : WebSocketConfigurer { |
||||
|
||||
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) { |
||||
registry.addHandler(myHandler(), "/myHandler").setAllowedOrigins("https://mydomain.com") |
||||
} |
||||
|
||||
@Bean |
||||
fun myHandler(): WebSocketHandler { |
||||
return MyHandler() |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandler |
||||
|
||||
import org.springframework.web.socket.TextMessage |
||||
import org.springframework.web.socket.WebSocketSession |
||||
import org.springframework.web.socket.handler.TextWebSocketHandler |
||||
|
||||
// tag::snippet[] |
||||
class MyHandler : TextWebSocketHandler() { |
||||
|
||||
override fun handleTextMessage(session: WebSocketSession, message: TextMessage) { |
||||
// ... |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandler |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.WebSocketHandler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocket |
||||
class WebSocketConfiguration : WebSocketConfigurer { |
||||
|
||||
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) { |
||||
registry.addHandler(myHandler(), "/myHandler") |
||||
} |
||||
|
||||
@Bean |
||||
fun myHandler(): WebSocketHandler { |
||||
return MyHandler() |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverhandshake |
||||
|
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.docs.web.websocket.websocketserverhandler.MyHandler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry |
||||
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocket |
||||
class WebSocketConfiguration : WebSocketConfigurer { |
||||
|
||||
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) { |
||||
registry.addHandler(MyHandler(), "/myHandler") |
||||
.addInterceptors(HttpSessionHandshakeInterceptor()) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.docs.web.websocket.websocketserverruntimeconfiguration |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.WebSocketHandler |
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry |
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy |
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler |
||||
import java.time.Duration |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableWebSocket |
||||
class JettyWebSocketConfiguration : WebSocketConfigurer { |
||||
|
||||
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) { |
||||
registry.addHandler(echoWebSocketHandler(), "/echo").setHandshakeHandler(handshakeHandler()) |
||||
} |
||||
|
||||
@Bean |
||||
fun echoWebSocketHandler(): WebSocketHandler { |
||||
return MyEchoHandler() |
||||
} |
||||
|
||||
@Bean |
||||
fun handshakeHandler(): DefaultHandshakeHandler { |
||||
val strategy = JettyRequestUpgradeStrategy() |
||||
strategy.addWebSocketConfigurer { |
||||
it.inputBufferSize = 8192 |
||||
it.idleTimeout = Duration.ofSeconds(600) |
||||
} |
||||
return DefaultHandshakeHandler(strategy) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2002-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.web.websocket.websocketserverruntimeconfiguration |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
class WebSocketConfiguration { |
||||
|
||||
@Bean |
||||
fun createWebSocketContainer() = ServletServerContainerFactoryBean().apply { |
||||
maxTextMessageBufferSize = 8192 |
||||
maxBinaryMessageBufferSize = 8192 |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker> |
||||
<websocket:transport message-size="131072" /> |
||||
<!-- ... --> |
||||
</websocket:message-broker> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker> |
||||
<websocket:transport send-timeout="15000" send-buffer-size="524288" /> |
||||
<!-- ... --> |
||||
</websocket:message-broker> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker application-destination-prefix="/app" path-matcher="pathMatcher"> |
||||
<websocket:stomp-endpoint path="/stomp"/> |
||||
<websocket:stomp-broker-relay prefix="/topic,/queue" /> |
||||
</websocket:message-broker> |
||||
|
||||
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher"> |
||||
<constructor-arg index="0" value="."/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker application-destination-prefix="/app"> |
||||
<websocket:stomp-endpoint path="/portfolio" /> |
||||
<websocket:simple-broker prefix="/topic, /queue"/> |
||||
</websocket:message-broker> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker application-destination-prefix="/app"> |
||||
<websocket:stomp-endpoint path="/portfolio"> |
||||
<websocket:sockjs /> |
||||
</websocket:stomp-endpoint> |
||||
<websocket:stomp-broker-relay prefix="/topic,/queue" /> |
||||
</websocket:message-broker> |
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:message-broker preserve-publish-order="true"> |
||||
<!-- ... --> |
||||
</websocket:message-broker> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:handlers> |
||||
<websocket:mapping path="/myHandler" handler="myHandler"/> |
||||
<websocket:sockjs/> |
||||
</websocket:handlers> |
||||
|
||||
<bean id="myHandler" class="org.springframework.docs.web.websocket.websocketserverhandler.MyHandler"/> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:handlers allowed-origins="https://mydomain.com"> |
||||
<websocket:mapping path="/myHandler" handler="myHandler" /> |
||||
</websocket:handlers> |
||||
|
||||
<bean id="myHandler" class="org.springframework.docs.web.websocket.websocketserverhandler.MyHandler" /> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:handlers> |
||||
<websocket:mapping path="/myHandler" handler="myHandler"/> |
||||
</websocket:handlers> |
||||
|
||||
<bean id="myHandler" class="org.springframework.docs.web.websocket.websocketserverhandler.MyHandler"/> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
https://www.springframework.org/schema/websocket/spring-websocket.xsd"> |
||||
|
||||
<websocket:handlers> |
||||
<websocket:mapping path="/myHandler" handler="myHandler"/> |
||||
<websocket:handshake-interceptors> |
||||
<bean class="org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor"/> |
||||
</websocket:handshake-interceptors> |
||||
</websocket:handlers> |
||||
|
||||
<bean id="myHandler" class="org.springframework.docs.web.websocket.websocketserverhandler.MyHandler"/> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd"> |
||||
|
||||
<!-- tag::snippet[] --> |
||||
<bean class="org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean"> |
||||
<property name="maxTextMessageBufferSize" value="8192"/> |
||||
<property name="maxBinaryMessageBufferSize" value="8192"/> |
||||
</bean> |
||||
<!-- end::snippet[] --> |
||||
|
||||
</beans> |
||||
|
||||
Loading…
Reference in new issue