Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c9df1c55
Commit
c9df1c55
authored
Mar 31, 2018
by
dnosan
Committed by
Stephane Nicoll
Jun 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auto-configuration for WebServiceTemplate
See gh-12707
parent
283ceaa0
Changes
16
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
2378 additions
and
2 deletions
+2378
-2
WebServiceTemplateAutoConfiguration.java
...bservices/client/WebServiceTemplateAutoConfiguration.java
+67
-0
package-info.java
...k/boot/autoconfigure/webservices/client/package-info.java
+20
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+2
-1
WebServiceTemplateAutoConfigurationTests.java
...ices/client/WebServiceTemplateAutoConfigurationTests.java
+150
-0
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+29
-1
pom.xml
spring-boot-project/spring-boot/pom.xml
+10
-0
WebServiceTemplateBuilder.java
...rk/boot/webservices/client/WebServiceTemplateBuilder.java
+1106
-0
WebServiceTemplateCustomizer.java
...boot/webservices/client/WebServiceTemplateCustomizer.java
+34
-0
package-info.java
...springframework/boot/webservices/client/package-info.java
+21
-0
WebServiceTemplateBuilderCustomsMessageSenderTests.java
...t/WebServiceTemplateBuilderCustomsMessageSenderTests.java
+93
-0
WebServiceTemplateBuilderHttpComponentsClientHttpRequestFactoryTests.java
...teBuilderHttpComponentsClientHttpRequestFactoryTests.java
+55
-0
WebServiceTemplateBuilderHttpComponentsMessageSenderTests.java
...rviceTemplateBuilderHttpComponentsMessageSenderTests.java
+67
-0
WebServiceTemplateBuilderHttpUrlConnectionMessageSenderTests.java
...ceTemplateBuilderHttpUrlConnectionMessageSenderTests.java
+70
-0
WebServiceTemplateBuilderOkHttp3ClientHttpRequestFactoryTests.java
...eTemplateBuilderOkHttp3ClientHttpRequestFactoryTests.java
+82
-0
WebServiceTemplateBuilderSimpleClientHttpRequestFactoryTests.java
...ceTemplateBuilderSimpleClientHttpRequestFactoryTests.java
+52
-0
WebServiceTemplateBuilderTests.java
...ot/webservices/client/WebServiceTemplateBuilderTests.java
+520
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java
0 → 100644
View file @
c9df1c55
/*
* 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
;
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/package-info.java
0 → 100644
View file @
c9df1c55
/*
* 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
;
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
c9df1c55
...
...
@@ -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=\
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfigurationTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
());
}
}
}
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
c9df1c55
...
...
@@ -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]]
...
...
spring-boot-project/spring-boot/pom.xml
View file @
c9df1c55
...
...
@@ -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>
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilder.java
0 → 100644
View file @
c9df1c55
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/webservices/client/WebServiceTemplateCustomizer.java
0 → 100644
View file @
c9df1c55
/*
* 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
);
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/webservices/client/package-info.java
0 → 100644
View file @
c9df1c55
/*
* 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
;
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderCustomsMessageSenderTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
();
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderHttpComponentsClientHttpRequestFactoryTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderHttpComponentsMessageSenderTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderHttpUrlConnectionMessageSenderTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
));
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderOkHttp3ClientHttpRequestFactoryTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderSimpleClientHttpRequestFactoryTests.java
0 → 100644
View file @
c9df1c55
/*
* 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
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java
0 → 100644
View file @
c9df1c55
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment