Skip to content

infinite loop in spring controller #8797

@peter-ponzel

Description

@peter-ponzel

Hello,

I was looking for a way to read the full path that was requested when using a RequestMapping with /**.
There was an approach on stackoverflow that used HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
while trying that I came across an interesting issue and wanted to report it.
Here is what I used/did:

pom.xml:

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>1.5.2.RELEASE</version>
	<relativePath/>
</parent>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-hateoas</artifactId>
	</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
<dependency>
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId>
	<optional>true</optional>
</dependency>

controller

@Controller
@RequestMapping("/foo")
@Slf4j
public class FooController {
	/** works like a charm */
	@RequestMapping(value = "/ok/**", method = RequestMethod.GET)
	public void ok(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
		final String paths = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
		log.debug("{}", paths);
	}
	/** indefinite loop */
	@RequestMapping(value = "/not-ok/**", method = RequestMethod.GET)
	public void notOk(final HttpServletRequest request) throws Exception {
		final String paths = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
		log.debug("{}", paths);
	}
}

You can also get rid of this issue with providing a response, for instance return ResponseEntity.ok(paths);

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions