Skip to content

Commit 156ba5a

Browse files
artembilangaryrussell
authored andcommitted
GH-3688: Fix WS DSL for proper values propagation
Fixes #3688 The `WebServiceTemplate` is populated with some defaults from its ctor. We should rely on the target default template values as much as possible and don't override them to `null` if end-user doesn't ask about that explicitly * Fix `BaseWsOutboundGatewaySpec` extensions to populate values to the target gateway only if they are not null - therefore provided by end-user * If end-user wants them explicitly `null`, it is better to do that via externally configured template. See overloaded variants for DSL: `Ws.marshallingOutboundGateway(WebServiceTemplate)` and `Ws.simpleOutboundGateway(WebServiceTemplate)` **Cherry-pick to `5.4.x` & `5.3.x`**
1 parent 346ebd7 commit 156ba5a

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

spring-integration-ws/src/main/java/org/springframework/integration/ws/dsl/BaseWsOutboundGatewaySpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ protected E doGet() {
158158
protected E assemble(E gateway) {
159159
gateway.setUriVariableExpressions(this.uriVariableExpressions);
160160
JavaUtils.INSTANCE
161-
.acceptIfNotNull(this.headerMapper, gateway::setHeaderMapper);
162-
gateway.setEncodingMode(this.encodingMode);
161+
.acceptIfNotNull(this.headerMapper, gateway::setHeaderMapper)
162+
.acceptIfNotNull(this.encodingMode, gateway::setEncodingMode);
163163
gateway.setIgnoreEmptyResponses(this.ignoreEmptyResponses);
164164
gateway.setRequestCallback(this.requestCallback);
165165
return gateway;

spring-integration-ws/src/main/java/org/springframework/integration/ws/dsl/MarshallingWsOutboundGatewaySpec.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020

21+
import org.springframework.integration.JavaUtils;
2122
import org.springframework.integration.ws.MarshallingWebServiceOutboundGateway;
2223
import org.springframework.oxm.Marshaller;
2324
import org.springframework.oxm.Unmarshaller;
@@ -141,9 +142,10 @@ protected MarshallingWebServiceOutboundGateway create() {
141142
@Override
142143
protected MarshallingWebServiceOutboundGateway assemble(MarshallingWebServiceOutboundGateway gateway) {
143144
MarshallingWebServiceOutboundGateway assembled = super.assemble(gateway);
144-
assembled.setFaultMessageResolver(this.faultMessageResolver);
145-
assembled.setMessageSenders(this.messageSenders);
146-
assembled.setInterceptors(this.gatewayInterceptors);
145+
JavaUtils.INSTANCE
146+
.acceptIfNotNull(this.faultMessageResolver, assembled::setFaultMessageResolver)
147+
.acceptIfNotNull(this.messageSenders, assembled::setMessageSenders)
148+
.acceptIfNotNull(this.gatewayInterceptors, assembled::setInterceptors);
147149
return assembled;
148150
}
149151

spring-integration-ws/src/main/java/org/springframework/integration/ws/dsl/SimpleWsOutboundGatewaySpec.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020

21+
import org.springframework.integration.JavaUtils;
2122
import org.springframework.integration.ws.SimpleWebServiceOutboundGateway;
2223
import org.springframework.ws.WebServiceMessageFactory;
2324
import org.springframework.ws.client.core.FaultMessageResolver;
@@ -100,7 +101,7 @@ public static class SimpleWsOutboundGatewayNoTemplateSpec
100101

101102
protected SourceExtractor<?> sourceExtractor; // NOSONAR
102103

103-
private boolean extractPayload;
104+
private boolean extractPayload = true;
104105

105106
/**
106107
* Configure a {@link SourceExtractor} to use.
@@ -181,9 +182,10 @@ protected SimpleWebServiceOutboundGateway create() {
181182
@Override
182183
protected SimpleWebServiceOutboundGateway assemble(SimpleWebServiceOutboundGateway gateway) {
183184
SimpleWebServiceOutboundGateway assembled = super.assemble(gateway);
184-
assembled.setFaultMessageResolver(this.faultMessageResolver);
185-
assembled.setMessageSenders(this.messageSenders);
186-
assembled.setInterceptors(this.gatewayInterceptors);
185+
JavaUtils.INSTANCE
186+
.acceptIfNotNull(this.faultMessageResolver, assembled::setFaultMessageResolver)
187+
.acceptIfNotNull(this.messageSenders, assembled::setMessageSenders)
188+
.acceptIfNotNull(this.gatewayInterceptors, assembled::setInterceptors);
187189
assembled.setExtractPayload(this.extractPayload);
188190
return assembled;
189191
}

spring-integration-ws/src/test/java/org/springframework/integration/ws/dsl/WsDslTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -96,7 +96,6 @@ void marshallingOutbound() {
9696
.marshaller(marshaller)
9797
.unmarshaller(unmarshaller)
9898
.messageFactory(messageFactory)
99-
.encodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY)
10099
.faultMessageResolver(faultMessageResolver)
101100
.headerMapper(headerMapper)
102101
.ignoreEmptyResponses(true)
@@ -172,7 +171,6 @@ void marshallingOutboundTemplate() {
172171
MarshallingWebServiceOutboundGateway gateway =
173172
Ws.marshallingOutboundGateway(template)
174173
.uri(uri)
175-
.encodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY)
176174
.headerMapper(headerMapper)
177175
.ignoreEmptyResponses(true)
178176
.requestCallback(requestCallback)
@@ -182,6 +180,10 @@ void marshallingOutboundTemplate() {
182180
assertThat(TestUtils.getPropertyValue(gateway, "headerMapper")).isSameAs(headerMapper);
183181
assertThat(TestUtils.getPropertyValue(gateway, "requestCallback")).isSameAs(requestCallback);
184182
assertThat(TestUtils.getPropertyValue(gateway, "uriVariableExpressions")).isEqualTo(uriVariableExpressions);
183+
assertThat(
184+
TestUtils.getPropertyValue(gateway, "uriFactory.encodingMode",
185+
DefaultUriBuilderFactory.EncodingMode.class))
186+
.isEqualTo(DefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES);
185187
}
186188

187189
@Test

0 commit comments

Comments
 (0)