Giter Site home page Giter Site logo

async-servlet-with-filter's Introduction

async-servlet-with-filter

This project demonstrates asynchronous Servlet 3 filters.

Run the application in a Tomcat container or directly with Jetty

> ./gradlew runJetty

and open http://localhost:8080

Description

  1. First the filter is called with dispatch type REQUEST
  2. An AsyncContext is started
  3. A asynchronous request (to http://checkip.amazonaws.com) is done and the doFilter method exits
  4. When the callback on the asynchronous call returns the dispatch() is called on the AsyncContext
  5. The request is dispatched again through the doFilter method, this time with dispatch type ASYNC
  6. This time we call chain.doFilter() and the request enters the servlets doGet() method
  7. A new AsyncContext is started and a asynchronous dispatch to a JSP page is done on an other thread
  8. The servlets doGet() method exits and control is returned to the filter that registers an AsyncListener
  9. The onStartAsync() is called on the AsyncListener
  10. The filters doFilter() method exits
  11. The response from the jsp is returned

Printout is something like this in Tomcat 8: (In Jetty 9 the last row is missing...)

WaitFilter::doFilter: >>> Start
Filter::doFilter: [REQUEST] Start >>> (Thread[http-nio-8080-exec-6,5,main])
Filter::doFilter: [REQUEST] End <<< (Thread[http-nio-8080-exec-6,5,main])
Filter::doFilter: <<< End 
Filter::doFilter: [REQUEST] AsyncResponse <<< (Thread[New I/O worker #1,5,RMI Runtime]), attr=81.170.155.156 
Filter::doFilter: >>> Start
Filter::doFilter: [ASYNC] before doFilter >>> (Thread[http-nio-8080-exec-7,5,main])
Servlet::doGet: Start >>> (Thread[http-nio-8080-exec-7,5,main])
AsyncListener::onStartAsync(Thread[http-nio-8080-exec-7,5,main])
Servlet::doGet: End <<< (Thread[http-nio-8080-exec-7,5,main])
Filter::doFilter: [ASYNC] after doFilter <<< (Thread[http-nio-8080-exec-7,5,main])
Servlet::In Async(Thread[pool-1-thread-1,5,RMI Runtime])
Filter::doFilter: <<< End 
Hello in JSP (Thread[http-nio-8080-exec-8,5,main]) attr=81.170.155.156 
AsyncListener::onComplete(Thread[http-nio-8080-exec-8,5,main])

async-servlet-with-filter's People

Contributors

parwen68 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.