Fix @RequestMapping so that git label can contain periods

Spring MVC lops off the "extension" from request paths by default
(causing no end of other problems), but in this case making it
impossible, or unintuitive at best, to use version-like labels
in git repositories (e.g. 1.0.0). This change makes the mapping
a regex match which includes the whole path, not just the stem.

Fixes gh-94
This commit is contained in:
Dave Syer
2015-03-02 09:03:59 +00:00
parent 80cc7f9800
commit 5fc2b1af66
2 changed files with 68 additions and 1 deletions

View File

@@ -56,7 +56,7 @@ public class EnvironmentController {
return labelled(name, profiles, defaultLabel);
}
@RequestMapping("/{name}/{profiles}/{label}")
@RequestMapping("/{name}/{profiles}/{label:.*}")
public Environment labelled(@PathVariable String name, @PathVariable String profiles,
@PathVariable String label) {
Environment environment = encryption.decrypt(repository.findOne(name, profiles,

View File

@@ -0,0 +1,67 @@
/*
* Copyright 2014-2015 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.cloud.config.server;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
/**
* @author Dave Syer
*
*/
public class EnvironmentControllerIntegrationTests {
private MockMvc mvc;
private EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);;
@Before
public void init() {
mvc = MockMvcBuilders.standaloneSetup(
new EnvironmentController(repository, new EncryptionController()))
.build();
}
@Test
public void environmentNoLabel() throws Exception {
Mockito.when(repository.findOne("foo", "default", "master")).thenReturn(
new Environment("foo", "default"));
mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect(
MockMvcResultMatchers.status().isOk());
}
@Test
public void environmentWithLabel() throws Exception {
Mockito.when(repository.findOne("foo", "default", "awesome")).thenReturn(
new Environment("foo", "default"));
mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome")).andExpect(
MockMvcResultMatchers.status().isOk());
}
@Test
public void environmentWithLabelContainingPeriod() throws Exception {
Mockito.when(repository.findOne("foo", "default", "1.0.0")).thenReturn(
new Environment("foo", "default"));
mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")).andExpect(
MockMvcResultMatchers.status().isOk());
}
}