Title: Vysper Websocket endpoint Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. # Websocket endpoint
Available since version 0.7.
While websockets are still being specified, a draft specification for XMPP over websockets has been published at . Websockets enables web browsers to establish duplex communications with servers with very little overhead. Vysper provides a websocket endpoint. The easiest way to use the endpoint is to simply add it as a regular endpoint: :::java XMPPServer server = new XMPPServer("vysper.org"); server.addEndpoint(new TCPEndpoint()); server.addEndpoint(new WebSocketEndpoint()); server.start(); That’s it. The default configuration will start a web server on port 8080 and supply websockets on . The port and context path can be configured: :::java WebSocketEndpoint wsEndpoint = new WebSocketEndpoint(); wsEndpoint.setContextPath("/xmpp"); wsEndpoint.setPort(9000); server.addEndpoint(wsEndpoint); ## Embedded Commonly, there’s a need to use websockets within the context of a web application. For that purpose, there is a servlet available that can be configured in web.xml inside your regular application. Vysper currently supports this for Jetty and Apache Tomcat 7.0.27 or later. For Jetty, add the following to your web.xml: :::java WebSocketEndpoint wsEndpoint = new WebSocketEndpoint(); wsEndpoint.setSSLEnabled(true); wsEndpoint.setSSLCertificateKeystore("keystore.jks", "sekrit"); server.addEndpoint(wsEndpoint); For Tomcat, add the following to your web.xml: :::XML WebSocket Servlet org.apache.vysper.xmpp.extension.websockets.TomcatXmppWebSocketServlet 1 WebSocket Servlet /ws Also, when using the servlet, the main Vysper XMPP server needs to be started by some other mean, typically via a context listener. The ServerRuntimeContext of the Vysper server needs to be made available within the servlet context under the key “org.apache.vysper.xmpp.server.ServerRuntimeContext”. There’s an example application included in the Vysper distribution which does this. The source code is available here: