Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
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
openSource
spring-boot-admin
Commits
b9dd1632
Commit
b9dd1632
authored
Nov 24, 2014
by
Johannes Stelzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workaorund for correct CORS-Headers from Jolokia
Filed
https://github.com/spring-projects/spring-boot/issues/1987
in order to configure it properly in the future.
parent
a881b8ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
2 deletions
+31
-2
SpringBootAdminClientAutoConfiguration.java
.../admin/config/SpringBootAdminClientAutoConfiguration.java
+31
-2
No files found.
spring-boot-starter-admin-client/src/main/java/de/codecentric/boot/admin/config/SpringBootAdminClientAutoConfiguration.java
View file @
b9dd1632
...
...
@@ -20,6 +20,7 @@ import java.util.Arrays;
import
java.util.List
;
import
org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping
;
import
org.springframework.boot.actuate.endpoint.mvc.JolokiaMvcEndpoint
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
...
...
@@ -32,8 +33,10 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.handler.AbstractHandlerMapping
;
import
org.springframework.web.servlet.mvc.ServletWrappingController
;
import
de.codecentric.boot.admin.actuate.LogfileMvcEndpoint
;
import
de.codecentric.boot.admin.services.SpringBootAdminRegistrator
;
...
...
@@ -98,9 +101,12 @@ public class SpringBootAdminClientAutoConfiguration {
return
endpointCorsFilter
;
}
/**
* This method applies several workarounds to apply CORS-Headers corretcly to all Endpoints
*/
@Bean
public
ApplicationListener
<
EmbeddedServletContainerInitializedEvent
>
listener
()
{
return
new
ApplicationListener
<
EmbeddedServletContainerInitializedEvent
>()
{
return
new
ApplicationListener
<
EmbeddedServletContainerInitializedEvent
>()
{
@Override
public
void
onApplicationEvent
(
EmbeddedServletContainerInitializedEvent
event
)
{
// We have to register the CORSHandler in this nasty way.
...
...
@@ -114,13 +120,36 @@ public class SpringBootAdminClientAutoConfiguration {
interceptorsField
.
setAccessible
(
true
);
@SuppressWarnings
(
"unchecked"
)
List
<
HandlerInterceptor
>
adaptedInterceptors
=
(
List
<
HandlerInterceptor
>)
interceptorsField
.
get
(
endpointMappingHandler
);
.
get
(
endpointMappingHandler
);
adaptedInterceptors
.
add
(
endpointCorsFilter
());
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
"Couldn't register CORS-Filter for endpoints"
,
ex
);
}
}
// Options request must be forwarded to jolokias servlet
// @see https://github.com/spring-projects/spring-boot/issues/1987
for
(
DispatcherServlet
dispatcher
:
event
.
getApplicationContext
()
.
getBeansOfType
(
DispatcherServlet
.
class
).
values
())
{
dispatcher
.
setDispatchOptionsRequest
(
true
);
}
// Options request must be forwarded to jolokias servlet
// @see https://github.com/spring-projects/spring-boot/issues/1987
// Since JolokiasMvcEndpoint can't be substituted easily this workaround is needed
for
(
JolokiaMvcEndpoint
jolokiaMvcEndpoint
:
event
.
getApplicationContext
()
.
getBeansOfType
(
JolokiaMvcEndpoint
.
class
).
values
())
{
try
{
Field
controllerField
=
JolokiaMvcEndpoint
.
class
.
getDeclaredField
(
"controller"
);
controllerField
.
setAccessible
(
true
);
ServletWrappingController
controller
=
(
ServletWrappingController
)
controllerField
.
get
(
jolokiaMvcEndpoint
);
controller
.
setSupportedMethods
(
"GET"
,
"HEAD"
,
"POST"
,
"OPTIONS"
);
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
"Couldn't reconfigure servletWrappingController for Jolokia"
,
ex
);
}
}
}
};
}
...
...
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