Class SwingBridgeVaadinServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
com.vaadin.flow.server.VaadinServlet
vaadinx.swing.app.SwingBridgeVaadinServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class SwingBridgeVaadinServlet extends com.vaadin.flow.server.VaadinServlet
The servlet a migrated app deploys on a plain servlet container, carrying the one piece of container wiring SB-Emulators requires — a virtual-thread-aware session lock:
@WebServlet(urlPatterns = "/*", asyncSupported = true)
public class AppServlet extends SwingBridgeVaadinServlet {}

That empty subclass is the whole host-app servlet. It exists only to carry the app's own @WebServlet mapping, which is the app's to choose.

Why the lock has to be wrapped. EHelper.callSwing runs every peer→Swing callback as a UI fiber — a virtual thread — so a modal dialog can park, and the session lock is held by the *carrier* platform thread rather than by the virtual thread mounted on it — so a virtual thread taking that lock would deadlock its session. VirtualThreadAwareLock makes both the check and the acquisition work; the loom runner's SessionLockCheck refuses a deployment that skipped it, at each session's first request (R_match_swing_errors case (9), D_vt_aware_session_lock). This class is how an app stops having to know that.

It deliberately installs no ErrorHandler — that is app policy, not runtime plumbing. Install one from a SessionInitListener, which reaches the same place as overriding createVaadinSession because ErrorEvent.findErrorHandler reads the session's handler when the error happens (D_library_servlet).

On Spring, do not use this class — the servlet has to extend SpringServlet so Vaadin's own bean-based route and instantiator discovery keeps working. See :emulators-spring, which auto-configures the equivalent.

An app needing its own VaadinServletService overrides createSwingBridgeService(DeploymentConfiguration), not createServletService — which is final here, so the wrap cannot be dropped and service.init() cannot be forgotten. SamplerServlet is the worked example. An app whose service must extend something else entirely cannot use this class at all: extend VaadinServlet and apply VirtualThreadAwareLock.wrap(VaadinService, WrappedSession, Lock) in your own getSessionLock, which is public for exactly that case.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A VaadinServletService whose session lock is virtual-thread-aware.
  • Field Summary

    Fields inherited from class com.vaadin.flow.server.VaadinServlet

    INTERNAL_VAADIN_SERVLET_VITE_DEV_MODE_FRONTEND_PATH

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final com.vaadin.flow.server.VaadinServletService
    createServletService(com.vaadin.flow.function.DeploymentConfiguration configuration)
    final on purpose: this is the seam through which the session-lock wrap could be lost silently, and losing it surfaces later and elsewhere as a StackOverflowError in Vaadin internals.
    createSwingBridgeService(com.vaadin.flow.function.DeploymentConfiguration configuration)
    The service this servlet runs on, before init().

    Methods inherited from class com.vaadin.flow.server.VaadinServlet

    createDeploymentConfiguration, createDeploymentConfiguration, createServletService, createStaticFileHandler, createVaadinRequest, destroy, getCurrent, getFrontendMapping, getLastPathParameter, getService, getServletConfig, handleContextOrServletRootWithoutSlash, init, serveStaticOrWebJarRequest, service, servletInitialized, whenFrontendMappingAvailable

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, service

    Methods inherited from class jakarta.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SwingBridgeVaadinServlet

      public SwingBridgeVaadinServlet()
  • Method Details

    • createServletService

      protected final com.vaadin.flow.server.VaadinServletService createServletService(com.vaadin.flow.function.DeploymentConfiguration configuration) throws com.vaadin.flow.server.ServiceException
      final on purpose: this is the seam through which the session-lock wrap could be lost silently, and losing it surfaces later and elsewhere as a StackOverflowError in Vaadin internals. Override createSwingBridgeService(DeploymentConfiguration) instead.
      Overrides:
      createServletService in class com.vaadin.flow.server.VaadinServlet
      Throws:
      com.vaadin.flow.server.ServiceException
    • createSwingBridgeService

      protected SwingBridgeVaadinServlet.SwingBridgeVaadinServletService createSwingBridgeService(com.vaadin.flow.function.DeploymentConfiguration configuration) throws com.vaadin.flow.server.ServiceException
      The service this servlet runs on, before init(). Override to add your own service behaviour; the return type is what keeps the session-lock wrap in place whatever you return.
      Returns:
      a new instance, uninitialized — createServletService(DeploymentConfiguration) calls init()
      Throws:
      com.vaadin.flow.server.ServiceException