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