blob: 17a8e7501c53b1f0e0301f92e98bfae40eca1f6b [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
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.
-->
<html>
<head>
<link type="text/css" rel="stylesheet" href="/resources/site.css">
<script src='/resources/space.js'></script>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture, web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support, integration standards, application integration, middleware, software, solutions, services, CXF, open source">
<meta name="description" content="Apache CXF, Services Framework - SSE">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shCoreCXF.css">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shThemeCXF.css">
<script src='/resources/highlighter/scripts/shCore.js'></script>
<script src='/resources/highlighter/scripts/shBrushBash.js'></script>
<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script src='/resources/highlighter/scripts/shBrushJava.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
</script>
<title>
Apache CXF -- SSE
</title>
</head>
<body onload="init()">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td id="cell-0-0" colspan="2">&nbsp;</td>
<td id="cell-0-1">&nbsp;</td>
<td id="cell-0-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-1-0">&nbsp;</td>
<td id="cell-1-1">&nbsp;</td>
<td id="cell-1-2">
<!-- Banner -->
<div class="banner" id="banner"><div><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left" colspan="1" nowrap>
<a shape="rect" href="http://cxf.apache.org/" title="Apache CXF"><span style="font-weight: bold; font-size: 170%; color: white">Apache CXF</span></a>
</td><td align="right" colspan="1" nowrap>
<a shape="rect" href="http://www.apache.org/" title="The Apache Sofware Foundation"><img border="0" alt="ASF Logo" src="http://cxf.apache.org/images/asf-logo.png"></a>
</td></tr></table></div></div>
<!-- Banner -->
<div id="top-menu">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<td>
<div align="left">
<!-- Breadcrumbs -->
<a href="index.html">Index</a>&nbsp;&gt;&nbsp;<a href="transports.html">Transports</a>&nbsp;&gt;&nbsp;<a href="sse.html">SSE</a>
<!-- Breadcrumbs -->
</div>
</td>
<td>
<div align="right">
<!-- Quicklinks -->
<div id="quicklinks"><p><a shape="rect" href="http://cxf.apache.org/download.html">Download</a> | <a shape="rect" href="http://cxf.apache.org/docs/index.html">Documentation</a></p></div>
<!-- Quicklinks -->
</div>
</td>
</tr>
</table>
</div>
</td>
<td id="cell-1-3">&nbsp;</td>
<td id="cell-1-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-2-0" colspan="2">&nbsp;</td>
<td id="cell-2-1">
<table>
<tr valign="top">
<td height="100%">
<div id="wrapper-menu-page-right">
<div id="wrapper-menu-page-top">
<div id="wrapper-menu-page-bottom">
<div id="menu-page">
<!-- NavigationBar -->
<div id="navigation"><ul class="alternate"><li><a shape="rect" href="overview.html">Overview</a></li><li><a shape="rect" href="how-tos.html">How-Tos</a></li><li><a shape="rect" href="frontends.html">Frontends</a></li><li><a shape="rect" href="databindings.html">DataBindings</a></li><li><a shape="rect" href="transports.html">Transports</a></li><li><a shape="rect" href="configuration.html">Configuration</a></li><li><a shape="rect" href="debugging-and-logging.html">Debugging and Logging</a></li><li><a shape="rect" href="tools.html">Tools</a></li><li><a shape="rect" href="restful-services.html">RESTful Services</a></li><li><a shape="rect" href="wsdl-bindings.html">WSDL Bindings</a></li><li><a shape="rect" href="service-routing.html">Service Routing</a></li><li><a shape="rect" href="dynamic-languages.html">Dynamic Languages</a></li><li><a shape="rect" href="ws-support.html">WS-* Support</a></li><li><a shape="rect" href="advanced-integration.html">Advanced Integration</a></li><li><a shape="rect" href="deployment.html">Deployment</a></li><li><a shape="rect" href="schemas-and-namespaces.html">Use of Schemas and Namespaces</a></li></ul><hr><ul class="alternate"><li><p>Search</p></li></ul><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="002890367768291051730:o99qiwa09y4">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" name="q" size="21">
<input type="submit" name="sa" value="Search">
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.2.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.1.x/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul><p>&#160;</p><p><a shape="rect" class="external-link" href="http://www.apache.org/events/current-event.html"><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.apache.org/events/current-event-125x125.png" data-image-src="http://www.apache.org/events/current-event-125x125.png"></span></a></p></div>
<!-- NavigationBar -->
</div>
</div>
</div>
</div>
</td>
<td height="100%">
<!-- Content -->
<div class="wiki-content">
<div id="ConfluenceContent"><h2 id="SSE-/*&lt;![CDATA[*/div.rbtoc1636141732635{padding:0px;}div.rbtoc1636141732635ul{list-style:disc;margin-left:0px;}div.rbtoc1636141732635li{margin-left:0px;padding-left:0px;}/*]]&gt;*/#SSE-Introduction#SSE-IntroductionSince3.2.5release#SSE-Since3.2.5releaseConfi"><style type="text/css">/*<![CDATA[*/
div.rbtoc1636141732635 {padding: 0px;}
div.rbtoc1636141732635 ul {list-style: disc;margin-left: 0px;}
div.rbtoc1636141732635 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style></h2><div class="toc-macro rbtoc1636141732635">
<ul class="toc-indentation"><li><a shape="rect" href="#SSE-"></a></li><li><a shape="rect" href="#SSE-Introduction">Introduction</a></li><li><a shape="rect" href="#SSE-Since3.2.5release">Since 3.2.5 release</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SSE-Configuration">Configuration</a></li><li><a shape="rect" href="#SSE-AdditionalProperties">Additional Properties</a></li><li><a shape="rect" href="#SSE-OSGi">OSGi</a></li></ul>
</li><li><a shape="rect" href="#SSE-Before3.2.5release">Before 3.2.5 release</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SSE-Configuration.1">Configuration</a></li><li><a shape="rect" href="#SSE-AdvancedConfiguration">Advanced Configuration</a></li><li><a shape="rect" href="#SSE-OSGi.1">OSGi</a></li></ul>
</li></ul>
</div><h2 id="SSE-Introduction">Introduction</h2><p>The <a shape="rect" class="external-link" href="https://jcp.org/en/jsr/detail?id=370" rel="nofollow">JAX-RS 2.1</a> introduced the support of server-sent events (SSE).</p><h2 id="SSE-Since3.2.5release">Since 3.2.5 release</h2><p>Thanks to the community contribution, the SSE implementation has been revamped significantly in <strong>3.2.5</strong> release and does not depend on any additional transport or/and library.</p><h3 id="SSE-Configuration">Configuration</h3><p>In most cases the SSE providers are going to be activated automatically, either though <strong>SseProvidersExtension</strong> or <strong>SseTransportCustomizationExtension</strong>. However, in case there is a need to manually add SSE support, it could be done by including <strong>SseFeature</strong>, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(&lt;application&gt;, JAXRSServerFactoryBean.class);
factory.setFeatures(Arrays.asList(new SseFeature()));
...
return factory.create();</pre>
</div></div><h3 id="SSE-AdditionalProperties">Additional Properties</h3><p>There are a couple of contextual properties which allow to fine-tune the Apache CXF SSE implementation to a particular context.</p><div class="table-wrap"><table class="confluenceTable"><colgroup span="1"><col span="1"><col span="1"><col span="1"></colgroup><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Property</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th><th colspan="1" rowspan="1" class="confluenceTh">Default</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>org.apache.cxf.sse.sink.buffer.size</strong></td><td colspan="1" rowspan="1" class="confluenceTd"><p>By default, the SSE events are scheduled in batches and than flushed one by one. <br clear="none">If the buffer overflows, no more events are going to be accepted (and consequently, the error is returned).<br clear="none">The size of the buffer could be controlled using this property (if default is not suitable).</p></td><td colspan="1" rowspan="1" class="confluenceTd">10000</td></tr></tbody></table></div><h3 id="SSE-OSGi">OSGi</h3><p>For the deployments inside OSGi containers (like Apache Karaf), <strong>Apache CXF</strong> provides a dedicated <strong>cxf-sse</strong> feature (which depends on <strong>cxf-http</strong> and <strong>cxf-jaxrs</strong>).</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>karaf@root()&gt; feature:install cxf-sse </pre>
</div></div><p>&#160;Once installed, the dependent bundles could benefit from SSE capabilities by specifying desired transport in the Blueprint configuration, for example.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&lt;blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd"&gt;
&lt;bean id="sseFeature" class="org.apache.cxf.jaxrs.sse.SseFeature" /&gt;
&#160;&lt;cxf:bus&gt;
&lt;cxf:features&gt;
&lt;cxf:logging /&gt;
&lt;/cxf:features&gt;
&lt;/cxf:bus&gt;
&lt;jaxrs:server id="sseSampleService" address="/"&gt;
&lt;jaxrs:serviceBeans&gt;
&lt;ref component-id="..." /&gt;
&lt;/jaxrs:serviceBeans&gt;
&lt;jaxrs:providers&gt;
&lt;ref component-id="..." /&gt;
&lt;/jaxrs:providers&gt;
&lt;jaxrs:features&gt;
&lt;ref component-id="sseFeature" /&gt;
&lt;/jaxrs:features&gt;
&#160;&lt;/jaxrs:server&gt;
&lt;/blueprint&gt;</pre>
</div></div><h2 id="SSE-Before3.2.5release">Before 3.2.5 release</h2><p>Although SSE in general works on top of HTTP transport, the SSE implementation in CXF uses the dedicated one, based on <a shape="rect" class="external-link" href="https://github.com/Atmosphere/atmosphere" rel="nofollow">Atmosphere</a> framework. This transport only required on the server-side (client side works over normal HTTP) and is fully compatible with HTTP transport.</p><h3 id="SSE-Configuration.1">Configuration</h3><p>There are several ways to configure SSE transport (and as the consequence, SSE support). The most straightforward one is to pass the init parameter&#160;<strong>"transportId"</strong> to the CXF servlet in question, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">final CXFNonSpringServlet cxfServlet = new CXFNonSpringServlet();
final ServletHolder holder = new ServletHolder(cxfServlet);
holder.setInitParameter(CXFCdiServlet.TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID);
...</pre>
</div></div><p>In this case the <strong>JAXRSServerFactoryBean</strong> instances should also specify the SSE transport during construction time, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(&lt;application&gt;, JAXRSServerFactoryBean.class);
factory.setTransportId(SseHttpTransportFactory.TRANSPORT_ID);
...
return factory.create();</pre>
</div></div><h3 id="SSE-AdvancedConfiguration">Advanced Configuration</h3><p>Since <strong>Apache CXF 3.2.3</strong> release, it is possible to use alternative means to configure transports, including SSE one, by passing it through the <strong>Bus</strong> property "<a shape="rect" class="external-link" href="http://org.apache.cxf.preferred.transport.id" rel="nofollow">org.apache.cxf.preferred.transport.id</a>" (also available as <strong>AbstractTransportFactory.PREFERRED_TRANSPORT_ID</strong> constant). With this property set to preferred transport, CXF servlet in question is going to pick it up instead of using the default one. SSE implementation benefits from that and in many cases setting the <strong>"transportId" </strong>init parameter on the servlet level could be omitted.</p><h3 id="SSE-OSGi.1">OSGi</h3><p>For the deployments inside OSGi containers (like Apache Karaf), <strong>Apache CXF</strong> provides a dedicated <strong>cxf-sse</strong> feature (which depends on <strong>cxf-http</strong> and <strong>cxf-jaxrs</strong>).</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>karaf@root()&gt; feature:install cxf-sse </pre>
</div></div><p>Once installed, the dependent bundles could benefit from SSE capabilities by specifying desired transport in the Blueprint configuration, for example.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">&lt;blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd"&gt;
&lt;cxf:bus&gt;
&lt;cxf:features&gt;
&lt;cxf:logging /&gt;
&lt;/cxf:features&gt;
&lt;/cxf:bus&gt;
&lt;jaxrs:server id="sseSampleService" address="/" transportId="http://cxf.apache.org/transports/http/sse"&gt;
&lt;jaxrs:serviceBeans&gt;
&lt;ref component-id="..." /&gt;
&lt;/jaxrs:serviceBeans&gt;
&lt;jaxrs:providers&gt;
&lt;ref component-id="..." /&gt;
&lt;/jaxrs:providers&gt;
&lt;/jaxrs:server&gt;
&lt;/blueprint&gt;</pre>
</div></div></div>
</div>
<!-- Content -->
</td>
</tr>
</table>
</td>
<td id="cell-2-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-3-0">&nbsp;</td>
<td id="cell-3-1">&nbsp;</td>
<td id="cell-3-2">
<div id="footer">
<!-- Footer -->
<div id="site-footer">
<a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a> -
(<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=75974373">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=75974373&amp;showComments=true&amp;showCommentArea=true#addcomment">add comment</a>)<br>
Apache CXF, CXF, Apache, the Apache feather logo are trademarks of The Apache Software Foundation.<br>
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</div>
<!-- Footer -->
</div>
</td>
<td id="cell-3-3">&nbsp;</td>
<td id="cell-3-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-4-0" colspan="2">&nbsp;</td>
<td id="cell-4-1">&nbsp;</td>
<td id="cell-4-2" colspan="2">&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4458903-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>