CitizenIntelligenceAgencySpringVaadinServlet.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of 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,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application;

  20. import java.io.IOException;

  21. import javax.servlet.ServletException;
  22. import javax.servlet.annotation.WebServlet;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;

  25. import com.vaadin.annotations.VaadinServletConfiguration;
  26. import com.vaadin.server.DefaultUIProvider;
  27. import com.vaadin.server.UIProvider;
  28. import com.vaadin.server.VaadinServletService;
  29. import com.vaadin.server.VaadinSession;
  30. import com.vaadin.spring.internal.UIScopeImpl;
  31. import com.vaadin.spring.internal.VaadinSessionScope;
  32. import com.vaadin.spring.server.SpringVaadinServlet;

  33. /**
  34.  * The Class CitizenIntelligenceAgencySpringVaadinServlet.
  35.  */
  36. @WebServlet(value = "/*", loadOnStartup = 2, asyncSupported = true)
  37. @VaadinServletConfiguration(productionMode = true, ui = CitizenIntelligenceAgencyUI.class, widgetset = "com.hack23.cia.web.widgets.WebWidgetSet")
  38. public final class CitizenIntelligenceAgencySpringVaadinServlet extends SpringVaadinServlet {

  39.     /** The Constant serialVersionUID. */
  40.     private static final long serialVersionUID = 1L;

  41.     /**
  42.      * Default constructor for CitizenIntelligenceAgencySpringVaadinServlet.
  43.      */
  44.     public CitizenIntelligenceAgencySpringVaadinServlet() {
  45.         // Default constructor
  46.     }

  47.     @Override
  48.     protected void service(final HttpServletRequest request, final HttpServletResponse response)
  49.             throws ServletException, IOException {
  50.         response.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
  51.         super.service(request, response);
  52.     }

  53.     @Override
  54.     protected void servletInitialized() throws ServletException {
  55.         final VaadinServletService service = getService();
  56.         service.addSessionInitListener(event -> {
  57.             final VaadinSession session = event.getSession();
  58.             for (final UIProvider provider : session.getUIProviders()) {
  59.                 if (DefaultUIProvider.class.getCanonicalName().equals(provider.getClass().getCanonicalName())) {
  60.                     session.removeUIProvider(provider);
  61.                 }
  62.             }
  63.             session.addUIProvider(new CustomSpringUIProvider(session));
  64.         });
  65.         service.addSessionDestroyListener(event -> {
  66.             final VaadinSession session = event.getSession();
  67.             UIScopeImpl.cleanupSession(session);
  68.             VaadinSessionScope.cleanupSession(session);
  69.         });
  70.     }
  71. }