Commit c9df1c55 authored by dnosan's avatar dnosan Committed by Stephane Nicoll

Add auto-configuration for WebServiceTemplate

See gh-12707
parent 283ceaa0
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.webservices.client;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.webservices.client.WebServiceTemplateBuilder;
import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import org.springframework.util.CollectionUtils;
import org.springframework.ws.client.core.WebServiceTemplate;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link WebServiceTemplate}.
*
* @author Dmytro Nosan
*/
@Configuration
@ConditionalOnClass({ WebServiceTemplateBuilder.class, WebServiceTemplate.class,
Unmarshaller.class, Marshaller.class })
public class WebServiceTemplateAutoConfiguration {
private final ObjectProvider<List<WebServiceTemplateCustomizer>> webServiceTemplateCustomizers;
public WebServiceTemplateAutoConfiguration(
ObjectProvider<List<WebServiceTemplateCustomizer>> webServiceTemplateCustomizers) {
this.webServiceTemplateCustomizers = webServiceTemplateCustomizers;
}
@Bean
@ConditionalOnMissingBean
public WebServiceTemplateBuilder webServiceTemplateBuilder() {
WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
List<WebServiceTemplateCustomizer> customizers = this.webServiceTemplateCustomizers
.getIfAvailable();
if (!CollectionUtils.isEmpty(customizers)) {
customizers = new ArrayList<>(customizers);
AnnotationAwareOrderComparator.sort(customizers);
builder = builder.setCustomizers(customizers);
}
return builder;
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Spring Web Services Clients.
*/
package org.springframework.boot.autoconfigure.webservices.client;
......@@ -126,7 +126,8 @@ org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration
# Failure analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
......
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.webservices.client;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.webservices.client.WebServiceTemplateBuilder;
import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.core.WebServiceTemplate;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebServiceTemplateAutoConfiguration
* WebServiceTemplateAutoConfiguration}.
*
* @author Dmytro Nosan
*/
public class WebServiceTemplateAutoConfigurationTests {
private AnnotationConfigApplicationContext context;
@After
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void webServiceTemplateShouldNotHaveMarshallerAndUnmarshaller() {
load(WebServiceTemplateConfig.class);
WebServiceTemplate webServiceTemplate = this.context
.getBean(WebServiceTemplate.class);
assertThat(webServiceTemplate.getUnmarshaller()).isNull();
assertThat(webServiceTemplate.getMarshaller()).isNull();
}
@Test
public void webServiceTemplateShouldUserCustomBuilder() {
load(CustomWebServiceTemplateBuilderConfig.class, WebServiceTemplateConfig.class);
WebServiceTemplate webServiceTemplate = this.context
.getBean(WebServiceTemplate.class);
assertThat(webServiceTemplate.getMarshaller()).isNotNull();
}
@Test
public void webServiceTemplateShouldApplyCustomizer() {
load(WebServiceTemplateCustomizerConfig.class, WebServiceTemplateConfig.class);
WebServiceTemplate webServiceTemplate = this.context
.getBean(WebServiceTemplate.class);
assertThat(webServiceTemplate.getUnmarshaller()).isNotNull();
}
@Test
public void builderShouldBeFreshForEachUse() {
load(DirtyWebServiceTemplateConfig.class);
}
private void load(Class<?>... config) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(config);
ctx.register(WebServiceTemplateAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
}
@Configuration
static class WebServiceTemplateConfig {
@Bean
public WebServiceTemplate webServiceTemplate(WebServiceTemplateBuilder builder) {
return builder.build();
}
}
@Configuration
static class DirtyWebServiceTemplateConfig {
@Bean
public WebServiceTemplate webServiceTemplateOne(
WebServiceTemplateBuilder builder) {
try {
return builder.build();
}
finally {
breakBuilderOnNextCall(builder);
}
}
@Bean
public WebServiceTemplate webServiceTemplateTwo(
WebServiceTemplateBuilder builder) {
try {
return builder.build();
}
finally {
breakBuilderOnNextCall(builder);
}
}
private void breakBuilderOnNextCall(WebServiceTemplateBuilder builder) {
builder.addCustomizers((webServiceTemplate) -> {
throw new IllegalStateException();
});
}
}
@Configuration
static class CustomWebServiceTemplateBuilderConfig {
@Bean
public WebServiceTemplateBuilder webServiceTemplateBuilder() {
return new WebServiceTemplateBuilder().setMarshaller(new Jaxb2Marshaller());
}
}
@Configuration
static class WebServiceTemplateCustomizerConfig {
@Bean
public WebServiceTemplateCustomizer webServiceTemplateCustomizer() {
return (ws) -> ws.setUnmarshaller(new Jaxb2Marshaller());
}
}
}
......@@ -5634,7 +5634,6 @@ The following code shows a typical example:
----
[[boot-features-webclient-customization]]
=== WebClient Customization
There are three main approaches to `WebClient` customization, depending on how broadly you
......@@ -5653,6 +5652,35 @@ the point of injection.
Finally, you can fall back to the original API and use `WebClient.create()`. In that case,
no auto-configuration or `WebClientCustomizer` is applied.
[[boot-features-webservicetemplate]]
== Calling Web Services with `WebServiceTemplate`
If you need to call remote WEB services from your application, you can use the Spring
Framework's {spring-webservices-reference}#client-web-service-template[`WebServiceTemplate`] class. Since
`WebServiceTemplate` instances often need to be customized before being used, Spring Boot does
not provide any single auto-configured `WebServiceTemplate` bean. It does, however,
auto-configure a `WebServiceTemplateBuilder`, which can be used to create `WebServiceTemplate`
instances when needed.
The following code shows a typical example:
[source,java,indent=0]
----
@Service
public class MyService {
private final WebServiceTemplate webServiceTemplate;
public MyService(WebServiceTemplateBuilder webServiceTemplateBuilder) {
this.webServiceTemplate = webServiceTemplateBuilder.build();
}
public DetailsResp someCall(DetailsReq detailsReq) {
return (DetailsResp) this.webServiceTemplate.marshalSendAndReceive(detailsReq, new SoapActionCallback(ACTION));
}
}
----
[[boot-features-validation]]
......
......@@ -245,6 +245,16 @@
<artifactId>spring-orm</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
......
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import org.springframework.ws.client.core.WebServiceTemplate;
/**
* Callback interface that can be used to customize a {@link WebServiceTemplate}.
*
* @author Dmytro Nosan
*/
public interface WebServiceTemplateCustomizer {
/**
* Callback to customize a {@link WebServiceTemplate} instance.
* @param webServiceTemplate the template to customize
*/
void customize(WebServiceTemplate webServiceTemplate);
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Web Services client utilities.
*/
package org.springframework.boot.webservices.client;
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.ws.transport.WebServiceMessageSender;
import org.springframework.ws.transport.http.ClientHttpRequestMessageSender;
/**
* Tests for
* {@link org.springframework.boot.webservices.client.WebServiceTemplateBuilder}.
*
* @author Dmytro Nosan
*/
public class WebServiceTemplateBuilderCustomsMessageSenderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void unknownSenderReadTimeout() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("with 'readTimeout'. Please use a custom customizer.");
this.thrown.expectMessage("There is no way to customize");
this.builder.setReadTimeout(3000).setWebServiceMessageSender(
() -> Mockito.mock(WebServiceMessageSender.class)).build();
}
@Test
public void unknownSenderConnectionTimeout() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(
"with 'connectionTimeout'. Please use a custom customizer.");
this.thrown.expectMessage("There is no way to customize");
this.builder.setConnectionTimeout(3000).setWebServiceMessageSender(
() -> Mockito.mock(WebServiceMessageSender.class)).build();
}
@Test
public void unknownRequestFactoryReadTimeout() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("with 'readTimeout'. Please use a custom customizer.");
this.thrown.expectMessage("There is no way to customize");
this.builder.setReadTimeout(3000)
.setWebServiceMessageSender(() -> new ClientHttpRequestMessageSender(
Mockito.mock(ClientHttpRequestFactory.class)))
.build();
}
@Test
public void unknownRequestFactoryConnectionTimeout() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(
"with 'connectionTimeout'. Please use a custom customizer.");
this.thrown.expectMessage("There is no way to customize");
this.builder.setConnectionTimeout(3000)
.setWebServiceMessageSender(() -> new ClientHttpRequestMessageSender(
Mockito.mock(ClientHttpRequestFactory.class)))
.build();
}
@Test
public void shouldBuildWithoutTimeouts() {
this.builder.setWebServiceMessageSender(
() -> Mockito.mock(WebServiceMessageSender.class)).build();
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import org.apache.http.client.config.RequestConfig;
import org.junit.Test;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.transport.http.ClientHttpRequestMessageSender;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebServiceTemplateBuilder}.
*
* @author Dmytro Nosan
*/
public class WebServiceTemplateBuilderHttpComponentsClientHttpRequestFactoryTests {
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void setTimeout() {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
ClientHttpRequestMessageSender sender = new ClientHttpRequestMessageSender(
new BufferingClientHttpRequestFactory(factory));
this.builder.setConnectionTimeout(5000).setReadTimeout(2000)
.setWebServiceMessageSender(() -> sender).build();
RequestConfig requestConfig = (RequestConfig) ReflectionTestUtils
.getField(factory, "requestConfig");
assertThat(requestConfig).isNotNull();
assertThat(requestConfig.getConnectTimeout()).isEqualTo(5000);
assertThat(requestConfig.getSocketTimeout()).isEqualTo(2000);
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import org.apache.http.client.HttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.junit.Test;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for
* {@link org.springframework.boot.webservices.client.WebServiceTemplateBuilder}. This
* test class check that builder will create HttpComponents by default if apache client is
* present in the classpath.
*
* @author Dmytro Nosan
*/
@SuppressWarnings("deprecation")
public class WebServiceTemplateBuilderHttpComponentsMessageSenderTests {
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void build() {
WebServiceTemplate webServiceTemplate = new WebServiceTemplateBuilder().build();
assertThat(webServiceTemplate.getMessageSenders()).hasSize(1);
assertThat(webServiceTemplate.getMessageSenders()[0])
.isInstanceOf(HttpComponentsMessageSender.class);
}
@Test
public void setTimeout() {
HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
HttpClient httpClient = sender.getHttpClient();
this.builder.setConnectionTimeout(5000).setReadTimeout(2000)
.setWebServiceMessageSender(() -> sender).build();
assertThat(HttpConnectionParams.getConnectionTimeout(httpClient.getParams()))
.isEqualTo(5000);
assertThat(HttpConnectionParams.getSoTimeout(httpClient.getParams()))
.isEqualTo(2000);
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import java.time.Duration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebServiceTemplateBuilder}. This test class check that builder will
* create HttpUrlConnectionMessageSender If Ok-http and Apache client are not present in
* the classpath.
*
* @author Dmytro Nosan
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "httpclient-*.jar", "okhttp-*.jar" })
public class WebServiceTemplateBuilderHttpUrlConnectionMessageSenderTests {
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void build() {
WebServiceTemplate webServiceTemplate = this.builder.build();
assertThat(webServiceTemplate.getMessageSenders()).hasSize(1);
assertThat(webServiceTemplate.getMessageSenders()[0])
.isInstanceOf(HttpUrlConnectionMessageSender.class);
}
@Test
public void setTimeout() {
HttpUrlConnectionMessageSender sender = new HttpUrlConnectionMessageSender();
this.builder.setConnectionTimeout(5000).setReadTimeout(2000)
.setWebServiceMessageSender(() -> sender).build();
assertThat(ReflectionTestUtils.getField(sender, "connectionTimeout"))
.isEqualTo(Duration.ofMillis(5000));
assertThat(ReflectionTestUtils.getField(sender, "readTimeout"))
.isEqualTo(Duration.ofMillis(2000));
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import okhttp3.OkHttpClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.http.ClientHttpRequestMessageSender;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebServiceTemplateBuilder}. This test class check that builder will
* create ClientHttpRequestMessageSender (OkHttp3ClientHttpRequestFactory) if apache
* client is not present in the classpath
*
* @author Dmytro Nosan
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("httpclient-*.jar")
public class WebServiceTemplateBuilderOkHttp3ClientHttpRequestFactoryTests {
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void build() {
WebServiceTemplate webServiceTemplate = this.builder.build();
assertThat(webServiceTemplate.getMessageSenders()).hasSize(1);
assertThat(webServiceTemplate.getMessageSenders()[0])
.isInstanceOf(ClientHttpRequestMessageSender.class);
ClientHttpRequestMessageSender sender = (ClientHttpRequestMessageSender) webServiceTemplate
.getMessageSenders()[0];
assertThat(sender.getRequestFactory())
.isInstanceOf(OkHttp3ClientHttpRequestFactory.class);
}
@Test
public void setTimeout() {
OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();
ClientHttpRequestMessageSender sender = new ClientHttpRequestMessageSender(
new BufferingClientHttpRequestFactory(factory));
this.builder.setConnectionTimeout(5000).setReadTimeout(2000)
.setWebServiceMessageSender(() -> sender).build();
OkHttpClient client = (OkHttpClient) ReflectionTestUtils.getField(factory,
"client");
assertThat(client).isNotNull();
assertThat(client.connectTimeoutMillis()).isEqualTo(5000);
assertThat(client.readTimeoutMillis()).isEqualTo(2000);
}
}
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webservices.client;
import org.junit.Test;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.transport.http.ClientHttpRequestMessageSender;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link WebServiceTemplateBuilder}.
*
* @author Dmytro Nosan
*/
public class WebServiceTemplateBuilderSimpleClientHttpRequestFactoryTests {
private WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder();
@Test
public void setTimeout() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
ClientHttpRequestMessageSender sender = new ClientHttpRequestMessageSender(
new BufferingClientHttpRequestFactory(factory));
this.builder.setConnectionTimeout(5000).setReadTimeout(2000)
.setWebServiceMessageSender(() -> sender).build();
assertThat(ReflectionTestUtils.getField(factory, "connectTimeout"))
.isEqualTo(5000);
assertThat(ReflectionTestUtils.getField(factory, "readTimeout")).isEqualTo(2000);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment