Jest w ogóle możliwe aby na jednym serwerze Jetty postawić websocket i jakieś restowe aplikacje?
Gdy dodam tylko kontekst samego websocketa to działa ale mam problem po dodaniu 2 kontekstów rest działa natomiast przy połączeniu do websocket dostaje komunikat:
onWebSocketError22: org.eclipse.jetty.websocket.api.UpgradeException: Didn't switch protocols
Główna aplikacja:
public class ServerProcess extends WebSocketHandler {
public static void main(String[] args) throws IOException, ClassNotFoundException {
int serverPort = ServerConfiguration.getConfiguration().getServerPort();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("src/main/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("159357258456");
SslConnectionFactory sslConne = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString());
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecureScheme("https");
http_config.setSecurePort(serverPort);
http_config.setOutputBufferSize(Integer.MAX_VALUE);
http_config.setRequestHeaderSize(8192);
http_config.setResponseHeaderSize(8192);
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory cf = new HttpConnectionFactory(https_config);
//rest
ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setContextPath("/");
ServletHolder jerseyServlet = servletContext.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
RestTest.class.getCanonicalName());
ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
contextHandlers.setHandlers(new Handler[]
{servletContext, new ServerProcess()});
Server server = new Server();
ServerConnector connector = new ServerConnector(server, sslConne, cf);
connector.setPort(serverPort);
server.addConnector(connector);
server.setHandler(contextHandlers);
try {
server.start();
server.dump(System.err);
server.join();
} catch (Exception e) {
}
}
@Override
public void configure(WebSocketServletFactory factory) {
factory.register(SocketService.class);
}
}
REST:
@Path("/entry-point")
public class RestTest {
@GET
@Path("test")
@Produces(MediaType.TEXT_PLAIN)
public String test() {
return "Test";
}
}