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
cb600f1c
Commit
cb600f1c
authored
Feb 26, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x' into 2.4.x
Closes gh-25449
parents
24b2bb92
8f72ca65
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
358 additions
and
51 deletions
+358
-51
JerseyWebEndpointManagementContextConfiguration.java
...rsey/JerseyWebEndpointManagementContextConfiguration.java
+20
-29
JerseyChildManagementContextConfiguration.java
...web/jersey/JerseyChildManagementContextConfiguration.java
+9
-1
JerseyManagementContextConfiguration.java
...gure/web/jersey/JerseyManagementContextConfiguration.java
+1
-6
JerseySameManagementContextConfiguration.java
.../web/jersey/JerseySameManagementContextConfiguration.java
+27
-6
ManagementContextResourceConfigCustomizer.java
...web/jersey/ManagementContextResourceConfigCustomizer.java
+36
-0
JerseyWebEndpointIntegrationTests.java
...ndpoint/web/jersey/JerseyWebEndpointIntegrationTests.java
+78
-0
JerseyChildManagementContextConfigurationTests.java
...ersey/JerseyChildManagementContextConfigurationTests.java
+26
-1
JerseySameManagementContextConfigurationTests.java
...jersey/JerseySameManagementContextConfigurationTests.java
+23
-1
AbstractJerseyApplicationTests.java
...java/smoketest/jersey/AbstractJerseyApplicationTests.java
+3
-3
AbstractJerseyManagementPortTests.java
...a/smoketest/jersey/AbstractJerseyManagementPortTests.java
+23
-4
JerseyFilterApplicationTests.java
...t/java/smoketest/jersey/JerseyFilterApplicationTests.java
+29
-0
JerseyFilterManagementPortTests.java
...ava/smoketest/jersey/JerseyFilterManagementPortTests.java
+30
-0
JerseyServletApplicationTests.java
.../java/smoketest/jersey/JerseyServletApplicationTests.java
+26
-0
JerseyServletManagementPortTests.java
...va/smoketest/jersey/JerseyServletManagementPortTests.java
+27
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
View file @
cb600f1c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -24,9 +24,9 @@ import java.util.List;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.glassfish.jersey.server.model.Resource
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.jersey.ManagementContextResourceConfigCustomizer
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType
;
import
org.springframework.boot.actuate.endpoint.ExposableEndpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
...
...
@@ -43,7 +43,6 @@ 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.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.StringUtils
;
...
...
@@ -67,14 +66,13 @@ class JerseyWebEndpointManagementContextConfiguration {
@Bean
JerseyWebEndpointsResourcesRegistrar
jerseyWebEndpointsResourcesRegistrar
(
Environment
environment
,
ObjectProvider
<
ResourceConfig
>
resourceConfig
,
WebEndpointsSupplier
webEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
WebEndpointProperties
webEndpointProperties
)
{
WebEndpointsSupplier
webEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
WebEndpointProperties
webEndpointProperties
)
{
String
basePath
=
webEndpointProperties
.
getBasePath
();
boolean
shouldRegisterLinks
=
shouldRegisterLinksMapping
(
environment
,
basePath
);
shouldRegisterLinksMapping
(
environment
,
basePath
);
return
new
JerseyWebEndpointsResourcesRegistrar
(
resourceConfig
.
getIfAvailable
(),
web
EndpointsSupplier
,
servletEndpointsSupplier
,
endpointMediaTypes
,
basePath
,
shouldRegisterLinks
);
return
new
JerseyWebEndpointsResourcesRegistrar
(
webEndpointsSupplier
,
servlet
EndpointsSupplier
,
endpointMediaTypes
,
basePath
,
shouldRegisterLinks
);
}
private
boolean
shouldRegisterLinksMapping
(
Environment
environment
,
String
basePath
)
{
...
...
@@ -83,12 +81,9 @@ class JerseyWebEndpointManagementContextConfiguration {
}
/**
* Register endpoints with the {@link ResourceConfig}. The
* {@link ResourceConfigCustomizer} cannot be used because we don't want to apply
* Register endpoints with the {@link ResourceConfig} for the management context.
*/
static
class
JerseyWebEndpointsResourcesRegistrar
{
private
final
ResourceConfig
resourceConfig
;
static
class
JerseyWebEndpointsResourcesRegistrar
implements
ManagementContextResourceConfigCustomizer
{
private
final
WebEndpointsSupplier
webEndpointsSupplier
;
...
...
@@ -100,33 +95,29 @@ class JerseyWebEndpointManagementContextConfiguration {
private
final
boolean
shouldRegisterLinks
;
JerseyWebEndpointsResourcesRegistrar
(
ResourceConfig
resourceConfig
,
WebEndpointsSupplier
webEndpointsSupplier
,
JerseyWebEndpointsResourcesRegistrar
(
WebEndpointsSupplier
webEndpointsSupplier
,
ServletEndpointsSupplier
servletEndpointsSupplier
,
EndpointMediaTypes
endpointMediaTypes
,
String
basePath
,
boolean
shouldRegisterLinks
)
{
super
();
this
.
resourceConfig
=
resourceConfig
;
this
.
webEndpointsSupplier
=
webEndpointsSupplier
;
this
.
servletEndpointsSupplier
=
servletEndpointsSupplier
;
this
.
mediaTypes
=
endpointMediaTypes
;
this
.
basePath
=
basePath
;
this
.
shouldRegisterLinks
=
shouldRegisterLinks
;
register
();
}
private
void
register
()
{
// We can't easily use @ConditionalOnBean because @AutoConfigureBefore is
// not an option for management contexts. Instead we manually check if
// the resource config bean exists
if
(
this
.
resourceConfig
==
null
)
{
return
;
}
@Override
public
void
customize
(
ResourceConfig
config
)
{
register
(
config
);
}
private
void
register
(
ResourceConfig
config
)
{
Collection
<
ExposableWebEndpoint
>
webEndpoints
=
this
.
webEndpointsSupplier
.
getEndpoints
();
Collection
<
ExposableServletEndpoint
>
servletEndpoints
=
this
.
servletEndpointsSupplier
.
getEndpoints
();
EndpointLinksResolver
linksResolver
=
getLinksResolver
(
webEndpoints
,
servletEndpoints
);
EndpointMapping
mapping
=
new
EndpointMapping
(
this
.
basePath
);
JerseyEndpointResourceFactory
resourceFactory
=
new
JerseyEndpointResourceFactory
();
register
(
resourceFactory
.
createEndpointResources
(
mapping
,
webEndpoints
,
this
.
mediaTypes
,
linksResolver
,
this
.
shouldRegisterLinks
)
);
Collection
<
Resource
>
endpointResources
=
new
JerseyEndpointResourceFactory
().
createEndpointResources
(
mapping
,
webEndpoints
,
this
.
mediaTypes
,
linksResolver
,
this
.
shouldRegisterLinks
);
register
(
endpointResources
,
config
);
}
private
EndpointLinksResolver
getLinksResolver
(
Collection
<
ExposableWebEndpoint
>
webEndpoints
,
...
...
@@ -137,8 +128,8 @@ class JerseyWebEndpointManagementContextConfiguration {
return
new
EndpointLinksResolver
(
endpoints
,
this
.
basePath
);
}
private
void
register
(
Collection
<
Resource
>
resources
)
{
this
.
resourceC
onfig
.
registerResources
(
new
HashSet
<>(
resources
));
private
void
register
(
Collection
<
Resource
>
resources
,
ResourceConfig
config
)
{
c
onfig
.
registerResources
(
new
HashSet
<>(
resources
));
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfiguration.java
View file @
cb600f1c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.web.jersey;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextType
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
...
@@ -47,4 +48,11 @@ public class JerseyChildManagementContextConfiguration {
return
()
->
"/"
;
}
@Bean
ResourceConfig
resourceConfig
(
ObjectProvider
<
ManagementContextResourceConfigCustomizer
>
customizers
)
{
ResourceConfig
resourceConfig
=
new
ResourceConfig
();
customizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
resourceConfig
));
return
resourceConfig
;
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyManagementContextConfiguration.java
View file @
cb600f1c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -39,9 +39,4 @@ class JerseyManagementContextConfiguration {
jerseyApplicationPath
.
getUrlMapping
());
}
@Bean
ResourceConfig
resourceConfig
()
{
return
new
ResourceConfig
();
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfiguration.java
View file @
cb600f1c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.web.jersey;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.ManagementContextType
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
...
@@ -25,10 +26,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.jersey.JerseyProperties
;
import
org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer
;
import
org.springframework.boot.autoconfigure.web.servlet.DefaultJerseyApplicationPath
;
import
org.springframework.boot.autoconfigure.web.servlet.JerseyApplicationPath
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
/**
...
...
@@ -39,18 +42,36 @@ import org.springframework.context.annotation.Import;
* @since 2.1.0
*/
@ManagementContextConfiguration
(
value
=
ManagementContextType
.
SAME
,
proxyBeanMethods
=
false
)
@Import
(
JerseyManagementContextConfiguration
.
class
)
@EnableConfigurationProperties
(
JerseyProperties
.
class
)
@ConditionalOnMissingBean
(
ResourceConfig
.
class
)
@ConditionalOnWebApplication
(
type
=
ConditionalOnWebApplication
.
Type
.
SERVLET
)
@ConditionalOnClass
(
ResourceConfig
.
class
)
@ConditionalOnMissingClass
(
"org.springframework.web.servlet.DispatcherServlet"
)
public
class
JerseySameManagementContextConfiguration
{
@Bean
@ConditionalOnMissingBean
(
JerseyApplicationPath
.
class
)
public
JerseyApplicationPath
jerseyApplicationPath
(
JerseyProperties
properties
,
ResourceConfig
config
)
{
return
new
DefaultJerseyApplicationPath
(
properties
.
getApplicationPath
(),
config
);
ResourceConfigCustomizer
managementResourceConfigCustomizerAdapter
(
ObjectProvider
<
ManagementContextResourceConfigCustomizer
>
customizers
)
{
return
(
config
)
->
customizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
config
));
}
@Configuration
(
proxyBeanMethods
=
false
)
@Import
(
JerseyManagementContextConfiguration
.
class
)
@ConditionalOnMissingBean
(
ResourceConfig
.
class
)
class
JerseyInfrastructureConfiguration
{
@Bean
@ConditionalOnMissingBean
(
JerseyApplicationPath
.
class
)
JerseyApplicationPath
jerseyApplicationPath
(
JerseyProperties
properties
,
ResourceConfig
config
)
{
return
new
DefaultJerseyApplicationPath
(
properties
.
getApplicationPath
(),
config
);
}
@Bean
ResourceConfig
resourceConfig
(
ObjectProvider
<
ResourceConfigCustomizer
>
resourceConfigCustomizers
)
{
ResourceConfig
resourceConfig
=
new
ResourceConfig
();
resourceConfigCustomizers
.
orderedStream
().
forEach
((
customizer
)
->
customizer
.
customize
(
resourceConfig
));
return
resourceConfig
;
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/jersey/ManagementContextResourceConfigCustomizer.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
.
actuate
.
autoconfigure
.
web
.
jersey
;
import
org.glassfish.jersey.server.ResourceConfig
;
/**
* Callback interface that can be implemented by beans wishing to customize Jersey's
* {@link ResourceConfig} in the management context before it is used.
*
* @author Andy Wilkinson
* @since 2.3.10
*/
public
interface
ManagementContextResourceConfigCustomizer
{
/**
* Customize the resource config.
* @param config the {@link ResourceConfig} to customize
*/
void
customize
(
ResourceConfig
config
);
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointIntegrationTests.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
.
actuate
.
autoconfigure
.
endpoint
.
web
.
jersey
;
import
java.util.Set
;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.glassfish.jersey.server.model.Resource
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.web.jersey.JerseySameManagementContextConfiguration
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration
;
import
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
;
import
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration
;
import
org.springframework.boot.logging.LogLevel
;
import
org.springframework.boot.test.context.FilteredClassLoader
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for web endpoints running on Jersey.
*
* @author Andy Wilkinson
*/
class
JerseyWebEndpointIntegrationTests
{
@Test
void
whenJerseyIsConfiguredToUseAFilterThenResourceRegistrationSucceeds
()
{
new
WebApplicationContextRunner
(
AnnotationConfigServletWebServerApplicationContext:
:
new
)
.
withConfiguration
(
AutoConfigurations
.
of
(
JerseySameManagementContextConfiguration
.
class
,
JerseyAutoConfiguration
.
class
,
ServletWebServerFactoryAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
WebEndpointAutoConfiguration
.
class
,
JerseyWebEndpointManagementContextConfiguration
.
class
))
.
withUserConfiguration
(
ResourceConfigConfiguration
.
class
)
.
withClassLoader
(
new
FilteredClassLoader
(
DispatcherServlet
.
class
))
.
withInitializer
(
new
ConditionEvaluationReportLoggingListener
(
LogLevel
.
INFO
))
.
withPropertyValues
(
"spring.jersey.type=filter"
,
"server.port=0"
).
run
((
context
)
->
{
assertThat
(
context
).
hasNotFailed
();
Set
<
Resource
>
resources
=
context
.
getBean
(
ResourceConfig
.
class
).
getResources
();
assertThat
(
resources
).
hasSize
(
1
);
Resource
resource
=
resources
.
iterator
().
next
();
assertThat
(
resource
.
getPath
()).
isEqualTo
(
"/actuator"
);
});
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
ResourceConfigConfiguration
{
@Bean
ResourceConfig
resourceConfig
()
{
return
new
ResourceConfig
();
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseyChildManagementContextConfigurationTests.java
View file @
cb600f1c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
...
@@ -27,8 +27,12 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.testsupport.classpath.ClassPathExclusions
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link JerseyChildManagementContextConfiguration}.
...
...
@@ -78,4 +82,25 @@ class JerseyChildManagementContextConfigurationTests {
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
ResourceConfig
.
class
));
}
@Test
void
resourceConfigIsCustomizedWithResourceConfigCustomizerBean
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomizerConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ResourceConfig
.
class
);
ResourceConfig
config
=
context
.
getBean
(
ResourceConfig
.
class
);
ManagementContextResourceConfigCustomizer
customizer
=
context
.
getBean
(
ManagementContextResourceConfigCustomizer
.
class
);
verify
(
customizer
).
customize
(
config
);
});
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
CustomizerConfiguration
{
@Bean
ManagementContextResourceConfigCustomizer
resourceConfigCustomizer
()
{
return
mock
(
ManagementContextResourceConfigCustomizer
.
class
);
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/jersey/JerseySameManagementContextConfigurationTests.java
View file @
cb600f1c
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Tests for {@link JerseySameManagementContextConfiguration}.
...
...
@@ -91,6 +92,17 @@ class JerseySameManagementContextConfigurationTests {
});
}
@Test
void
resourceConfigIsCustomizedWithResourceConfigCustomizerBean
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomizerConfiguration
.
class
).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ResourceConfig
.
class
);
ResourceConfig
config
=
context
.
getBean
(
ResourceConfig
.
class
);
ManagementContextResourceConfigCustomizer
customizer
=
context
.
getBean
(
ManagementContextResourceConfigCustomizer
.
class
);
verify
(
customizer
).
customize
(
config
);
});
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
ConfigWithJerseyApplicationPath
{
...
...
@@ -111,4 +123,14 @@ class JerseySameManagementContextConfigurationTests {
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
CustomizerConfiguration
{
@Bean
ManagementContextResourceConfigCustomizer
resourceConfigCustomizer
()
{
return
mock
(
ManagementContextResourceConfigCustomizer
.
class
);
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/
Sample
JerseyApplicationTests.java
→
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/
Abstract
JerseyApplicationTests.java
View file @
cb600f1c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
...
@@ -27,8 +27,8 @@ import org.springframework.http.ResponseEntity;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
class
Sample
JerseyApplicationTests
{
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
properties
=
"logging.level.root=debug"
)
abstract
class
Abstract
JerseyApplicationTests
{
@Autowired
private
TestRestTemplate
restTemplate
;
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyManagementPortTests.java
→
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/
Abstract
JerseyManagementPortTests.java
View file @
cb600f1c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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.
...
...
@@ -21,6 +21,7 @@ import javax.ws.rs.Path;
import
org.glassfish.jersey.server.ResourceConfig
;
import
org.junit.jupiter.api.Test
;
import
smoketest.jersey.AbstractJerseyManagementPortTests.ResourceConfigConfiguration
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort
;
...
...
@@ -30,18 +31,22 @@ import org.springframework.boot.test.context.TestConfiguration;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.boot.web.server.LocalServerPort
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for separate management and main service ports.
* Base class for integration tests for Jersey using separate management and main service
* ports.
*
* @author Madhura Bhave
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
"management.server.port=0"
)
class
JerseyManagementPortTests
{
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.server.port=0"
,
"debug=true"
})
@Import
(
ResourceConfigConfiguration
.
class
)
class
AbstractJerseyManagementPortTests
{
@LocalServerPort
private
int
port
;
...
...
@@ -67,6 +72,20 @@ class JerseyManagementPortTests {
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
@Test
void
actuatorShouldBeAvailableOnManagementPort
()
{
ResponseEntity
<
String
>
entity
=
this
.
testRestTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/actuator/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
}
@Test
void
actuatorShouldNotBeAvailableOnMainPort
()
{
ResponseEntity
<
String
>
entity
=
this
.
testRestTemplate
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/actuator/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
@TestConfiguration
static
class
ResourceConfigConfiguration
{
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyFilterApplicationTests.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
smoketest
.
jersey
;
import
org.springframework.test.context.TestPropertySource
;
/**
* Smoke tests for Jersey configured as a Filter.
*
* @author Andy Wilkinson
*/
@TestPropertySource
(
properties
=
"spring.jersey.type=filter"
)
class
JerseyFilterApplicationTests
extends
AbstractJerseyApplicationTests
{
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyFilterManagementPortTests.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
smoketest
.
jersey
;
import
org.springframework.test.context.TestPropertySource
;
/**
* Integration tests for Jersey configured as a Servlet using separate management and main
* service ports.
*
* @author Andy Wilkinson
*/
@TestPropertySource
(
properties
=
"spring.jersey.type=filter"
)
public
class
JerseyFilterManagementPortTests
extends
AbstractJerseyManagementPortTests
{
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyServletApplicationTests.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
smoketest
.
jersey
;
/**
* Smoke tests for Jersey configured as a Servlet.
*
* @author Andy Wilkinson
*/
class
JerseyServletApplicationTests
extends
AbstractJerseyApplicationTests
{
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyServletManagementPortTests.java
0 → 100644
View file @
cb600f1c
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://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
smoketest
.
jersey
;
/**
* Integration tests for Jersey configured as a Servlet using separate management and main
* service ports.
*
* @author Andy Wilkinson
*/
public
class
JerseyServletManagementPortTests
extends
AbstractJerseyManagementPortTests
{
}
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