Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1069 and add according Test #1220

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions src/main/java/spark/ExceptionMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ExceptionMapper {

Expand Down Expand Up @@ -52,7 +53,7 @@ public synchronized static ExceptionMapper getServletInstance() {
* Class constructor
*/
public ExceptionMapper() {
this.exceptionMap = new HashMap<>();
this.exceptionMap = new ConcurrentHashMap<>();
}

/**
Expand Down Expand Up @@ -94,7 +95,8 @@ public ExceptionHandlerImpl getHandler(Class<? extends Exception> exceptionClass

// No handler found either for the superclasses of the exception class
// We cache the null value to prevent future
this.exceptionMap.put(exceptionClass, null);
// We do not need to cache the null value. comment by lloyd.
// this.exceptionMap.put(exceptionClass, null);
return null;
}

Expand Down
11 changes: 3 additions & 8 deletions src/main/java/spark/embeddedserver/jetty/JettyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class JettyHandler extends SessionHandler {

private Filter filter;
private final Filter filter;

public JettyHandler(Filter filter) {
this.filter = filter;
Expand All @@ -45,16 +45,11 @@ public void doHandle(
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {

HttpRequestWrapper wrapper = new HttpRequestWrapper(request);
filter.doFilter(wrapper, response, null);

if (wrapper.notConsumed()) {
baseRequest.setHandled(false);
} else {
baseRequest.setHandled(true);
}
baseRequest.setHandled(!wrapper.notConsumed());

}

}
}
3 changes: 2 additions & 1 deletion src/main/java/spark/http/matching/MatcherFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public void doFilter(ServletRequest servletRequest,

String httpMethodStr = method.toLowerCase();
String uri = httpRequest.getRequestURI();
if (uri.length() > 1 && uri.endsWith("/"))
uri = uri.substring(0, uri.length() - 1);
String acceptType = httpRequest.getHeader(ACCEPT_TYPE_REQUEST_MIME_HEADER);

Body body = Body.create();
Expand Down Expand Up @@ -133,7 +135,6 @@ public void doFilter(ServletRequest servletRequest,
BeforeFilters.execute(context);
Routes.execute(context);
AfterFilters.execute(context);

} catch (HaltException halt) {

Halt.modify(httpResponse, body, halt);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package spark.embeddedserver.jetty;

public class JettyHandlerTest {
}