| <!DOCTYPE html>
|
|
|
| <html lang="en">
|
| <head>
|
| <title>Vysper Websocket endpoint — Apache MINA</title>
|
|
|
| <link href="/assets/css/common.css" rel="stylesheet" type="text/css"/>
|
| <link href="/assets/css/vysper.css" rel="stylesheet" type="text/css"/>
|
| </head>
|
| <body>
|
| <script src="https://www.apachecon.com/event-images/snippet.js"></script>
|
| <div id="container">
|
| <div id="header">
|
| <div id="subProjectsNavBar">
|
| <a href="/">
|
|
|
| Apache MINA Project
|
|
|
| </a>
|
| |
|
| <a href="/mina-project/">
|
|
|
| MINA
|
|
|
| </a>
|
| |
|
| <a href="/asyncweb-project/">
|
|
|
| AsyncWeb
|
|
|
| </a>
|
| |
|
| <a href="/ftpserver-project/">
|
|
|
| FtpServer
|
|
|
| </a>
|
| |
|
| <a href="/sshd-project/">
|
|
|
| SSHD
|
|
|
| </a>
|
| |
|
| <a href="/vysper-project/">
|
|
|
| <strong>Vysper</strong>
|
|
|
| </a>
|
| </div>
|
| </div>
|
|
|
|
|
| <div id="content">
|
| <div id="leftColumn">
|
| <div id="navigation">
|
| <a class="acevent" data-format="wide" data-width="170"></a>
|
| <h5>Social Networks</h5>
|
| <ul>
|
| <li><a href="https://fosstodon.org/@apachemina">Apache MINA Mastodon</a></li>
|
| </ul>
|
| <h5>Overview</h5>
|
| <ul>
|
| <li><a href="/vysper-project/index.html">Home</a> </li>
|
| <li><a href="/vysper-project/documentation.html">Documentation</a></li>
|
| <li><a href="/vysper-project/downloads.html">Downloads</a></li>
|
| <li><a href="/vysper-project/sources.html">Source</a></li>
|
| </ul>
|
|
|
| <h5>Community</h5>
|
| <ul>
|
| <li><a href="/vysper-project/mailing_lists.html">Mailing Lists</a></li>
|
| <li><a href="/vysper-project/getting_involved.html">Getting Involved</a></li>
|
| <li><a href="/vysper-project/issue_tracking.html">Issue Tracking</a></li>
|
| <li><a href="https://www.apache.org/foundation/contributing.html">Contributing</a></li>
|
| <li><a href="https://www.apache.org/licenses/">License</a></li>
|
| <li><a href="https://www.apache.org/security/">Security</a></li>
|
| </ul>
|
|
|
| <h5>Sponsorship</h5>
|
| <ul>
|
| <li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
|
| <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
|
| <li><a href="https://www.apache.org/">apache.org</a></li>
|
| </ul>
|
| </div>
|
| </div>
|
| <div id="rightColumn">
|
|
|
|
|
| |
| <h1 id="websocket-endpoint">Websocket endpoint</h1> |
| <div class="info" markdown="1"> |
| Available since version 0.7. |
| </div> |
| <p>While websockets are still being specified, a draft specification for XMPP over websockets has been published at <a href="http://tools.ietf.org/html/draft-moffitt-xmpp-over-websocket-00">http://tools.ietf.org/html/draft-moffitt-xmpp-over-websocket-00</a>. Websockets enables web browsers to establish duplex communications with servers with very little overhead.</p> |
| <p>Vysper provides a websocket endpoint. The easiest way to use the endpoint is to simply add it as a regular endpoint:</p> |
| <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">XMPPServer server <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> XMPPServer<span style="color:#666">(</span><span style="color:#b44">"vysper.org"</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| |
| server<span style="color:#666">.</span><span style="color:#b44">addEndpoint</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> TCPEndpoint<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| |
| server<span style="color:#666">.</span><span style="color:#b44">addEndpoint</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> WebSocketEndpoint<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| |
| server<span style="color:#666">.</span><span style="color:#b44">start</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| </code></pre></div><p>That’s it. The default configuration will start a web server on port 8080 and supply websockets on <a href="http://vysper.org">http://vysper.org</a>:8080/.</p> |
| <p>The port and context path can be configured:</p> |
| <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">WebSocketEndpoint wsEndpoint <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> WebSocketEndpoint<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| wsEndpoint<span style="color:#666">.</span><span style="color:#b44">setContextPath</span><span style="color:#666">(</span><span style="color:#b44">"/xmpp"</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| wsEndpoint<span style="color:#666">.</span><span style="color:#b44">setPort</span><span style="color:#666">(</span>9000<span style="color:#666">)</span><span style="color:#666">;</span> |
| server<span style="color:#666">.</span><span style="color:#b44">addEndpoint</span><span style="color:#666">(</span>wsEndpoint<span style="color:#666">)</span><span style="color:#666">;</span> |
| </code></pre></div><h2 id="embedded">Embedded</h2> |
| <p>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.</p> |
| <p>Vysper currently supports this for Jetty and Apache Tomcat 7.0.27 or later.</p> |
| <p>For Jetty, add the following to your web.xml:</p> |
| <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">WebSocketEndpoint wsEndpoint <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> WebSocketEndpoint<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| wsEndpoint<span style="color:#666">.</span><span style="color:#b44">setSSLEnabled</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| wsEndpoint<span style="color:#666">.</span><span style="color:#b44">setSSLCertificateKeystore</span><span style="color:#666">(</span><span style="color:#b44">"keystore.jks"</span><span style="color:#666">,</span> <span style="color:#b44">"sekrit"</span><span style="color:#666">)</span><span style="color:#666">;</span> |
| server<span style="color:#666">.</span><span style="color:#b44">addEndpoint</span><span style="color:#666">(</span>wsEndpoint<span style="color:#666">)</span><span style="color:#666">;</span> |
| </code></pre></div><p>For Tomcat, add the following to your web.xml:</p> |
| <div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-xml" data-lang="xml"><span style="color:#008000;font-weight:bold"><servlet</span><span style="color:#008000;font-weight:bold">></span> |
| <span style="color:#008000;font-weight:bold"><servlet-name</span><span style="color:#008000;font-weight:bold">></span>WebSocket Servlet<span style="color:#008000;font-weight:bold"></servlet-name></span> |
| <span style="color:#008000;font-weight:bold"><servlet-class</span><span style="color:#008000;font-weight:bold">></span>org.apache.vysper.xmpp.extension.websockets.TomcatXmppWebSocketServlet<span style="color:#008000;font-weight:bold"></servlet-class></span> |
| <span style="color:#008000;font-weight:bold"><load-on-startup</span><span style="color:#008000;font-weight:bold">></span>1<span style="color:#008000;font-weight:bold"></load-on-startup></span> |
| <span style="color:#008000;font-weight:bold"></servlet></span> |
| <span style="color:#008000;font-weight:bold"><servlet-mapping</span><span style="color:#008000;font-weight:bold">></span> |
| <span style="color:#008000;font-weight:bold"><servlet-name</span><span style="color:#008000;font-weight:bold">></span>WebSocket Servlet<span style="color:#008000;font-weight:bold"></servlet-name></span> |
| <span style="color:#008000;font-weight:bold"><url-pattern</span><span style="color:#008000;font-weight:bold">></span>/ws<span style="color:#008000;font-weight:bold"></url-pattern></span> |
| <span style="color:#008000;font-weight:bold"></servlet-mapping></span> |
| </code></pre></div><p>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: <a href="http://svn.apache.org/repos/asf/mina/vysper/trunk/examples/embedded-war/">http://svn.apache.org/repos/asf/mina/vysper/trunk/examples/embedded-war/</a></p> |
| |
|
|
|
|
|
|
| </div>
|
| <div id="endContent"></div>
|
| </div>
|
|
|
| <div id="footer">
|
| © 2003-2024, <a href="https://www.apache.org">The Apache Software Foundation</a> - <a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy Policy</a><br />
|
| Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
|
| Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
|
| </div>
|
|
|
| </div>
|
|
|
| </body>
|
|
|
| </html>
|