You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SessionRequestHandler.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.communication;
  17. import java.io.IOException;
  18. import java.util.ArrayList;
  19. import com.vaadin.server.RequestHandler;
  20. import com.vaadin.server.VaadinRequest;
  21. import com.vaadin.server.VaadinResponse;
  22. import com.vaadin.server.VaadinSession;
  23. /**
  24. * Handles a request by passing it to each registered {@link RequestHandler} in
  25. * the session in turn until one produces a response. This method is used for
  26. * requests that have not been handled by any specific functionality in the
  27. * servlet/portlet.
  28. * <p>
  29. * The request handlers are invoked in the reverse order in which they were
  30. * added to the session until a response has been produced. This means that the
  31. * most recently added handler is used first and the first request handler that
  32. * was added to the session is invoked towards the end unless any previous
  33. * handler has already produced a response.
  34. * </p>
  35. * <p>
  36. * The session is not locked during execution of the request handlers. The
  37. * request handler can itself decide if it needs to lock the session or not.
  38. * </p>
  39. *
  40. * @see VaadinSession#addRequestHandler(RequestHandler)
  41. * @see RequestHandler
  42. *
  43. * @since 7.1
  44. */
  45. public class SessionRequestHandler implements RequestHandler {
  46. @Override
  47. public boolean handleRequest(VaadinSession session, VaadinRequest request,
  48. VaadinResponse response) throws IOException {
  49. // Use a copy to avoid ConcurrentModificationException
  50. session.lock();
  51. ArrayList<RequestHandler> requestHandlers;
  52. try {
  53. requestHandlers = new ArrayList<RequestHandler>(
  54. session.getRequestHandlers());
  55. } finally {
  56. session.unlock();
  57. }
  58. for (RequestHandler handler : requestHandlers) {
  59. if (handler.handleRequest(session, request, response)) {
  60. return true;
  61. }
  62. }
  63. // If not handled
  64. return false;
  65. }
  66. }