All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javawebstack.httpserver.websocket.InternalWebSocketRequestHandler Maven / Gradle / Ivy

Go to download

This library provides a routing and request mapping stack on top of the well known and industry proven eclipse jetty http server. It also supports websockets.

There is a newer version: 1.0.2
Show newest version
package org.javawebstack.httpserver.websocket;

import org.eclipse.jetty.server.Request;
import org.javawebstack.httpserver.Exchange;
import org.javawebstack.httpserver.handler.RequestHandler;
import org.javawebstack.httpserver.handler.WebSocketHandler;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.UUID;

public class InternalWebSocketRequestHandler implements RequestHandler {
    private final WebSocketHandler handler;

    public InternalWebSocketRequestHandler(WebSocketHandler handler) {
        this.handler = handler;
    }

    public Object handle(Exchange exchange) {
        String id = UUID.randomUUID().toString();
        exchange.rawResponse().setHeader("X-Server-WSID", id);
        InternalWebSocketAdapter.webSockets.put(id, new WebSocket(exchange, handler));
        try {
            exchange.getServer().getInternalWebSocketHandler().handle(exchange.getPath(), (Request) exchange.rawRequest(), exchange.rawRequest(), exchange.rawResponse());
        } catch (IOException | ServletException ignored) {
            ignored.printStackTrace();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy