Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fixed redirection to urls without trailing slash allowing usage of relative paths in GUI. #239

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scheduler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {

testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'joda-time:joda-time:2.3'

testCompile 'org.springframework:spring-test'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.apache.mesos.elasticsearch.scheduler;

import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.context.annotation.Configuration;

/**
*/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("*^/$", "/")
.setKeepQueryParams(true)
.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
}
}
2 changes: 1 addition & 1 deletion scheduler/src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</logger>

<logger name="org.springframework">
<level value="WARN"/>
<level value="DEBUG"/>
</logger>

<root>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.apache.mesos.elasticsearch.scheduler;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WebApplication.class)
@WebAppConfiguration
public class WebApplicationTest {

@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;

@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}

@Test
public void redirectWhenTrailingSlashMissing() throws Exception {
this.mockMvc.perform(get("/")).andExpect(status().isOk());
}
}