Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] Programmatic WebSocket upgrade on Jetty 10
  • From: Rossen Stoyanchev <rstoyanchev@xxxxxxxxxx>
  • Date: Thu, 7 Jan 2021 22:24:14 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EgQCRcrUfkrM29tK+n+Tu0Jr4hA72IuIOHH0qNuhMlE=; b=ogYn/ME2k57esS0oUpTxPDtaE/1gEDGOhzmugTkvQaHxytGbTylP6BI/UKNOOg7wR4PEEBSnj4yjSQhM+YORk2eTuGYdBtlhI+Xt8yHPpQIqCCC9c1RW7/FSuU8COBlLzVZIcNd0n6yzfUZbfrT2QE6L/XuYhlbYkLSTpVWjI9DEmSDpQPf+Q0ySBxTzUwFDvFOZfjZtMDohv6OBTi8dZ8qGJr6axv/nkCsrSvoihv8HnoTOKGTMIxFC/MGZEvp6QoH8omDW+/PHfZekQ7cFGBWAeLu8ViXpYf/3qZgm7nTRLuybQ36waoJCROIlp66vL5WnRsQHTxBWuBRWuISZpg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eXt5f2bsTgB3tlegl+VDt/BzM+eobt8sZyXOgNJW7Z1cdULTtAaiq0kLB77f9V1XXF5GAF3ZoLWywySV+HZP8PwVY/m9b01p9K/Lm/SMJ/7tFmJwwP1H9JKYX4fzDS86YUOPa785I5B3cPkerOskvefS7fJK6y1OOLRpTErysz8tNJSuABqdpA2iGfZt6I7zRqEI/KMD1kTn/GrNJ9wPiUzsMfAJqYT9+hSdMSYZZ+XsVeQil6/BcNhBBbWfAKPRI7Er80LzA+c8jZNk9x1ZBhfN0Ja0iDLKxcp3byOnhOfBKpc+81qd4j3v3E5kqqrynCjwnzMC7fZKm5zYsxQxbg==
  • Delivered-to: jetty-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jetty-dev>
  • List-help: <mailto:jetty-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jetty-dev>, <mailto:jetty-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jetty-dev>, <mailto:jetty-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHW5UPQGT46lHN4z0a479iXmND02w==
  • Thread-topic: Programmatic WebSocket upgrade on Jetty 10

Hi,

I need to support WebSocket upgrades on Jetty 10 from within a web framework. Like what JettyWebSocketServlet or WebSocketUpgradeFilter do internally but not actually using them nor relying on their mapping mechanism.

My initial attempt at a minimal custom Servlet to do this:

@SuppressWarnings("serial")
public class MyServlet extends HttpServlet {

    private final Handshaker handshaker = new HandshakerSelector();

    private WebSocketComponents components;

    private JettyServerFrameHandlerFactory frameHandlerFactory;


    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        this.components = WebSocketServerComponents.getWebSocketComponents(getServletContext());
        this.frameHandlerFactory = JettyServerFrameHandlerFactory.getFactory(getServletContext());
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Configuration.Customizer customizer = new Configuration.ConfigurationCustomizer();
        WebSocketCreator creator = (req1, resp1) -> new MyEchoSocket();
        CreatorNegotiator negotiator = new CreatorNegotiator(creator, this.frameHandlerFactory, customizer);
        this.handshaker.upgradeRequest(negotiator, req, resp, this.components, null);
    }
}
 
However, several types are from "internal" packages. Is there a better to do this? It would be very useful to have some basic API for programmatic WebSocket upgrades from a framework or application Servlet.

Thanks,
Rossen

Back to the top