Author: buildbot
Date: Tue Feb 6 04:57:28 2018
New Revision: 1024920
Log:
Production update by buildbot for cxf
Modified:
websites/production/cxf/content/cache/docs.pageCache
websites/production/cxf/content/docs/using-cxf-and-cdi-11-jsr-346.html
Modified: websites/production/cxf/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/cxf/content/docs/using-cxf-and-cdi-11-jsr-346.html
==============================================================================
--- websites/production/cxf/content/docs/using-cxf-and-cdi-11-jsr-346.html
(original)
+++ websites/production/cxf/content/docs/using-cxf-and-cdi-11-jsr-346.html Tue
Feb 6 04:57:28 2018
@@ -32,8 +32,8 @@
<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/shBrushXml.js'></script>
<script src='/resources/highlighter/scripts/shBrushJava.js'></script>
+<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
@@ -117,7 +117,7 @@ Apache CXF -- Using CXF and CDI 1.1 (JSR
<td height="100%">
<!-- Content -->
<div class="wiki-content">
-<div id="ConfluenceContent"><h1
id="UsingCXFandCDI1.1(JSR-346)-Introduction">Introduction </h1><p>The
JAX-RS 2.0 specification (JSR-339) mandates the support of CDI 1.1 (JSR-346)
and Apache CXF starting from the version 3.0 introduces the initial support of
this feature. As the starting point, the emphasis has been done on supporting
embedded Jety 8/9 and Tomcat 7/8 containers as primary deployment (though other
application servers will be supported in the future). </p><h1
id="UsingCXFandCDI1.1(JSR-346)-Architectureanddesign">Architecture and
design </h1><p>At the moment, the integration of Apache CXF and CDI
revolves around two key components, which reside in the new module called
<strong>cxf-integration-cdi</strong></p><ul><li><strong>CXFCdiServlet</strong>
servlet</li><li><strong>JAXRSCdiResourceExtension</strong> portable CDI
extension</li></ul><p>The fact of including
<strong>cxf-integration-cdi</strong> as a dependency allows 
<strong>JAXRSCdiResourceExtens
ion</strong>  portable CDI extension to be discovered by CDI
container. The  <strong>JAXRSCdiResourceExtension</strong> creates the
instance of the <strong>Bus</strong> and registers it with
<strong>BeanManager</strong>. From this point, the  <strong>Bus</strong>
instance is a regular CDI bean (with
<span><strong>@</strong><span><strong>Application</strong> scope)</span></span>
available for injection. This instance of the  <strong>Bus</strong>
is being injected into <strong>CXFCdiServlet</strong> servlet once it is
initialized by servlet container.</p><p>Depending on the design,
<strong>JAXRSCdiResourceExtension</strong> may use zero-based configuration
approach or rely on particular JAX-RS <strong>Application</strong> instances.
The <strong>org.apache.cxf.cdi.CXFCdiServlet</strong> should be configured
as well (more examples for programmatic and WAR scenarios below).</p><h1
id="UsingCXFandCDI1.1(JSR-346)-Zero-basedConfiguration">Ze
ro-based Configuration</h1><p>If the Apache CXF application contains only one
single instance of JAX-RS <strong>Application</strong> (annotated with
<strong>@ApplicationPath</strong>) with no singletons and classes defined, the
following rules are being applied by <strong>JAXRSCdiResourceExtension</strong>
in order to configure and publish the configured JAX-RS
resources:</p><ul><li>the instance of the JAX-RS <strong>Application</strong>
(annotated with <strong>@ApplicationPath</strong>) is being created and
registered with <strong>BeanManager</strong></li><li>all instances of the
discovered JAX-RS <strong>providers </strong>(annotated with
<strong>@Provider</strong>) are being created and registered with
<strong>BeanManager</strong></li><li>all instances of the discovered JAX-RS
<strong>resources</strong> (annotated with <strong>@Path</strong>) are being
created and registered with <strong>BeanManager</strong></li></ul><p>Lastly,
the instance of the <strong>JAXRSServerFactoryBean</
strong> is being created and configured with all service beans and providers
discovered before. Additionally, the providers are enriched with the services
for <strong>javax.ws.rs.ext.MessageBodyReader</strong> and
<strong>javax.ws.rs.ext.MessageBodyWriter</strong>, loaded via
<strong>ServiceLoader</strong>. From this moment, Apache CXF application is
ready to serve the requests. The quick example is shown below.</p><p>The empty
JAX-RS <strong>Application</strong>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div id="ConfluenceContent"><h1
id="UsingCXFandCDI1.1(JSR-346)-Introduction">Introduction </h1><p>The
JAX-RS 2.0 specification (JSR-339) mandates the support of CDI 1.1 (JSR-346)
and Apache CXF starting from the version 3.0 introduces the initial support of
this feature. As the starting point, the emphasis has been done on supporting
embedded Jety 8/9 and Tomcat 7/8 containers as primary deployment (though other
application servers will be supported in the future). </p><h1
id="UsingCXFandCDI1.1(JSR-346)-Architectureanddesign">Architecture and
design </h1><p>At the moment, the integration of Apache CXF and CDI
revolves around two key components, which reside in the new module called
<strong>cxf-integration-cdi</strong></p><ul><li><strong>CXFCdiServlet</strong>
servlet</li><li><strong>JAXRSCdiResourceExtension</strong> portable CDI
extension</li></ul><p>The fact of including
<strong>cxf-integration-cdi</strong> as a dependency allows 
<strong>JAXRSCdiResourceExtens
ion</strong>  portable CDI extension to be discovered by CDI
container. The  <strong>JAXRSCdiResourceExtension</strong> creates the
instance of the <strong>Bus</strong> and registers it with
<strong>BeanManager</strong>. From this point, the  <strong>Bus</strong>
instance is a regular CDI bean (with
<span><strong>@</strong><span><strong>Application</strong> scope)</span></span>
available for injection. This instance of the  <strong>Bus</strong>
is being injected into <strong>CXFCdiServlet</strong> servlet once it is
initialized by servlet container.</p><p>Depending on the design,
<strong>JAXRSCdiResourceExtension</strong> may use zero-based configuration
approach or rely on particular JAX-RS <strong>Application</strong> instances.
The <strong>org.apache.cxf.cdi.CXFCdiServlet</strong> should be configured
as well (more examples for programmatic and WAR scenarios below).</p><h1
id="UsingCXFandCDI1.1(JSR-346)-Zero-basedConfiguration">Ze
ro-based Configuration</h1><p>If the Apache CXF application contains either no
instance of JAX-RS <strong>Application</strong> or only one single
instance of JAX-RS <strong>Application</strong> (annotated with
<strong>@ApplicationPath</strong>) with no singletons and classes defined, the
following rules are being applied by <strong>JAXRSCdiResourceExtension</strong>
in order to configure and publish the configured JAX-RS
resources:</p><ul><li>the instance of the JAX-RS <strong>Application</strong>
(annotated with <strong>@ApplicationPath</strong>) is being created and
registered with <strong>BeanManager</strong></li><li>all instances of the
discovered JAX-RS <strong>providers </strong>(annotated with
<strong>@Provider</strong>) are being created and registered with
<strong>BeanManager</strong></li><li>all instances of the discovered JAX-RS
<strong>resources</strong> (annotated with <strong>@Path</strong>) are being
created and registered with <strong>BeanManager</strong></li></
ul><p>Lastly, the instance of the <strong>JAXRSServerFactoryBean</strong> is
being created and configured with all service beans and providers discovered
before. Additionally, the providers are enriched with the services for
<strong>javax.ws.rs.ext.MessageBodyReader</strong> and
<strong>javax.ws.rs.ext.MessageBodyWriter</strong>, loaded via
<strong>ServiceLoader</strong>. From this moment, Apache CXF application is
ready to serve the requests. The quick example is shown below.</p><p>The empty
JAX-RS <strong>Application</strong>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">@ApplicationPath("/api")
public class BookStoreApplication extends Application {
}</pre>
@@ -159,7 +159,7 @@ public class BookStore {
return service.get(id);
}
}</pre>
-</div></div><h1
id="UsingCXFandCDI1.1(JSR-346)-DeployingwithembeddedJetty8/9(programmaticconfiguration)">Deploying
with embedded Jetty 8/9 (programmatic configuration)</h1><p>With <strong>Jetty
8/9</strong> it possible to create fully embeddable REST / JAX-RS servers
without <strong>web.xml</strong> or <strong>WAR</strong> files involved.
For Apache CXF applications which are using CDI 1.1,
the <strong>CXFCdiServlet</strong> servlet should be used as a
starting point. Following example demonstrates the necessary configuration
points in order to create embedded <strong>Jetty 8/9</strong> instance. As a
CDI 1.1 implementation, <strong>JBoss Weld 2.0</strong> is being used.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><h1
id="UsingCXFandCDI1.1(JSR-346)-AdditionalConfigurationCapabilities">Additional
Configuration Capabilities</h1><p>If you have a need to, you can configure the
underlying <strong>JAXRSServerFactoryBean</strong> by implementing the
interface <strong>JAXRSServerFactoryCustomizationExtension</strong>. 
Instances of this extension can be located via <strong>ServiceLoader</strong>
of as CDI beans.  You can use this to programmatically add new providers,
or otherwise manipulate the runtime before the server is created.  An
example of how this is used can be seen at <a shape="rect"
class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/cdi/SseTransportCustomizationExtension.java"
rel="nofollow">SseTransportCustomizationExtension</a>.</p><h1
id="UsingCXFandCDI1.1(JSR-346)-CDiLifecycleforJAX-RSContextObjects">CDi
Lifecycle for JAX-RS Context Objects</h1><p>The CDI extension also suppor
ts the injection (via CDI) of <strong>@Context </strong>objects. 
Any known object can be injected via CDI.  This happens automatically when
the CDI extension is used, and a <strong>@Context</strong> is declared as
a field on a resource class.  Note that this does allow you to inject
your <strong>@Context</strong> objects in non-JAX-RS components as
well.  The logic is in two parts:</p><ol><li>Rewriting injection
points<ol><li>When an injection point is found that
contains <strong>@Context</strong> two additional annotations are
added</li><li>These annotations are <strong>@Inject
</strong>and <strong>@ContextResolved</strong></li><li>The use
of <strong>@Inject </strong>will force the CDI runtime to take over the
injection of the bean value, while<strong> @ContextResolved </strong>is
simply a qualifier we apply to the injection point to avoid
ambiguities</li></ol></li><li><strong>Providing Beans</strong><ol><li>For each
of t
he built in<strong> @Context </strong>types, we register a bean that
provides a<strong> @RequestScoped </strong>bean that resolves the value,
by looking up the internal context value</li><li>In addition, a user or
intergrator can implement<strong> ContextClassProvider </strong>to register an
additional class as context type to be
resolved.</li></ol></li></ol><p> </p><h1
id="UsingCXFandCDI1.1(JSR-346)-DeployingwithembeddedJetty8/9(programmaticconfiguration)">Deploying
with embedded Jetty 8/9 (programmatic configuration)</h1><p>With <strong>Jetty
8/9</strong> it possible to create fully embeddable REST / JAX-RS servers
without <strong>web.xml</strong> or <strong>WAR</strong> files involved.
For Apache CXF applications which are using CDI 1.1,
the <strong>CXFCdiServlet</strong> servlet should be used as a
starting point. Following example demonstrates the necessary configuration
points in order to create embedded <strong>Jetty 8/9</strong> instance. As a C
DI 1.1 implementation, <strong>JBoss Weld 2.0</strong> is being used.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">System.setProperty("java.naming.factory.url",
"org.eclipse.jetty.jndi");
System.setProperty("java.naming.factory.initial",
"org.eclipse.jetty.jndi.InitialContextFactory");