|
|
@ -26,6 +26,7 @@ import java.util.Set;
|
|
|
|
import javax.xml.transform.TransformerFactory;
|
|
|
|
import javax.xml.transform.TransformerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.PropertyMapper;
|
|
|
|
import org.springframework.oxm.Marshaller;
|
|
|
|
import org.springframework.oxm.Marshaller;
|
|
|
|
import org.springframework.oxm.Unmarshaller;
|
|
|
|
import org.springframework.oxm.Unmarshaller;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
@ -76,9 +77,17 @@ public class WebServiceTemplateBuilder {
|
|
|
|
private final WebServiceMessageFactory messageFactory;
|
|
|
|
private final WebServiceMessageFactory messageFactory;
|
|
|
|
|
|
|
|
|
|
|
|
public WebServiceTemplateBuilder(WebServiceTemplateCustomizer... customizers) {
|
|
|
|
public WebServiceTemplateBuilder(WebServiceTemplateCustomizer... customizers) {
|
|
|
|
this(true, Collections.emptySet(), Collections.emptySet(),
|
|
|
|
this.detectHttpMessageSender = true;
|
|
|
|
append(Collections.<WebServiceTemplateCustomizer>emptySet(), customizers),
|
|
|
|
this.interceptors = null;
|
|
|
|
new WebServiceMessageSenders(), null, null, null, null, null);
|
|
|
|
this.internalCustomizers = null;
|
|
|
|
|
|
|
|
this.customizers = Collections
|
|
|
|
|
|
|
|
.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(customizers)));
|
|
|
|
|
|
|
|
this.messageSenders = new WebServiceMessageSenders();
|
|
|
|
|
|
|
|
this.marshaller = null;
|
|
|
|
|
|
|
|
this.unmarshaller = null;
|
|
|
|
|
|
|
|
this.destinationProvider = null;
|
|
|
|
|
|
|
|
this.transformerFactoryClass = null;
|
|
|
|
|
|
|
|
this.messageFactory = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private WebServiceTemplateBuilder(boolean detectHttpMessageSender,
|
|
|
|
private WebServiceTemplateBuilder(boolean detectHttpMessageSender,
|
|
|
@ -89,11 +98,11 @@ public class WebServiceTemplateBuilder {
|
|
|
|
Unmarshaller unmarshaller, DestinationProvider destinationProvider,
|
|
|
|
Unmarshaller unmarshaller, DestinationProvider destinationProvider,
|
|
|
|
Class<? extends TransformerFactory> transformerFactoryClass,
|
|
|
|
Class<? extends TransformerFactory> transformerFactoryClass,
|
|
|
|
WebServiceMessageFactory messageFactory) {
|
|
|
|
WebServiceMessageFactory messageFactory) {
|
|
|
|
|
|
|
|
this.detectHttpMessageSender = detectHttpMessageSender;
|
|
|
|
this.interceptors = interceptors;
|
|
|
|
this.interceptors = interceptors;
|
|
|
|
this.internalCustomizers = internalCustomizers;
|
|
|
|
this.internalCustomizers = internalCustomizers;
|
|
|
|
this.customizers = customizers;
|
|
|
|
this.customizers = customizers;
|
|
|
|
this.messageSenders = messageSenders;
|
|
|
|
this.messageSenders = messageSenders;
|
|
|
|
this.detectHttpMessageSender = detectHttpMessageSender;
|
|
|
|
|
|
|
|
this.marshaller = marshaller;
|
|
|
|
this.marshaller = marshaller;
|
|
|
|
this.unmarshaller = unmarshaller;
|
|
|
|
this.unmarshaller = unmarshaller;
|
|
|
|
this.destinationProvider = destinationProvider;
|
|
|
|
this.destinationProvider = destinationProvider;
|
|
|
@ -357,7 +366,7 @@ public class WebServiceTemplateBuilder {
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
public WebServiceTemplateBuilder setWebServiceMessageFactory(
|
|
|
|
public WebServiceTemplateBuilder setWebServiceMessageFactory(
|
|
|
|
WebServiceMessageFactory messageFactory) {
|
|
|
|
WebServiceMessageFactory messageFactory) {
|
|
|
|
Assert.notNull(messageFactory, "messageFactory must not be null");
|
|
|
|
Assert.notNull(messageFactory, "MessageFactory must not be null");
|
|
|
|
return new WebServiceTemplateBuilder(this.detectHttpMessageSender,
|
|
|
|
return new WebServiceTemplateBuilder(this.detectHttpMessageSender,
|
|
|
|
this.interceptors, this.internalCustomizers, this.customizers,
|
|
|
|
this.interceptors, this.internalCustomizers, this.customizers,
|
|
|
|
this.messageSenders, this.marshaller, this.unmarshaller,
|
|
|
|
this.messageSenders, this.marshaller, this.unmarshaller,
|
|
|
@ -425,7 +434,6 @@ public class WebServiceTemplateBuilder {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the default URI to be used on operations that do not have a URI parameter.
|
|
|
|
* Set the default URI to be used on operations that do not have a URI parameter.
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* Typically, either this property is set, or
|
|
|
|
* Typically, either this property is set, or
|
|
|
|
* {@link #setDestinationProvider(DestinationProvider)}, but not both.
|
|
|
|
* {@link #setDestinationProvider(DestinationProvider)}, but not both.
|
|
|
|
* @param defaultUri the destination provider URI to be used on operations that do not
|
|
|
|
* @param defaultUri the destination provider URI to be used on operations that do not
|
|
|
@ -439,10 +447,8 @@ public class WebServiceTemplateBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the {@link DestinationProvider} to use
|
|
|
|
* Set the {@link DestinationProvider} to use. Typically, either this property is set,
|
|
|
|
* <p>
|
|
|
|
* or {@link #setDefaultUri(String)}, but not both.
|
|
|
|
* Typically, either this property is set, or {@link #setDefaultUri(String)}, but not
|
|
|
|
|
|
|
|
* both.
|
|
|
|
|
|
|
|
* @param destinationProvider the destination provider to be used on operations that
|
|
|
|
* @param destinationProvider the destination provider to be used on operations that
|
|
|
|
* do not have a URI parameter.
|
|
|
|
* do not have a URI parameter.
|
|
|
|
* @return a new builder instance.
|
|
|
|
* @return a new builder instance.
|
|
|
@ -450,7 +456,7 @@ public class WebServiceTemplateBuilder {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public WebServiceTemplateBuilder setDestinationProvider(
|
|
|
|
public WebServiceTemplateBuilder setDestinationProvider(
|
|
|
|
DestinationProvider destinationProvider) {
|
|
|
|
DestinationProvider destinationProvider) {
|
|
|
|
Assert.notNull(destinationProvider, "destinationProvider must not be null");
|
|
|
|
Assert.notNull(destinationProvider, "DestinationProvider must not be null");
|
|
|
|
return new WebServiceTemplateBuilder(this.detectHttpMessageSender,
|
|
|
|
return new WebServiceTemplateBuilder(this.detectHttpMessageSender,
|
|
|
|
this.interceptors, this.internalCustomizers, this.customizers,
|
|
|
|
this.interceptors, this.internalCustomizers, this.customizers,
|
|
|
|
this.messageSenders, this.marshaller, this.unmarshaller,
|
|
|
|
this.messageSenders, this.marshaller, this.unmarshaller,
|
|
|
@ -492,49 +498,45 @@ public class WebServiceTemplateBuilder {
|
|
|
|
* @see #build(Class)
|
|
|
|
* @see #build(Class)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public <T extends WebServiceTemplate> T configure(T webServiceTemplate) {
|
|
|
|
public <T extends WebServiceTemplate> T configure(T webServiceTemplate) {
|
|
|
|
Assert.notNull(webServiceTemplate, "webServiceTemplate must not be null");
|
|
|
|
Assert.notNull(webServiceTemplate, "WebServiceTemplate must not be null");
|
|
|
|
configureMessageSenders(webServiceTemplate);
|
|
|
|
configureMessageSenders(webServiceTemplate);
|
|
|
|
if (!CollectionUtils.isEmpty(this.internalCustomizers)) {
|
|
|
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
for (WebServiceTemplateCustomizer internalCustomizer : this.internalCustomizers) {
|
|
|
|
applyCustomizers(webServiceTemplate, this.internalCustomizers);
|
|
|
|
internalCustomizer.customize(webServiceTemplate);
|
|
|
|
map.from(() -> this.marshaller).to(webServiceTemplate::setMarshaller);
|
|
|
|
}
|
|
|
|
map.from(() -> this.unmarshaller).to(webServiceTemplate::setUnmarshaller);
|
|
|
|
}
|
|
|
|
map.from(() -> this.destinationProvider)
|
|
|
|
if (this.marshaller != null) {
|
|
|
|
.to(webServiceTemplate::setDestinationProvider);
|
|
|
|
webServiceTemplate.setMarshaller(this.marshaller);
|
|
|
|
map.from(() -> this.transformerFactoryClass)
|
|
|
|
}
|
|
|
|
.to(webServiceTemplate::setTransformerFactoryClass);
|
|
|
|
if (this.unmarshaller != null) {
|
|
|
|
map.from(() -> this.messageFactory).to(webServiceTemplate::setMessageFactory);
|
|
|
|
webServiceTemplate.setUnmarshaller(this.unmarshaller);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.destinationProvider != null) {
|
|
|
|
|
|
|
|
webServiceTemplate.setDestinationProvider(this.destinationProvider);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.transformerFactoryClass != null) {
|
|
|
|
|
|
|
|
webServiceTemplate.setTransformerFactoryClass(this.transformerFactoryClass);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.messageFactory != null) {
|
|
|
|
|
|
|
|
webServiceTemplate.setMessageFactory(this.messageFactory);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(this.interceptors)) {
|
|
|
|
if (!CollectionUtils.isEmpty(this.interceptors)) {
|
|
|
|
webServiceTemplate.setInterceptors(
|
|
|
|
Set<ClientInterceptor> merged = new LinkedHashSet<>(this.interceptors);
|
|
|
|
append(this.interceptors, webServiceTemplate.getInterceptors())
|
|
|
|
if (webServiceTemplate.getInterceptors() != null) {
|
|
|
|
.toArray(new ClientInterceptor[0]));
|
|
|
|
merged.addAll(Arrays.asList(webServiceTemplate.getInterceptors()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(this.customizers)) {
|
|
|
|
|
|
|
|
for (WebServiceTemplateCustomizer customizer : this.customizers) {
|
|
|
|
|
|
|
|
customizer.customize(webServiceTemplate);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
webServiceTemplate.setInterceptors(merged.toArray(new ClientInterceptor[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applyCustomizers(webServiceTemplate, this.customizers);
|
|
|
|
return webServiceTemplate;
|
|
|
|
return webServiceTemplate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void applyCustomizers(WebServiceTemplate webServiceTemplate,
|
|
|
|
|
|
|
|
Set<WebServiceTemplateCustomizer> customizers) {
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(customizers)) {
|
|
|
|
|
|
|
|
for (WebServiceTemplateCustomizer internalCustomizer : customizers) {
|
|
|
|
|
|
|
|
internalCustomizer.customize(webServiceTemplate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private <T extends WebServiceTemplate> void configureMessageSenders(
|
|
|
|
private <T extends WebServiceTemplate> void configureMessageSenders(
|
|
|
|
T webServiceTemplate) {
|
|
|
|
T webServiceTemplate) {
|
|
|
|
if (this.messageSenders.isOnlyAdditional() && this.detectHttpMessageSender) {
|
|
|
|
if (this.messageSenders.isOnlyAdditional() && this.detectHttpMessageSender) {
|
|
|
|
Set<WebServiceMessageSender> mergedMessageSenders = append(
|
|
|
|
Set<WebServiceMessageSender> merged = append(
|
|
|
|
this.messageSenders.getMessageSenders(),
|
|
|
|
this.messageSenders.getMessageSenders(),
|
|
|
|
new HttpWebServiceMessageSenderBuilder().build());
|
|
|
|
new HttpWebServiceMessageSenderBuilder().build());
|
|
|
|
webServiceTemplate.setMessageSenders(
|
|
|
|
webServiceTemplate
|
|
|
|
mergedMessageSenders.toArray(new WebServiceMessageSender[0]));
|
|
|
|
.setMessageSenders(merged.toArray(new WebServiceMessageSender[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!CollectionUtils.isEmpty(this.messageSenders.getMessageSenders())) {
|
|
|
|
else if (!CollectionUtils.isEmpty(this.messageSenders.getMessageSenders())) {
|
|
|
|
webServiceTemplate.setMessageSenders(this.messageSenders.getMessageSenders()
|
|
|
|
webServiceTemplate.setMessageSenders(this.messageSenders.getMessageSenders()
|
|
|
@ -542,15 +544,8 @@ public class WebServiceTemplateBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> Set<T> append(Set<T> set, T[] additions) {
|
|
|
|
private <T> Set<T> append(Set<T> set, T addition) {
|
|
|
|
return append(set, additions != null
|
|
|
|
return append(set, Collections.singleton(addition));
|
|
|
|
? new LinkedHashSet<>(Arrays.asList(additions)) : Collections.emptySet());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> Set<T> append(Set<T> set, T addition) {
|
|
|
|
|
|
|
|
Set<T> result = new LinkedHashSet<>(set != null ? set : Collections.emptySet());
|
|
|
|
|
|
|
|
result.add(addition);
|
|
|
|
|
|
|
|
return Collections.unmodifiableSet(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> Set<T> append(Set<T> set, Collection<? extends T> additions) {
|
|
|
|
private static <T> Set<T> append(Set<T> set, Collection<? extends T> additions) {
|
|
|
|