Search in sources :

Example 1 with MimeMappings

use of org.springframework.boot.web.server.MimeMappings in project connectors-workspace-one by vmware.

the class ConnectorsAutoConfiguration method webServerFactory.

@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    mappings.add("hbs", "text/x-handlebars-template");
    mappings.add("hal", "application/hal+json");
    factory.setMimeMappings(mappings);
    return factory;
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) MimeMappings(org.springframework.boot.web.server.MimeMappings) Bean(org.springframework.context.annotation.Bean)

Example 2 with MimeMappings

use of org.springframework.boot.web.server.MimeMappings in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method mimeType.

@Test
void mimeType() throws Exception {
    FileCopyUtils.copy("test", new FileWriter(new File(this.tempDir, "test.xxcss")));
    AbstractServletWebServerFactory factory = getFactory();
    factory.setRegisterDefaultServlet(true);
    factory.setDocumentRoot(this.tempDir);
    MimeMappings mimeMappings = new MimeMappings();
    mimeMappings.add("xxcss", "text/css");
    factory.setMimeMappings(mimeMappings);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/test.xxcss"));
    assertThat(response.getHeaders().getContentType().toString()).isEqualTo("text/css");
    response.close();
}
Also used : FileWriter(java.io.FileWriter) MimeMappings(org.springframework.boot.web.server.MimeMappings) File(java.io.File) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

MimeMappings (org.springframework.boot.web.server.MimeMappings)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)1 Bean (org.springframework.context.annotation.Bean)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1