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
a7b3a913
Commit
a7b3a913
authored
Apr 09, 2016
by
Vedran Pavic
Committed by
Stephane Nicoll
Apr 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auto-configuration for Spring Web Services
Closes gh-1045
parent
9da54a45
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
316 additions
and
14 deletions
+316
-14
pom.xml
spring-boot-autoconfigure/pom.xml
+5
-0
WsAutoConfiguration.java
...gframework/boot/autoconfigure/ws/WsAutoConfiguration.java
+78
-0
WsProperties.java
...g/springframework/boot/autoconfigure/ws/WsProperties.java
+87
-0
package-info.java
...g/springframework/boot/autoconfigure/ws/package-info.java
+20
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+2
-1
WsAutoConfigurationTests.java
...ework/boot/autoconfigure/ws/WsAutoConfigurationTests.java
+124
-0
WebServiceConfig.java
...t-sample-ws/src/main/java/sample/ws/WebServiceConfig.java
+0
-13
No files found.
spring-boot-autoconfigure/pom.xml
View file @
a7b3a913
...
@@ -512,6 +512,11 @@
...
@@ -512,6 +512,11 @@
<artifactId>
spring-social-linkedin
</artifactId>
<artifactId>
spring-social-linkedin
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.ws
</groupId>
<artifactId>
spring-ws-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<dependency>
<groupId>
org.thymeleaf
</groupId>
<groupId>
org.thymeleaf
</groupId>
<artifactId>
thymeleaf
</artifactId>
<artifactId>
thymeleaf
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ws/WsAutoConfiguration.java
0 → 100644
View file @
a7b3a913
/*
* Copyright 2012-2016 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
.
ws
;
import
java.util.Map
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.ws.config.annotation.DelegatingWsConfiguration
;
import
org.springframework.ws.config.annotation.WsConfigurationSupport
;
import
org.springframework.ws.transport.http.MessageDispatcherServlet
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Web Services.
*
* @author Vedran Pavic
* @since 1.4.0
*/
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass
(
MessageDispatcherServlet
.
class
)
@ConditionalOnMissingBean
(
WsConfigurationSupport
.
class
)
@EnableConfigurationProperties
(
WsProperties
.
class
)
@AutoConfigureAfter
(
EmbeddedServletContainerAutoConfiguration
.
class
)
public
class
WsAutoConfiguration
{
private
WsProperties
properties
;
public
WsAutoConfiguration
(
WsProperties
properties
)
{
this
.
properties
=
properties
;
}
@Bean
public
ServletRegistrationBean
messageDispatcherServlet
(
ApplicationContext
applicationContext
)
{
MessageDispatcherServlet
servlet
=
new
MessageDispatcherServlet
();
servlet
.
setApplicationContext
(
applicationContext
);
String
path
=
this
.
properties
.
getPath
();
String
urlMapping
=
(
path
.
endsWith
(
"/"
)
?
path
+
"*"
:
path
+
"/*"
);
ServletRegistrationBean
registration
=
new
ServletRegistrationBean
(
servlet
,
urlMapping
);
registration
.
setLoadOnStartup
(
this
.
properties
.
getServlet
().
getLoadOnStartup
());
for
(
Map
.
Entry
<
String
,
String
>
entry
:
this
.
properties
.
getInit
().
entrySet
())
{
registration
.
addInitParameter
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
registration
;
}
@Configuration
@Import
(
DelegatingWsConfiguration
.
class
)
protected
static
class
WsConfiguration
{
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ws/WsProperties.java
0 → 100644
View file @
a7b3a913
/*
* Copyright 2012-2016 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
.
ws
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* {@link ConfigurationProperties} for Spring Web Services.
*
* @author Vedran Pavic
* @since 1.4.0
*/
@ConfigurationProperties
(
"spring.ws"
)
public
class
WsProperties
{
/**
* Path that serves as the base URI for the services.
*/
@NotNull
@Pattern
(
regexp
=
"/[^?#]*"
,
message
=
"Path must start with /"
)
private
String
path
=
"/services"
;
/**
* Init parameters to pass to Spring Web Services via the servlet.
*/
private
Map
<
String
,
String
>
init
=
new
HashMap
<
String
,
String
>();
private
final
Servlet
servlet
=
new
Servlet
();
public
String
getPath
()
{
return
this
.
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
Map
<
String
,
String
>
getInit
()
{
return
this
.
init
;
}
public
void
setInit
(
Map
<
String
,
String
>
init
)
{
this
.
init
=
init
;
}
public
Servlet
getServlet
()
{
return
this
.
servlet
;
}
public
static
class
Servlet
{
/**
* Load on startup priority of the Spring Web Services servlet.
*/
private
int
loadOnStartup
=
-
1
;
public
int
getLoadOnStartup
()
{
return
this
.
loadOnStartup
;
}
public
void
setLoadOnStartup
(
int
loadOnStartup
)
{
this
.
loadOnStartup
=
loadOnStartup
;
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ws/package-info.java
0 → 100644
View file @
a7b3a913
/*
* Copyright 2012-2016 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.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
ws
;
spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
a7b3a913
...
@@ -96,7 +96,8 @@ org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration,\
...
@@ -96,7 +96,8 @@ org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration,\
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration
org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.ws.WsAutoConfiguration
# Template availability providers
# Template availability providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ws/WsAutoConfigurationTests.java
0 → 100644
View file @
a7b3a913
/*
* Copyright 2012-2016 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
.
ws
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link WsAutoConfiguration}.
*
* @author Vedran Pavic
*/
public
class
WsAutoConfigurationTests
{
private
AnnotationConfigWebApplicationContext
context
=
new
AnnotationConfigWebApplicationContext
();
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Before
public
void
setupContext
()
{
this
.
context
.
setServletContext
(
new
MockServletContext
());
}
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
defaultConfiguration
()
{
registerAndRefresh
(
WsAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
}
@Test
public
void
customPathMustBeginWithASlash
()
{
this
.
thrown
.
expect
(
BeanCreationException
.
class
);
this
.
thrown
.
expectMessage
(
"Path must start with /"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.ws.path=invalid"
);
registerAndRefresh
(
WsAutoConfiguration
.
class
);
}
@Test
public
void
customPathWithTrailingSlash
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.ws.path=/valid/"
);
registerAndRefresh
(
WsAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/valid/*"
);
}
@Test
public
void
customPath
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.ws.path=/valid"
);
registerAndRefresh
(
WsAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ServletRegistrationBean
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
).
getUrlMappings
())
.
contains
(
"/valid/*"
);
}
@Test
public
void
customLoadOnStartup
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.ws.servlet.load-on-startup=1"
);
registerAndRefresh
(
WsAutoConfiguration
.
class
);
ServletRegistrationBean
registrationBean
=
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
);
assertThat
(
ReflectionTestUtils
.
getField
(
registrationBean
,
"loadOnStartup"
))
.
isEqualTo
(
1
);
}
@Test
public
void
customInitParameters
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.ws.init.key1=value1"
,
"spring.ws.init.key2=value2"
);
registerAndRefresh
(
WsAutoConfiguration
.
class
);
ServletRegistrationBean
registrationBean
=
this
.
context
.
getBean
(
ServletRegistrationBean
.
class
);
assertThat
(
registrationBean
.
getInitParameters
()).
containsEntry
(
"key1"
,
"value1"
);
assertThat
(
registrationBean
.
getInitParameters
()).
containsEntry
(
"key2"
,
"value2"
);
}
private
void
registerAndRefresh
(
Class
<?>...
annotatedClasses
)
{
this
.
context
.
register
(
annotatedClasses
);
this
.
context
.
refresh
();
}
}
spring-boot-samples/spring-boot-sample-ws/src/main/java/sample/ws/WebServiceConfig.java
View file @
a7b3a913
...
@@ -16,30 +16,17 @@
...
@@ -16,30 +16,17 @@
package
sample
.
ws
;
package
sample
.
ws
;
import
org.springframework.boot.context.embedded.ServletRegistrationBean
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.ws.config.annotation.EnableWs
;
import
org.springframework.ws.config.annotation.WsConfigurerAdapter
;
import
org.springframework.ws.config.annotation.WsConfigurerAdapter
;
import
org.springframework.ws.transport.http.MessageDispatcherServlet
;
import
org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition
;
import
org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition
;
import
org.springframework.xml.xsd.SimpleXsdSchema
;
import
org.springframework.xml.xsd.SimpleXsdSchema
;
import
org.springframework.xml.xsd.XsdSchema
;
import
org.springframework.xml.xsd.XsdSchema
;
@EnableWs
@Configuration
@Configuration
public
class
WebServiceConfig
extends
WsConfigurerAdapter
{
public
class
WebServiceConfig
extends
WsConfigurerAdapter
{
@Bean
public
ServletRegistrationBean
dispatcherServlet
(
ApplicationContext
applicationContext
)
{
MessageDispatcherServlet
servlet
=
new
MessageDispatcherServlet
();
servlet
.
setApplicationContext
(
applicationContext
);
return
new
ServletRegistrationBean
(
servlet
,
"/services/*"
);
}
@Bean
(
name
=
"holiday"
)
@Bean
(
name
=
"holiday"
)
public
DefaultWsdl11Definition
defaultWsdl11Definition
(
XsdSchema
countriesSchema
)
{
public
DefaultWsdl11Definition
defaultWsdl11Definition
(
XsdSchema
countriesSchema
)
{
DefaultWsdl11Definition
wsdl11Definition
=
new
DefaultWsdl11Definition
();
DefaultWsdl11Definition
wsdl11Definition
=
new
DefaultWsdl11Definition
();
...
...
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