ASF Bugzilla – Attachment 33359 Details for
Bug 58751
Strange behaviour after calling sendError when an async request times out
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Sample the reproduces the problem
TomcatAsyncTimeout.java (text/plain), 2.21 KB, created by
Andy Wilkinson
on 2015-12-17 20:51:23 UTC
(
hide
)
Description:
Sample the reproduces the problem
Filename:
MIME Type:
Creator:
Andy Wilkinson
Created:
2015-12-17 20:51:23 UTC
Size:
2.21 KB
patch
obsolete
>package com.example; > >import java.io.File; >import java.io.IOException; > >import javax.servlet.AsyncContext; >import javax.servlet.AsyncEvent; >import javax.servlet.AsyncListener; >import javax.servlet.ServletException; >import javax.servlet.http.HttpServlet; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.http.HttpServletResponse; > >import org.apache.catalina.Context; >import org.apache.catalina.startup.Tomcat; >import org.apache.tomcat.util.descriptor.web.ErrorPage; > >public class TomcatAsyncTimeout { > > public static void main(String[] args) throws Exception { > Tomcat tomcat = new Tomcat(); > tomcat.setPort(8080); > Context context = tomcat.addContext("", > new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()); > tomcat.addServlet("", "timeout", AsyncServlet.class.getName()) > .setAsyncSupported(true); > tomcat.addServlet("", "error", ErrorServlet.class.getName()); > context.addServletMapping("/timeout", "timeout"); > context.addServletMapping("/error", "error"); > ErrorPage errorPage = new ErrorPage(); > errorPage.setLocation("/error"); > context.addErrorPage(errorPage); > tomcat.start(); > while (true) { > Thread.sleep(1000); > } > } > > public static class AsyncServlet extends HttpServlet { > > @Override > protected void doGet(HttpServletRequest req, HttpServletResponse resp) > throws ServletException, IOException { > AsyncContext context = req.startAsync(); > context.setTimeout(5000); > context.addListener(new AsyncListener() { > > @Override > public void onTimeout(AsyncEvent event) throws IOException { > HttpServletResponse response = (HttpServletResponse) event > .getSuppliedResponse(); > if (!response.isCommitted()) { > response.sendError(503, "Message"); > } > } > > @Override > public void onStartAsync(AsyncEvent event) throws IOException { > } > > @Override > public void onError(AsyncEvent event) throws IOException { > } > > @Override > public void onComplete(AsyncEvent event) throws IOException { > } > }); > } > > } > > public static class ErrorServlet extends HttpServlet { > > @Override > protected void doGet(HttpServletRequest req, HttpServletResponse resp) > throws ServletException, IOException { > resp.getWriter().println("Error!"); > } > > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 58751
: 33359 |
33363