I am new using undertow, I'm developing a stand alone application that will use this as embedded server. I wish I could deploy web sockets, servlets, and restfull htmls services within my embedded undertow.
So far I've only done the test with web sockets and servlets, the problem that each separate function properly, but deploy them together web sockets not I access from a test page with HTML and JavaScript, if I remove the servlet page nigun test runs without error.
This is my code:
/*
* Create the appWebSocketDeploymentInfo and configure
*/
WebSocketDeploymentInfo appWebSocketDeploymentInfo = new WebSocketDeploymentInfo();
appWebSocketDeploymentInfo.setBuffers(new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 17000, 17000 * 16));
appWebSocketDeploymentInfo.addEndpoint(WebSocketEndpoint1.class);
appWebSocketDeploymentInfo.addEndpoint(WebSocketEndpoint2.class);
/*
* Create the appDeploymentInfo and configure
*/
DeploymentInfo appDeploymentInfo = Servlets.deployment()
.setClassLoader(Server.class.getClassLoader())
.setContextPath("/myapp)
.setDeploymentName("app.war")
.setResourceManager(new FileResourceManager(new File("src/main/webapp"), 1024))
.addServlets(Servlets.servlet("HomeServlet", HomeServlet.class).addMapping("/home"))
.setResourceManager(new ClassPathResourceManager(Server.class.getClassLoader(), Server.class.getPackage()))
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, appWebSocketDeploymentInfo);
/*
* Create the deploymentManager
*/
deploymentManager = Servlets.defaultContainer().addDeployment(appDeploymentInfo);
/*
* Deploy the app
*/
deploymentManager.deploy();
/*
* Create the path handle
*/
pathHandler = Handlers.path(Handlers.redirect("/myapp/home")).addPrefixPath("/myapp", deploymentManager.start());
/*
* Create the server
*/
undertowServer = Undertow.builder().addHttpListener(DEFAULT_PORT, DEFAULT_IP).setHandler(pathHandler).build();
The javascript log error is
WebSocket connection to 'ws://localhost:8080/fermat/node-channel' failed: Error during WebSocket handshake: Unexpected response code: 404