2

Introduction

We have has created a request mapping as the following:

@RequestMapping(path = "/{project}/{resource}/{language}", method = RequestMethod.GET)
public ResponseEntity<Resource> get(
        @PathVariable String project, 
        @PathVariable String resource, 
        @PathVariable String language) throws IOException {

We could change the path and add a prefix in order to avoid issues but this has been decided as unwanted.

path = "/generateReport/{project}/{resource}/{language}"

Unfortunately, this current mapping is creating problems with swagger-ui.html. When we call it from: http://localhost:8023/swagger-ui.html , the page is blank because all the requests that follow the format a/b/c are hijacked.

Examples:

  <link rel="stylesheet" type="text/css" href="webjars/springfox-swagger-ui/springfox.css?v=2.8.0-SNAPSHOT" >
  <link rel="stylesheet" type="text/css" href="webjars/springfox-swagger-ui/swagger-ui.css?v=2.8.0-SNAPSHOT" >
  <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/favicon-32x32.png?v=2.8.0-SNAPSHOT" sizes="32x32" />
  <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/favicon-16x16.png?v=2.8.0-SNAPSHOT" sizes="16x16" />

And

<script src="webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=2.8.0-SNAPSHOT"> </script>
<script src="webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=2.8.0-SNAPSHOT"> </script>
<script src="webjars/springfox-swagger-ui/springfox.js?v=2.8.0-SNAPSHOT"> </script>

Question

So how do i deal with this? Is there a way to specify that requests starting with webjars should be re-directed elsewhere?

I tried using the consumes keyword, and this works in terms of the client (though I don't like using the content-type like this).

consumes = MediaType.APPLICATION_JSON_VALUE .

Unfortunately, now I am getting the following when I try to access swagger-ui.html :

DefaultHandlerExceptionResolver Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported

The HTML is being generated for swagger-ui.html, but all the resources it needs cannot be loaded.

Any ideas?

Update

I found a work around using path variables and regular expressions:

@RequestMapping(path = "/{project:^(?!webjars).+}/{resource}/{language}", method = RequestMethod.GET)
public ResponseEntity<Resource> get(
        @PathVariable String project, 
        @PathVariable String resource, 
        @PathVariable String language) throws IOException {

However, new answers are still appreciated as I don''t like this 100%

Menelaos
  • 23,508
  • 18
  • 90
  • 155

1 Answers1

0

I found a work around using path variables and regular expressions:

@RequestMapping(path = "/{project:^(?!webjars).+}/{resource}/{language}", method = RequestMethod.GET)
public ResponseEntity<Resource> get(
        @PathVariable String project, 
        @PathVariable String resource, 
        @PathVariable String language) throws IOException {

However, new answers are still appreciated!

Menelaos
  • 23,508
  • 18
  • 90
  • 155