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.

VaadinServletRequest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2000-2016 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;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletRequestWrapper;
  19. import javax.servlet.http.HttpSession;
  20. /**
  21. * Wrapper for {@link HttpServletRequest}.
  22. *
  23. * @author Vaadin Ltd.
  24. * @since 7.0
  25. *
  26. * @see VaadinRequest
  27. * @see VaadinServletResponse
  28. */
  29. public class VaadinServletRequest extends HttpServletRequestWrapper
  30. implements VaadinRequest {
  31. private final VaadinServletService vaadinService;
  32. /**
  33. * Wraps a http servlet request and associates with a vaadin service
  34. *
  35. * @param request
  36. * the http servlet request to wrap
  37. * @param vaadinService
  38. * the associated vaadin service
  39. */
  40. public VaadinServletRequest(HttpServletRequest request,
  41. VaadinServletService vaadinService) {
  42. super(request);
  43. this.vaadinService = vaadinService;
  44. }
  45. @Override
  46. public WrappedSession getWrappedSession() {
  47. return getWrappedSession(true);
  48. }
  49. @Override
  50. public WrappedSession getWrappedSession(boolean allowSessionCreation) {
  51. HttpSession session = getSession(allowSessionCreation);
  52. if (session != null) {
  53. return new WrappedHttpSession(session);
  54. } else {
  55. return null;
  56. }
  57. }
  58. /**
  59. * Gets the original, unwrapped HTTP servlet request.
  60. *
  61. * @return the servlet request
  62. */
  63. public HttpServletRequest getHttpServletRequest() {
  64. return this;
  65. }
  66. @Override
  67. public VaadinServletService getService() {
  68. return vaadinService;
  69. }
  70. /**
  71. * Gets the currently processed Vaadin servlet request. The current request
  72. * is automatically defined when the request is started. The current request
  73. * can not be used in e.g. background threads because of the way server
  74. * implementations reuse request instances.
  75. *
  76. *
  77. * @return the current Vaadin servlet request instance if available,
  78. * otherwise <code>null</code>
  79. * @since 8.1
  80. */
  81. public static VaadinServletRequest getCurrent() {
  82. VaadinRequest currentRequest = VaadinRequest.getCurrent();
  83. if (currentRequest instanceof VaadinServletRequest) {
  84. return (VaadinServletRequest) currentRequest;
  85. } else {
  86. return null;
  87. }
  88. }
  89. }