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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations