Skip to content

Commit e2b6618

Browse files
committed
RSocketOutbound refinements; resolve deprecations
* Use properly `cache()` for the `Mono` in the `ClientRSocketConnector` * Don't require a `publisherElementTypeExpression` in the `RSocketOutboundGateway`: the target element type is determined automatically in the `DefaultRequestSpec.toResponseSpec()` * SF has deprecated `MediaType.APPLICATION_JSON_UTF8`: fix all its usage in favor of recommendations to use the `MediaType.APPLICATION_JSON` instead * Also fix plain `application/json;charset=UTF-8` literals to use `MediaType.APPLICATION_JSON` instead
1 parent 6d7bc1f commit e2b6618

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

spring-integration-http/src/test/java/org/springframework/integration/http/management/IntegrationGraphControllerTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public void setup() {
8282
public void testIntegrationGraphGet() throws Exception {
8383
this.mockMvc.perform(get("/testIntegration")
8484
.header(HttpHeaders.ORIGIN, "https://foo.bar.com")
85-
.accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
85+
.accept(MediaType.APPLICATION_JSON))
8686
.andExpect(status().isOk())
87-
.andExpect(content().contentType("application/json;charset=UTF-8"))
87+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
8888
.andExpect(handler().handlerType(IntegrationGraphController.class))
8989
.andExpect(handler().methodName("getGraph"))
9090
.andExpect(jsonPath("$.nodes..name")

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public void afterPropertiesSet() {
101101
.dataMimeType(this.dataMimeType.toString());
102102
this.factoryConfigurer.accept(clientFactory);
103103
clientFactory.setupPayload(this.connectPayload);
104-
this.rsocketMono = clientFactory.transport(this.clientTransport).start();
104+
this.rsocketMono = clientFactory.transport(this.clientTransport).start().cache();
105105
}
106106

107107
public void connect() {
108-
this.rsocketMono.cache().subscribe();
108+
this.rsocketMono.subscribe();
109109
}
110110

111111
public Mono<RSocketRequester> getRSocketRequester() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.rsocket.inbound;
18+
19+
import java.util.Arrays;
20+
21+
import org.springframework.integration.gateway.MessagingGatewaySupport;
22+
import org.springframework.messaging.Message;
23+
import org.springframework.messaging.MessageDeliveryException;
24+
import org.springframework.messaging.ReactiveMessageHandler;
25+
import org.springframework.util.Assert;
26+
27+
import reactor.core.publisher.Mono;
28+
29+
/**
30+
*
31+
* @author Artem Bilan
32+
*
33+
* @since 5.2
34+
*/
35+
public class RSocketInboundGateway extends MessagingGatewaySupport implements ReactiveMessageHandler {
36+
37+
private final String[] path;
38+
39+
public RSocketInboundGateway(String... path) {
40+
Assert.notNull(path, "'path' must not be null");
41+
this.path = path;
42+
}
43+
44+
45+
@Override
46+
public Mono<Void> handleMessage(Message<?> message) {
47+
if (!isRunning()) {
48+
return Mono.error(new MessageDeliveryException(message,
49+
"The RSocket Inbound Gateway '" + getComponentName() + "' is stopped; " +
50+
"service for path " + Arrays.toString(this.path) + " is not available at the moment."));
51+
}
52+
return null;
53+
}
54+
55+
}

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/outbound/RSocketOutboundGateway.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class RSocketOutboundGateway extends AbstractReplyProducingMessageHandler
7272

7373
private Expression commandExpression = new ValueExpression<>(Command.requestResponse);
7474

75-
private Expression publisherElementTypeExpression = new ValueExpression<>(String.class);
75+
private Expression publisherElementTypeExpression;
7676

7777
private Expression expectedResponseTypeExpression = new ValueExpression<>(String.class);
7878

@@ -181,7 +181,7 @@ protected void doInit() {
181181
super.doInit();
182182
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
183183
if (this.clientRSocketConnector != null) {
184-
this.rsocketRequesterMono = this.clientRSocketConnector.getRSocketRequester().cache();
184+
this.rsocketRequesterMono = this.clientRSocketConnector.getRSocketRequester();
185185
}
186186
}
187187

@@ -220,8 +220,7 @@ private RSocketRequester.ResponseSpec createResponseSpec(RSocketRequester.Reques
220220
Message<?> requestMessage) {
221221

222222
Object payload = requestMessage.getPayload();
223-
224-
if (payload instanceof Publisher<?>) {
223+
if (payload instanceof Publisher<?> && this.publisherElementTypeExpression != null) {
225224
Object publisherElementType = evaluateExpressionForType(requestMessage, this.publisherElementTypeExpression,
226225
"publisherElementTypeExpression");
227226
return responseSpecForPublisher(requestSpec, (Publisher<?>) payload, publisherElementType);

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpointTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testSimpleGet() {
7676
@Test
7777
public void testJsonResult() {
7878
this.webTestClient.get().uri("/persons")
79-
.accept(MediaType.APPLICATION_JSON_UTF8)
79+
.accept(MediaType.APPLICATION_JSON)
8080
.exchange()
8181
.expectStatus().isOk()
8282
.expectBody()

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/management/IntegrationGraphControllerTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public void testIntegrationGraphGet() {
5353
.build();
5454

5555
webTestClient.get().uri("/testIntegration")
56-
.accept(MediaType.APPLICATION_JSON_UTF8)
56+
.accept(MediaType.APPLICATION_JSON)
5757
.exchange()
5858
.expectStatus().isOk()
59-
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
59+
.expectHeader().contentType(MediaType.APPLICATION_JSON)
6060
.expectBody()
6161
.jsonPath("$.nodes..name").isArray()
6262
.jsonPath("$.contentDescriptor.name").isEqualTo("testApplication")

0 commit comments

Comments
 (0)