Skip to content

Commit

Permalink
GH-3688: Fix WS DSL for proper values propagation
Browse files Browse the repository at this point in the history
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`**
  • Loading branch information
artembilan authored and garyrussell committed Dec 13, 2021
1 parent ad34310 commit db14fad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ protected E doGet() {
protected E assemble(E gateway) {
gateway.setUriVariableExpressions(this.uriVariableExpressions);
JavaUtils.INSTANCE
.acceptIfNotNull(this.headerMapper, gateway::setHeaderMapper);
gateway.setEncodingMode(this.encodingMode);
.acceptIfNotNull(this.headerMapper, gateway::setHeaderMapper)
.acceptIfNotNull(this.encodingMode, gateway::setEncodingMode);
gateway.setIgnoreEmptyResponses(this.ignoreEmptyResponses);
gateway.setRequestCallback(this.requestCallback);
return gateway;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2021 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.
Expand All @@ -18,6 +18,7 @@

import java.util.Arrays;

import org.springframework.integration.JavaUtils;
import org.springframework.integration.ws.MarshallingWebServiceOutboundGateway;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
Expand Down Expand Up @@ -141,9 +142,10 @@ protected MarshallingWebServiceOutboundGateway create() {
@Override
protected MarshallingWebServiceOutboundGateway assemble(MarshallingWebServiceOutboundGateway gateway) {
MarshallingWebServiceOutboundGateway assembled = super.assemble(gateway);
assembled.setFaultMessageResolver(this.faultMessageResolver);
assembled.setMessageSenders(this.messageSenders);
assembled.setInterceptors(this.gatewayInterceptors);
JavaUtils.INSTANCE
.acceptIfNotNull(this.faultMessageResolver, assembled::setFaultMessageResolver)
.acceptIfNotNull(this.messageSenders, assembled::setMessageSenders)
.acceptIfNotNull(this.gatewayInterceptors, assembled::setInterceptors);
return assembled;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2021 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.
Expand All @@ -18,6 +18,7 @@

import java.util.Arrays;

import org.springframework.integration.JavaUtils;
import org.springframework.integration.ws.SimpleWebServiceOutboundGateway;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.FaultMessageResolver;
Expand Down Expand Up @@ -100,7 +101,7 @@ public static class SimpleWsOutboundGatewayNoTemplateSpec

protected SourceExtractor<?> sourceExtractor; // NOSONAR

private boolean extractPayload;
private boolean extractPayload = true;

/**
* Configure a {@link SourceExtractor} to use.
Expand Down Expand Up @@ -181,9 +182,10 @@ protected SimpleWebServiceOutboundGateway create() {
@Override
protected SimpleWebServiceOutboundGateway assemble(SimpleWebServiceOutboundGateway gateway) {
SimpleWebServiceOutboundGateway assembled = super.assemble(gateway);
assembled.setFaultMessageResolver(this.faultMessageResolver);
assembled.setMessageSenders(this.messageSenders);
assembled.setInterceptors(this.gatewayInterceptors);
JavaUtils.INSTANCE
.acceptIfNotNull(this.faultMessageResolver, assembled::setFaultMessageResolver)
.acceptIfNotNull(this.messageSenders, assembled::setMessageSenders)
.acceptIfNotNull(this.gatewayInterceptors, assembled::setInterceptors);
assembled.setExtractPayload(this.extractPayload);
return assembled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2021 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.
Expand Down Expand Up @@ -96,7 +96,6 @@ void marshallingOutbound() {
.marshaller(marshaller)
.unmarshaller(unmarshaller)
.messageFactory(messageFactory)
.encodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY)
.faultMessageResolver(faultMessageResolver)
.headerMapper(headerMapper)
.ignoreEmptyResponses(true)
Expand Down Expand Up @@ -172,7 +171,6 @@ void marshallingOutboundTemplate() {
MarshallingWebServiceOutboundGateway gateway =
Ws.marshallingOutboundGateway(template)
.uri(uri)
.encodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY)
.headerMapper(headerMapper)
.ignoreEmptyResponses(true)
.requestCallback(requestCallback)
Expand All @@ -182,6 +180,10 @@ void marshallingOutboundTemplate() {
assertThat(TestUtils.getPropertyValue(gateway, "headerMapper")).isSameAs(headerMapper);
assertThat(TestUtils.getPropertyValue(gateway, "requestCallback")).isSameAs(requestCallback);
assertThat(TestUtils.getPropertyValue(gateway, "uriVariableExpressions")).isEqualTo(uriVariableExpressions);
assertThat(
TestUtils.getPropertyValue(gateway, "uriFactory.encodingMode",
DefaultUriBuilderFactory.EncodingMode.class))
.isEqualTo(DefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES);
}

@Test
Expand Down

0 comments on commit db14fad

Please sign in to comment.