Search in sources :

Example 6 with DeploymentException

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

the class BasicEchoEndpointContextListener method contextInitialized.

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

Example 7 with DeploymentException

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

the class Client method main.

public static void main(String[] args) {
    try {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://echo.websocket.org:80/";
        System.out.println("Connecting to " + uri);
        container.connectToServer(MyClientEndpoint.class, URI.create(uri));
        messageLatch.await(100, TimeUnit.SECONDS);
    } catch (DeploymentException | InterruptedException | IOException ex) {
        Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) IOException(java.io.IOException)

Example 8 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, 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(TestClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) PrintWriter(java.io.PrintWriter)

Example 9 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>");
        List<Class<? extends Encoder>> encoders = new ArrayList<>();
        encoders.add(MyMessageEncoder.class);
        List<Class<? extends Decoder>> decoders = new ArrayList<>();
        decoders.add(MyMessageDecoder.class);
        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().encoders(encoders).decoders(decoders).build(), URI.create(uri));
        out.println("<br><br>Look in server.log for message exchange between client/server.");
        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) Encoder(javax.websocket.Encoder) ArrayList(java.util.ArrayList) Class(java.lang.Class) DeploymentException(javax.websocket.DeploymentException) Decoder(javax.websocket.Decoder) PrintWriter(java.io.PrintWriter)

Example 10 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, null, URI.create(uri));
        out.println("<br><br>Look in server.log for message exchange between client/server.");
        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)

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