Comments (3)
My solution for now is to inherit AssetsBundle and implement the previous behavior (kotlin code):
class SPAAssetsBundle(resourcePath: String, uriPath: String, indexFile: String, assetsName: String) :
AssetsBundle(resourcePath, uriPath, indexFile, assetsName) {
override fun createServlet(): AssetServlet {
return SPAAssetServlet(resourcePath, uriPath, indexFile, defaultMediaType, StandardCharsets.UTF_8)
}
}
class SPAAssetServlet(resourcePath: String, uriPath: String, indexFile: String?, defaultMediaType: String?, defaultCharset: Charset?) :
AssetServlet(resourcePath, uriPath, indexFile, defaultMediaType, defaultCharset) {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
super.doGet(req, resp)
if (resp.status == HttpServletResponse.SC_NOT_FOUND) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND)
// or do something else...
}
}
}
Would also allow for more complex error handling.
from dropwizard.
Hi @Zinurist. The problem of using sendError
instead of setStatus
is that not catching exceptions like IOException
would lead to information exposure through the servlet container's error page mechanism. Therefore we decided to use setStatus
to keep Dropwizard safe in the default configuration.
If you want to use custom error pages through the container's error page mechanism, you can restore the previous behaviour yourself. setStatus
doesn't commit the response, so you can modify it afterwards. The following code snippet provides a very simple Filter
that resets the response and uses sendError
to trigger the error pages:
environment.servlets().addFilter("sendError", new Filter() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
filterChain.doFilter(servletRequest, servletResponse);
if (!(servletResponse instanceof HttpServletResponse)) {
throw new IllegalStateException("Expecting instance of HttpServletResponse");
}
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
int status = httpServletResponse.getStatus();
if (!httpServletResponse.isCommitted() && httpServletResponse.getStatus() >= 400) {
httpServletResponse.reset();
httpServletResponse.sendError(status);
}
}
}).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
from dropwizard.
Thank you for the help! Closing the issue since I was able to work around it.
from dropwizard.
Related Issues (20)
- Bug in hibernate 6.1.7 HOT 1
- Access log should contain the name of the authenticated user HOT 1
- Incorrect bouncy castle artifact is using under DW 4.x and 3.x version HOT 1
- Jetty 11.0.x CVE-2023-36479 and CVE-2023-40167 HOT 2
- Gradle dependency issue in v3.0.2 with Guava and Findbugs HOT 2
- Is Dropwizard affected by CVE-2023-44487? HOT 3
- Vulnerability issues with dependencies in dropwizard 4.0.1 HOT 1
- Vulnerability issues with dependencies in dropwizard 4.0.1 HOT 1
- IlligalAccesException : module com.fasterxml.jackson.module.blackbird does not read module *** HOT 12
- Incorrect javadocs for io.dropwizard.logging.common.AppenderFactory
- Dropwizard 4.0.3 not logging request logs HOT 2
- AWS Serverless Example HOT 1
- Dropwizard 4.0.2 + Hibernate + ContainerResponseFilter with NameBinding HOT 3
- Jersey client 2.21 doesnt support Transfer-encoding: chunked, is there any workaround?
- Breaking change in a version between 4.0.1 and 4.0.4 HOT 3
- DropwizardJettyServerAdapter in DropWizard3 causing exception when there are multiple HttpHeaders HOT 9
- Update Logback to fix CVE-2023-6378? HOT 4
- NPE in tests when a factory is used to inject a value to a resource method parameter HOT 2
- Managed virtual thread pool HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dropwizard.