|
24 | 24 |
|
25 | 25 | import io.rsocket.ConnectionSetupPayload;
|
26 | 26 | import io.rsocket.RSocket;
|
| 27 | +import io.rsocket.RSocketFactory; |
27 | 28 | import io.rsocket.SocketAcceptor;
|
28 | 29 | import io.rsocket.frame.FrameType;
|
29 | 30 | import reactor.core.publisher.Mono;
|
30 | 31 |
|
| 32 | +import org.springframework.beans.BeanUtils; |
31 | 33 | import org.springframework.core.ReactiveAdapterRegistry;
|
32 | 34 | import org.springframework.core.annotation.AnnotatedElementUtils;
|
33 | 35 | import org.springframework.core.codec.Decoder;
|
|
40 | 42 | import org.springframework.messaging.handler.annotation.MessageMapping;
|
41 | 43 | import org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler;
|
42 | 44 | import org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler;
|
| 45 | +import org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer; |
43 | 46 | import org.springframework.messaging.rsocket.DefaultMetadataExtractor;
|
44 | 47 | import org.springframework.messaging.rsocket.MetadataExtractor;
|
45 | 48 | import org.springframework.messaging.rsocket.RSocketRequester;
|
@@ -324,10 +327,50 @@ private MessagingRSocket createResponder(ConnectionSetupPayload setupPayload, RS
|
324 | 327 | Assert.notNull(strategies, "No RSocketStrategies. Was afterPropertiesSet not called?");
|
325 | 328 | RSocketRequester requester = RSocketRequester.wrap(rsocket, dataMimeType, metadataMimeType, strategies);
|
326 | 329 |
|
327 |
| - Assert.notNull(this.metadataExtractor, () -> "No MetadataExtractor. Was afterPropertiesSet not called?"); |
| 330 | + Assert.state(this.metadataExtractor != null, |
| 331 | + () -> "No MetadataExtractor. Was afterPropertiesSet not called?"); |
| 332 | + |
| 333 | + Assert.state(getRouteMatcher() != null, |
| 334 | + () -> "No RouteMatcher. Was afterPropertiesSet not called?"); |
328 | 335 |
|
329 | 336 | return new MessagingRSocket(dataMimeType, metadataMimeType, this.metadataExtractor, requester,
|
330 | 337 | this, getRouteMatcher(), strategies);
|
331 | 338 | }
|
332 | 339 |
|
| 340 | + |
| 341 | + public static ClientRSocketFactoryConfigurer clientResponder(Object... handlers) { |
| 342 | + return new ResponderConfigurer(handlers); |
| 343 | + } |
| 344 | + |
| 345 | + |
| 346 | + private static final class ResponderConfigurer implements ClientRSocketFactoryConfigurer { |
| 347 | + |
| 348 | + private final List<Object> handlers = new ArrayList<>(); |
| 349 | + |
| 350 | + @Nullable |
| 351 | + private RSocketStrategies strategies; |
| 352 | + |
| 353 | + |
| 354 | + private ResponderConfigurer(Object... handlers) { |
| 355 | + Assert.notEmpty(handlers, "No handlers"); |
| 356 | + for (Object obj : handlers) { |
| 357 | + this.handlers.add(obj instanceof Class ? BeanUtils.instantiateClass((Class<?>) obj) : obj); |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + @Override |
| 362 | + public void configureWithStrategies(RSocketStrategies strategies) { |
| 363 | + this.strategies = strategies; |
| 364 | + } |
| 365 | + |
| 366 | + @Override |
| 367 | + public void configure(RSocketFactory.ClientRSocketFactory factory) { |
| 368 | + RSocketMessageHandler handler = new RSocketMessageHandler(); |
| 369 | + handler.setHandlers(this.handlers); |
| 370 | + handler.setRSocketStrategies(this.strategies); |
| 371 | + handler.afterPropertiesSet(); |
| 372 | + factory.acceptor(handler.clientResponder()); |
| 373 | + } |
| 374 | + } |
| 375 | + |
333 | 376 | }
|
0 commit comments