Search in sources :

Example 1 with ApplicationRoute

use of de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute in project spring-boot-admin by codecentric.

the class ApplicationHeadersFilter method run.

@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    String requestURI = this.urlPathHelper.getPathWithinApplication(ctx.getRequest());
    ApplicationRoute route = this.routeLocator.getMatchingRoute(requestURI);
    if (route != null) {
        HttpHeaders headers = headersProvider.getHeaders(route.getApplication());
        for (Entry<String, List<String>> header : headers.entrySet()) {
            ctx.addZuulRequestHeader(header.getKey(), header.getValue().get(0));
        }
    }
    return null;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) List(java.util.List) RequestContext(com.netflix.zuul.context.RequestContext) ApplicationRoute(de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute)

Example 2 with ApplicationRoute

use of de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute in project spring-boot-admin by codecentric.

the class ApplicationHeadersFilterTest method test_add_headers_on_matching_route_only.

@Test
public void test_add_headers_on_matching_route_only() {
    Application application = Application.create("test").withHealthUrl("/health").build();
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("test", "qwertz");
    when(routeLocator.getMatchingRoute("/health")).thenReturn(new ApplicationRoute(application, null, null, null, null));
    when(headerProvider.getHeaders(application)).thenReturn(httpHeaders);
    RequestContext context = creteRequestContext("/health");
    RequestContext.testSetCurrentContext(context);
    filter.run();
    assertThat(context.getZuulRequestHeaders().get("test"), is("qwertz"));
    context = creteRequestContext("/foobar");
    RequestContext.testSetCurrentContext(context);
    filter.run();
    assertThat(context.getZuulRequestHeaders().get("test"), nullValue());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestContext(com.netflix.zuul.context.RequestContext) Application(de.codecentric.boot.admin.model.Application) ApplicationRoute(de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute) Test(org.junit.Test)

Aggregations

RequestContext (com.netflix.zuul.context.RequestContext)2 ApplicationRoute (de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute)2 HttpHeaders (org.springframework.http.HttpHeaders)2 Application (de.codecentric.boot.admin.model.Application)1 List (java.util.List)1 Test (org.junit.Test)1