Search in sources :

Example 31 with DeploymentException

use of javax.websocket.DeploymentException in project jetty.project by eclipse.

the class PongContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(ServerContainer.class.getName());
    try {
        Configurator config = new Config();
        container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/ping").configurator(config).build());
        container.addEndpoint(ServerEndpointConfig.Builder.create(PongMessageEndpoint.class, "/pong").configurator(config).build());
        container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class, "/ping-socket").build());
        container.addEndpoint(ServerEndpointConfig.Builder.create(PongSocket.class, "/pong-socket").build());
    } catch (DeploymentException e) {
        throw new RuntimeException("Unable to add endpoint directly", e);
    }
}
Also used : Configurator(javax.websocket.server.ServerEndpointConfig.Configurator) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) DeploymentException(javax.websocket.DeploymentException) ServerContainer(javax.websocket.server.ServerContainer)

Example 32 with DeploymentException

use of javax.websocket.DeploymentException in project javaee7-samples by javaee-samples.

the class TestLocalClient method processRequest.

/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://localhost:" + request.getLocalPort() + request.getContextPath() + "/websocket";
        out.println("Connecting to " + uri);
        container.connectToServer(MyClient.class, URI.create(uri));
        out.println("<br><br>Look in server.log for log messages from message exchange between client/server.");
        out.println("</body>");
        out.println("</html>");
    } catch (DeploymentException ex) {
        Logger.getLogger(TestLocalClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) PrintWriter(java.io.PrintWriter)

Example 33 with DeploymentException

use of javax.websocket.DeploymentException in project javaee7-samples by javaee-samples.

the class TestRemoteClient method processRequest.

/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestRemoteClient</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestRemoteClient at " + request.getContextPath() + "</h1>");
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://echo.websocket.org:80/";
        out.println("Connecting to " + uri);
        container.connectToServer(MyClient.class, URI.create(uri));
        out.println("<br><br>Look in server.log for log messages from message exchange between client/server.");
        out.println("</body>");
        out.println("</html>");
    } catch (DeploymentException ex) {
        Logger.getLogger(TestRemoteClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) PrintWriter(java.io.PrintWriter)

Example 34 with DeploymentException

use of javax.websocket.DeploymentException in project javaee7-samples by javaee-samples.

the class TestClient method processRequest.

/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://localhost:" + request.getLocalPort() + request.getContextPath() + "/websocket";
        out.println("Connecting to " + uri);
        container.connectToServer(MyClient.class, ClientEndpointConfig.Builder.create().configurator(new MyConfigurator()).build(), URI.create(uri));
        out.println("<br><br>Look in server.log for message exchange between client/server and headers from configurator.");
        out.println("</body>");
        out.println("</html>");
    } catch (DeploymentException ex) {
        Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) PrintWriter(java.io.PrintWriter)

Example 35 with DeploymentException

use of javax.websocket.DeploymentException in project undertow by undertow-io.

the class AddEndpointServlet method init.

@Override
public void init(ServletConfig c) throws ServletException {
    String websocketPath = "/foo";
    ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ProgramaticEndpoint.class, websocketPath).build();
    ServerContainer serverContainer = (ServerContainer) c.getServletContext().getAttribute("javax.websocket.server.ServerContainer");
    try {
        serverContainer.addEndpoint(config);
    } catch (DeploymentException ex) {
        throw new ServletException("Error deploying websocket endpoint:", ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) DeploymentException(javax.websocket.DeploymentException) ServerContainer(javax.websocket.server.ServerContainer)

Aggregations

DeploymentException (javax.websocket.DeploymentException)36 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)16 ServerContainer (javax.websocket.server.ServerContainer)11 ServletException (javax.servlet.ServletException)7 WebSocketContainer (javax.websocket.WebSocketContainer)7 IOException (java.io.IOException)6 PrintWriter (java.io.PrintWriter)6 ArrayList (java.util.ArrayList)6 Endpoint (javax.websocket.Endpoint)5 ServerEndpoint (javax.websocket.server.ServerEndpoint)5 ExecutionException (java.util.concurrent.ExecutionException)3 ClientEndpoint (javax.websocket.ClientEndpoint)3 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)3 Extension (javax.websocket.Extension)3 WebSocketExtension (io.undertow.websockets.WebSocketExtension)2 WebSocketChannel (io.undertow.websockets.core.WebSocketChannel)2 EOFException (java.io.EOFException)2 InetSocketAddress (java.net.InetSocketAddress)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 HashMap (java.util.HashMap)2