Refactored to this:
@WebServlet(asyncSupported = true, urlPatterns = { "/hello" })public
class MyServlet extends HttpServlet {
private static final Executor EXEC = Executors.newCachedThreadPool();
private HttpServletRequest req(AsyncContext async) {
return (HttpServletRequest) async.getRequest();
}
private HttpServletResponse res(AsyncContext async) {
return (HttpServletResponse) async.getResponse();
}
private void asyncGet(final AsyncContext async) {
EXEC.execute(new Runnable() {
public void run() {
try {
res(async).setContentType("text/plain");
Thread.sleep(2000);
PrintWriter out = res(async).getWriter();
out.println("Context path: " + req(async).getContextPath());
out.println("Servlet path: " + req(async).getServletPath());
} catch (Exception e) {
e.printStackTrace();
} finally {
async.complete();
}
}
});
}
public void doGet(final HttpServletRequest req,
final HttpServletResponse res) {
asyncGet(req.startAsync());
}
}
Same result:
Context path: null
Servlet path:
On Thu, Apr 17, 2014 at 4:21 PM, Jesse McConnell
<[email protected]>wrote:
> http://docs.oracle.com/javaee/6/api/javax/servlet/AsyncContext.html
>
> at first blush, use the variables on the async context...or try
> asyncContext.getServletRequest().getContextPath(); though not sure
> that should work for that use case
> --
> jesse mcconnell
> [email protected]
>
>
> On Thu, Apr 17, 2014 at 8:49 AM, Nils Kilden-Pedersen <[email protected]>
> wrote:
> > Should I open a bug report?
> >
> >
> > On Tue, Apr 15, 2014 at 11:36 AM, Nils Kilden-Pedersen <[email protected]
> >
> > wrote:
> >>
> >> Sorry about the delay.
> >>
> >> I tried this on 9.1.4 and got the same problem.
> >>
> >> This servlet:
> >>
> >> @WebServlet(asyncSupported=true, urlPatterns={"/hello"})
> >> public class MyServlet extends HttpServlet {
> >>
> >> private static final Executor EXEC =
> Executors.newCachedThreadPool();
> >>
> >> public void doGet(final HttpServletRequest req, final
> >> HttpServletResponse res) {
> >> final AsyncContext async = req.startAsync();
> >> EXEC.execute(new Runnable() {
> >> public void run() {
> >> try {
> >> res.setContentType("text/plain");
> >> Thread.sleep(2000);
> >> PrintWriter out = res.getWriter();
> >> out.println("Context path: " +
> req.getContextPath());
> >> out.println("Servlet path: " +
> req.getServletPath());
> >> } catch (Exception e) {
> >> e.printStackTrace();
> >> } finally {
> >> async.complete();
> >> }
> >> }
> >> });
> >> }
> >> }
> >>
> >> when put in webapps/ROOT produces this:
> >>
> >> Context path: null
> >> Servlet path:
> >>
> >>
> >>
> >> On Sun, Apr 6, 2014 at 8:06 PM, Jan Bartel <[email protected]> wrote:
> >>>
> >>> Hi Nils,
> >>>
> >>> Can you make a really simple test that reproduces?
> >>>
> >>> regards
> >>> Jan
> >>>
> >>> On 6 April 2014 04:18, Nils Kilden-Pedersen <[email protected]> wrote:
> >>> > I suspect this is a race condition related to async. If the Request
> >>> > object
> >>> > (or by extension HttpConnection), it looks like the context path (and
> >>> > other
> >>> > mutable variables) are being set/reset to null, possibly before the
> >>> > async
> >>> > context has completed.
> >>> >
> >>> > When I disabled async I could not reproduce this.
> >>> >
> >>> > On Sat, Apr 5, 2014 at 9:00 AM, Nils Kilden-Pedersen <
> [email protected]>
> >>> > wrote:
> >>> >>
> >>> >> Here are some characteristics of my app:
> >>> >>
> >>> >> Jetty 9.1.2
> >>> >>
> >>> >> Windows 8.1, haven't yet tried on Linux (probably not relevant)
> >>> >>
> >>> >> App is a folder in webapps named ROOT
> >>> >> There's no xml descriptor
> >>> >> The servlet is configured using annotations
> >>> >> The servlet is async
> >>> >>
> >>> >> So very basic setup, configuration wise.
> >>> >>
> >>> >>
> >>> >>
> >>> >> On Sat, Apr 5, 2014 at 3:27 AM, Jan Bartel <[email protected]>
> wrote:
> >>> >>>
> >>> >>> Nils,
> >>> >>>
> >>> >>> Using the standard test.war and test.xml from the jetty distro, and
> >>> >>> setting the context path to be "/", I haven't been able to
> reproduce
> >>> >>> this with jetty-9.1.3, nor actually with jetty-9.1.0. Can you
> >>> >>> reliably
> >>> >>> reproduce with the test webapp?
> >>> >>>
> >>> >>> Jan
> >>> >>>
> >>> >>> On 5 April 2014 14:05, Nils Kilden-Pedersen <[email protected]>
> wrote:
> >>> >>> > When running in the root context, request.getContextPath()
> returns
> >>> >>> > null
> >>> >>> > rather than "" as expected.
> >>> >>> >
> >>> >>> >
> >>> >>> >
> >>> >>> >
> http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getContextPath()
> >>> >>> >
> >>> >>> > This is on 9.1.2.
> >>> >>> >
> >>> >>> >
> >>> >>> > _______________________________________________
> >>> >>> > jetty-users mailing list
> >>> >>> > [email protected]
> >>> >>> > https://dev.eclipse.org/mailman/listinfo/jetty-users
> >>> >>> >
> >>> >>>
> >>> >>>
> >>> >>>
> >>> >>> --
> >>> >>> Jan Bartel <[email protected]>
> >>> >>> www.webtide.com
> >>> >>> 'Expert Jetty/CometD developer,production,operations advice'
> >>> >>> _______________________________________________
> >>> >>> jetty-users mailing list
> >>> >>> [email protected]
> >>> >>> https://dev.eclipse.org/mailman/listinfo/jetty-users
> >>> >>
> >>> >>
> >>> >
> >>> >
> >>> > _______________________________________________
> >>> > jetty-users mailing list
> >>> > [email protected]
> >>> > https://dev.eclipse.org/mailman/listinfo/jetty-users
> >>> >
> >>>
> >>>
> >>>
> >>> --
> >>> Jan Bartel <[email protected]>
> >>> www.webtide.com
> >>> 'Expert Jetty/CometD developer,production,operations advice'
> >>> _______________________________________________
> >>> jetty-users mailing list
> >>> [email protected]
> >>> https://dev.eclipse.org/mailman/listinfo/jetty-users
> >>
> >>
> >
> >
> > _______________________________________________
> > jetty-users mailing list
> > [email protected]
> > https://dev.eclipse.org/mailman/listinfo/jetty-users
> >
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users