SHARE
TWEET

Untitled

a guest Jun 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Path("/api")
  2. public class MyServer {
  3.  
  4. @GET
  5. @Consumes(MediaType.APPLICATION_XML)
  6. @Produces(MediaType.APPLICATION_XML)
  7. @Path("/my-request")
  8. public String myRequest(String type,
  9.     @Context HttpServletRequest requestContext,
  10.     @Context HttpServletResponse response) {
  11. ...
  12. }
  13.      
  14. @Path("/api")
  15. public class MyServer {
  16.  
  17.   private ScheduledExecutorService scheduler = ...;
  18.  
  19.   @GET
  20.   @Consumes(MediaType.APPLICATION_XML)
  21.   @Produces(MediaType.APPLICATION_XML)
  22.   @Path("/my-request")
  23.   public String myRequest(String type,
  24.                           @Context HttpServletRequest requestContext,
  25.                           @Context HttpServletResponse response,
  26.                           @Suspended AsyncResponse asyncResponse) {
  27.     scheduler.schedule(new Runnable() {
  28.       @Override
  29.       public void run() {
  30.         asyncResponse.resume(...)
  31.       }
  32.     }, 5, TimeUnit.SECOND);
  33.   }
  34. }
  35.      
  36. @WebFilter(urlPatterns = "/*", asyncSupported = true)
  37. @WebListener
  38. public class HttpFilter implements Filter {
  39.  
  40.     @Override
  41.    public void init(FilterConfig filterConfig) throws ServletException {   }
  42.  
  43.     @Override
  44.     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
  45.         if(denyIP(servletRequest.getRemoteAddr())) {
  46.             AsyncContext asyncContext = servletRequest.startAsync();
  47.             asyncContext.setTimeout(100000);
  48.         }else{
  49.            filterChain.doFilter(servletRequest, servletResponse);
  50.         }
  51.     }
  52.  
  53.     @Override
  54.     public void destroy() {   }
  55.  
  56.     private boolean denyIP(String address){
  57.          //todo
  58.          return true;
  59.     }
  60.  
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top