Skip to content
Closed
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
Expand Up @@ -78,11 +78,9 @@ public final class ServerlessMVC {

private volatile ServletWebServerApplicationContext applicationContext;

private ServletContext servletContext;

private final CountDownLatch contextStartupLatch = new CountDownLatch(1);

private final long initializatioinTimeout;
private final long initializationTimeout;

public static ServerlessMVC INSTANCE(Class<?>... componentClasses) {
ServerlessMVC mvc = new ServerlessMVC();
Expand All @@ -103,7 +101,7 @@ private ServerlessMVC() {
if (!StringUtils.hasText(timeoutValue)) {
timeoutValue = System.getProperty(INIT_TIMEOUT);
}
this.initializatioinTimeout = StringUtils.hasText(timeoutValue) ? Long.valueOf(timeoutValue) : 20000;
this.initializationTimeout = StringUtils.hasText(timeoutValue) ? Long.valueOf(timeoutValue) : 20000;
}

private void initializeContextAsync(Class<?>... componentClasses) {
Expand Down Expand Up @@ -137,7 +135,7 @@ public ConfigurableWebApplicationContext getApplicationContext() {

public ServletContext getServletContext() {
this.waitForContext();
return this.servletContext;
return this.dispatcher.getServletContext();
}

public void stop() {
Expand All @@ -157,7 +155,7 @@ public void stop() {
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers
*/
public void service(HttpServletRequest request, HttpServletResponse response) throws Exception {
Assert.state(this.waitForContext(), "Failed to initialize Application within the specified time of " + this.initializatioinTimeout + " milliseconds. "
Assert.state(this.waitForContext(), "Failed to initialize Application within the specified time of " + this.initializationTimeout + " milliseconds. "
+ "If you need to increase it, please set " + INIT_TIMEOUT + " environment variable");
this.service(request, response, (CountDownLatch) null);
}
Expand Down Expand Up @@ -189,7 +187,7 @@ public void service(HttpServletRequest request, HttpServletResponse response, Co

public boolean waitForContext() {
try {
return contextStartupLatch.await(initializatioinTimeout, TimeUnit.MILLISECONDS);
return contextStartupLatch.await(initializationTimeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand All @@ -215,7 +213,6 @@ private static class ProxyFilterChain implements FilterChain {
* Create a {@code FilterChain} with Filter's and a Servlet.
*
* @param servlet the {@link Servlet} to invoke in this {@link FilterChain}
* @param filters the {@link Filter}'s to invoke in this {@link FilterChain}
* @since 4.0.x
*/
ProxyFilterChain(DispatcherServlet servlet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package org.springframework.cloud.function.serverless.web;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
Expand Down Expand Up @@ -104,7 +108,14 @@ public int getEffectiveMinorVersion() {

@Override
public String getMimeType(String file) {
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
String mimeType = null;
try {
mimeType = Files.probeContentType(Paths.get(file));
}
catch (IOException | InvalidPathException e) {
log("unable to probe for content type " + file, e);
}
return mimeType;
}

@Override
Expand Down