Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

clean up some code #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,64 +1,61 @@
package org.springframework.samples.mvc.mapping;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RestController
@RequestMapping("/mapping")
public class MappingController {

@RequestMapping("/mapping/path")
public @ResponseBody String byPath() {
@RequestMapping("/path")
public String byPath() {
return "Mapped by path!";
}

@RequestMapping(value="/mapping/path/*", method=RequestMethod.GET)
public @ResponseBody String byPathPattern(HttpServletRequest request) {
@RequestMapping(value="/path/*", method=RequestMethod.GET)
public String byPathPattern(HttpServletRequest request) {
return "Mapped by path pattern ('" + request.getRequestURI() + "')";
}

@RequestMapping(value="/mapping/method", method=RequestMethod.GET)
public @ResponseBody String byMethod() {
@RequestMapping(value="/method", method=RequestMethod.GET)
public String byMethod() {
return "Mapped by path + method";
}

@RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo")
public @ResponseBody String byParameter() {
@RequestMapping(value="/parameter", method=RequestMethod.GET, params="foo")
public String byParameter() {
return "Mapped by path + method + presence of query parameter!";
}

@RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="!foo")
public @ResponseBody String byParameterNegation() {
@RequestMapping(value="/parameter", method=RequestMethod.GET, params="!foo")
public String byParameterNegation() {
return "Mapped by path + method + not presence of query parameter!";
}

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="FooHeader=foo")
public @ResponseBody String byHeader() {
@RequestMapping(value="/header", method=RequestMethod.GET, headers="FooHeader=foo")
public String byHeader() {
return "Mapped by path + method + presence of header!";
}

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="!FooHeader")
public @ResponseBody String byHeaderNegation() {
@RequestMapping(value="/header", method=RequestMethod.GET, headers="!FooHeader")
public String byHeaderNegation() {
return "Mapped by path + method + absence of header!";
}

@RequestMapping(value="/mapping/consumes", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) {
@RequestMapping(value="/consumes", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
public String byConsumes(@RequestBody JavaBean javaBean) {
return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')";
}

@RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody JavaBean byProducesJson() {
@RequestMapping(value="/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public JavaBean byProducesJson() {
return new JavaBean();
}

@RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE)
public @ResponseBody JavaBean byProducesXml() {
@RequestMapping(value="/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE)
public JavaBean byProducesXml() {
return new JavaBean();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.junit.Before;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

Expand Down Expand Up @@ -52,7 +51,7 @@ public void submitSuccess() throws Exception {
.param("_additionalInfo[java]", "on")
.param("subscribeNewsletter", "false"))
.andDo(print())
.andExpect(status().isMovedTemporarily())
.andExpect(status().isFound())
.andExpect(redirectedUrl("/form"))
.andExpect(flash().attribute("message",
"Form submitted successfully. Bound properties name='Joe', age=56, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RedirectControllerTests {
@Before
public void setup() throws Exception {
this.mockMvc = standaloneSetup(new RedirectController(new DefaultFormattingConversionService()))
.alwaysExpect(status().isMovedTemporarily()).build();
.alwaysExpect(status().isFound()).build();
}

@Test
Expand Down