-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): make springwolf ui path configurable (#786)
* feat(core): make springwolf ui path configurable Co-authored-by: Timon Back <[email protected]> * chore(core): use default values for springwolf.path.base * chore(core): allow missing WebMvcConfigurer class in classpath * chore(core): add integration test for custom springwolf path Co-authored-by: Timon Back <[email protected]> --------- Co-authored-by: Timon Back <[email protected]>
- Loading branch information
Showing
12 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.../main/java/io/github/springwolf/core/configuration/SpringwolfUiResourceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.configuration; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@ConditionalOnClass(WebMvcConfigurer.class) | ||
@Import(SpringwolfUiResourceConfigurer.class) | ||
public class SpringwolfUiResourceConfiguration {} |
46 changes: 46 additions & 0 deletions
46
...src/main/java/io/github/springwolf/core/configuration/SpringwolfUiResourceConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.configuration; | ||
|
||
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.web.WebProperties; | ||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@Configuration | ||
@RequiredArgsConstructor | ||
@Order(value = Ordered.HIGHEST_PRECEDENCE) // Highest so that all others will replace this configuration | ||
public class SpringwolfUiResourceConfigurer implements WebMvcConfigurer { | ||
|
||
private final SpringwolfConfigProperties springwolfConfigProperties; | ||
private final WebProperties webProperties; | ||
private final WebMvcProperties webMvcProperties; | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
String springwolfBasePath = springwolfConfigProperties.getPath().getBase(); | ||
|
||
log.debug("Serving Springwolf with base-path: {}", springwolfBasePath); | ||
|
||
registry.addResourceHandler(springwolfBasePath + "/**", webMvcProperties.getStaticPathPattern()) | ||
.addResourceLocations(buildStaticLocation()); | ||
} | ||
|
||
private String[] buildStaticLocation() { | ||
List<String> staticLocations = | ||
new ArrayList<>(Arrays.asList(webProperties.getResources().getStaticLocations())); | ||
staticLocations.add("classpath:/META-INF/resources/springwolf/"); | ||
|
||
return staticLocations.toArray(new String[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...c/test/java/io/github/springwolf/examples/sqs/CustomPathConfigurationIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.examples.sqs; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SpringBootTest( | ||
classes = {SpringwolfSqsExampleApplication.class}, | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ExtendWith({SqsTestContainerExtension.class}) | ||
@TestPropertySource( | ||
properties = {"springwolf.path.base=/my-custom/springwolf/endpoint/test", "springwolf.path.docs=/apispec"}) | ||
class CustomPathConfigurationIntegrationTest { | ||
|
||
@DynamicPropertySource | ||
static void setUpTestContainers(DynamicPropertyRegistry registry) { | ||
SqsTestContainerExtension.overrideConfiguration(registry); | ||
} | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
void getSpec() { | ||
String url = "/my-custom/springwolf/endpoint/test/apispec"; | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
} | ||
|
||
@Test | ||
void canPublish() { | ||
String url = "/my-custom/springwolf/endpoint/test/sqs/publish"; | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
} | ||
|
||
@Test | ||
void asyncapiDocsShouldReturnTheCorrectJsonResponse() { | ||
String url = "/my-custom/springwolf/endpoint/test/asyncapi-ui.html"; | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); | ||
|
||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters