Author: coheigea Date: Tue Aug 29 11:11:59 2017 New Revision: 1017424 Log: Updating website
Added: websites/production/cxf/content/docs/jax-rs-nio.html websites/production/cxf/content/docs/jax-rs-rxjava.html Modified: websites/production/cxf/content/cache/docs.pageCache websites/production/cxf/content/cache/main.pageCache websites/production/cxf/content/docs/a-simple-jax-ws-service.html websites/production/cxf/content/docs/jax-rs-basics.html websites/production/cxf/content/docs/jax-rs.html websites/production/cxf/content/docs/security-configuration.html websites/production/cxf/content/docs/swagger2feature.html websites/production/cxf/content/docs/writing-a-service-with-spring.html websites/production/cxf/content/fediz-downloads.html websites/production/cxf/content/fediz.html websites/production/cxf/content/index.html websites/production/cxf/content/resources-and-articles.html Modified: websites/production/cxf/content/cache/docs.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/cxf/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/cxf/content/docs/a-simple-jax-ws-service.html ============================================================================== --- websites/production/cxf/content/docs/a-simple-jax-ws-service.html (original) +++ websites/production/cxf/content/docs/a-simple-jax-ws-service.html Tue Aug 29 11:11:59 2017 @@ -28,17 +28,6 @@ <meta name="description" content="Apache CXF, Services Framework - A simple JAX-WS service"> -<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/shBrushJava.js'></script> -<script src='/resources/highlighter/scripts/shBrushXml.js'></script> -<script src='/resources/highlighter/scripts/shBrushPlain.js'></script> -<script> - SyntaxHighlighter.defaults['toolbar'] = false; - SyntaxHighlighter.all(); -</script> <title> @@ -120,14 +109,7 @@ Apache CXF -- A simple JAX-WS service <div class="wiki-content"> <div id="ConfluenceContent"><p>This example will lead you through creating your first service with doing "code first" development with JAX-WS.</p> -<style type="text/css">/*<![CDATA[*/ -div.rbtoc1497149357576 {padding: 0px;} -div.rbtoc1497149357576 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1497149357576 li {margin-left: 0px;padding-left: 0px;} - -/*]]>*/</style><div class="toc-macro rbtoc1497149357576"> -<ul class="toc-indentation"><li><a shape="rect" href="#AsimpleJAX-WSservice-Settingupyourbuild">Setting up your build</a></li><li><a shape="rect" href="#AsimpleJAX-WSservice-WritingyourService">Writing your Service</a></li><li><a shape="rect" href="#AsimpleJAX-WSservice-Publishingyourservice">Publishing your service</a></li><li><a shape="rect" href="#AsimpleJAX-WSservice-Accessingyourservice">Accessing your service</a></li></ul> -</div> + <p>This example corresponds to the <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/">java_first_jaxws</a> example in the CXF distribution.</p> @@ -141,101 +123,33 @@ div.rbtoc1497149357576 li {margin-left: <h1 id="AsimpleJAX-WSservice-WritingyourService">Writing your Service</h1> <p>First we'll write our service interface. It will have one operation called <code>sayHi</code> which says "Hello" to whoever submits their name.</p> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ - -@WebService -public interface HelloWorld { - - String sayHi(String text); - - - /* Advanced usecase of passing an Interface in. JAX-WS/JAXB does not - * support interfaces directly. Special XmlAdapter classes need to - * be written to handle them - */ - String sayHiToUser(User user); - - - /* Map passing - * JAXB also does not support Maps. It handles Lists great, but Maps are - * not supported directly. They also require use of a XmlAdapter to map - * the maps into beans that JAXB can use. - */ - @XmlJavaTypeAdapter(IntegerUserMapAdapter.class) - Map<Integer, User> getUsers(); -} -]]></script> -</div></div> +<plain-text-body>{snippet:id=service|lang=java|url=cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/main/java/demo/hw/server/HelloWorld.java}</plain-text-body> <p>To make sure your parameter is named correctly in the xml you should use:</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;"> +<plain-text-body> @WebService public interface HelloWorld { String sayHi(@WebParam(name="text") String text); } -</pre> -</div></div> +</plain-text-body> <p>The @WebParam annotation is necessary as java interfaces do not store the Parameter name in the .class file. So if you leave out the annotation your parameter will be named arg0.</p> <p>Our implementation will then look like this:</p> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ -package demo.hw.server; - -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.jws.WebService; - -@WebService(endpointInterface = "demo.hw.server.HelloWorld", - serviceName = "HelloWorld") -public class HelloWorldImpl implements HelloWorld { - Map<Integer, User> users = new LinkedHashMap<Integer, User>(); - - - public String sayHi(String text) { - System.out.println("sayHi called"); - return "Hello " + text; - } - - public String sayHiToUser(User user) { - System.out.println("sayHiToUser called"); - users.put(users.size() + 1, user); - return "Hello " + user.getName(); - } - - public Map<Integer, User> getUsers() { - System.out.println("getUsers called"); - return users; - } - -} -]]></script> -</div></div> +<plain-text-body>{snippet:id=service|lang=java|url=cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/main/java/demo/hw/server/HelloWorldImpl.java}</plain-text-body> <p>The @WebService annotation on the implementation class lets CXF know which interface we want to create our WSDL with. In this case its simply our HelloWorld interface.</p> <h1 id="AsimpleJAX-WSservice-Publishingyourservice">Publishing your service</h1> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ -System.out.println("Starting Server"); -HelloWorldImpl implementor = new HelloWorldImpl(); -String address = "http://localhost:9000/helloWorld"; -Endpoint.publish(address, implementor); -]]></script> -</div></div> +<plain-text-body>{snippet:id=publish|lang=java|url=cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/main/java/demo/hw/server/Server.java}</plain-text-body> <p>whole code at <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/main/java/demo/hw/server/Server.java">http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/main/java/demo/hw/server/Server.java</a></p> <p>Alternatively you can use the following code. This gives you more control over the behaviour. For example you can add a logging interceptor:</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;"> +<plain-text-body> HelloWorldImpl implementor = new HelloWorldImpl(); JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean(); svrFactory.setServiceClass(HelloWorld.class); @@ -244,8 +158,7 @@ svrFactory.setServiceBean(implementor); svrFactory.getInInterceptors().add(new LoggingInInterceptor()); svrFactory.getOutInterceptors().add(new LoggingOutInterceptor()); svrFactory.create(); -</pre> -</div></div> +</plain-text-body> <p>You could leave out the ServiceClass. But it is better to use it so the server and the client are created from the same interface. If you instead only use the implementation class subtle problems may occur.</p> @@ -258,8 +171,7 @@ svrFactory.create(); <p>For the client there is also the alternative approach that gives you more flexibility. Of course like above the logging interceptors are optional but they help a lot when starting:</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;"> +<plain-text-body> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); @@ -270,8 +182,7 @@ HelloWorld client = (HelloWorld) factory String reply = client.sayHi("HI"); System.out.println("Server said: " + reply); System.exit(0); -</pre> -</div></div></div> +</plain-text-body></div> </div> <!-- Content --> </td> Modified: websites/production/cxf/content/docs/jax-rs-basics.html ============================================================================== --- websites/production/cxf/content/docs/jax-rs-basics.html (original) +++ websites/production/cxf/content/docs/jax-rs-basics.html Tue Aug 29 11:11:59 2017 @@ -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/shBrushJava.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(); @@ -117,16 +117,20 @@ Apache CXF -- JAX-RS Basics <td height="100%"> <!-- Content --> <div class="wiki-content"> -<div id="ConfluenceContent"><p><span style="font-size:2em;font-weight:bold">JAX-RS : Understanding the Basics</span> +<div id="ConfluenceContent"><p> </p><p> <span style="font-size:2em;font-weight:bold">JAX-RS : Understanding the Basics</span>  </p><p> </p><p><style type="text/css">/*<![CDATA[*/ -div.rbtoc1498643224259 {padding: 0px;} -div.rbtoc1498643224259 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1498643224259 li {margin-left: 0px;padding-left: 0px;} - -/*]]>*/</style></p><div class="toc-macro rbtoc1498643224259"> -<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-WhatisNewinJAX-RS2.0">What is New in JAX-RS 2.0</a> +div.rbtoc1504004875071 {padding: 0px;} +div.rbtoc1504004875071 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1504004875071 li {margin-left: 0px;padding-left: 0px;} + +/*]]>*/</style></p><div class="toc-macro rbtoc1504004875071"> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-WhatisNewinJAX-RS2.1">What is New in JAX-RS 2.1</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-ReactiveClientAPI">Reactive Client API</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-CompletionStage">CompletionStage</a></li><li><a shape="rect" href="#JAX-RSBasics-RxJavaObservable">RxJava Observable</a></li></ul> +</li><li><a shape="rect" href="#JAX-RSBasics-CompletableFutureasamethodreturnvalue">CompletableFuture as a method return value</a></li><li><a shape="rect" href="#JAX-RSBasics-ServerSentEvents">Server Sent Events</a></li><li><a shape="rect" href="#JAX-RSBasics-SubResourcesasClasses">SubResources as Classes</a></li><li><a shape="rect" href="#JAX-RSBasics-CXFNIOExtension">CXF NIO Extension</a></li></ul> +</li><li><a shape="rect" href="#JAX-RSBasics-WhatisNewinJAX-RS2.0">What is New in JAX-RS 2.0</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-Filters">Filters</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-Server">Server</a></li><li><a shape="rect" href="#JAX-RSBasics-Client">Client</a></li></ul> </li><li><a shape="rect" href="#JAX-RSBasics-Interceptors">Interceptors</a></li><li><a shape="rect" href="#JAX-RSBasics-DynamicFeatures">Dynamic Features</a></li><li><a shape="rect" href="#JAX-RSBasics-Exceptions">Exceptions</a></li><li><a shape="rect" href="#JAX-RSBasics-Suspendedinvocations">Suspended invocations</a></li><li><a shape="rect" href="#JAX-RSBasics-Parameterconverters">Parameter converters</a></li><li><a shape="rect" href="#JAX-RSBasics-Beanparameters">Bean parameters</a></li><li><a shape="rect" href="#JAX-RSBasics-ResourceInfo">ResourceInfo</a></li><li><a shape="rect" href="#JAX-RSBasics-Injectionintosubresources">Injection into subresources</a></li><li><a shape="rect" href="#JAX-RSBasics-Updatestothematchingalgorithm">Updates to the matching algorithm</a></li><li><a shape="rect" href="#JAX-RSBasics-Link">Link</a></li><li><a shape="rect" href="#JAX-RSBasics-ClientAPI">Client API</a></li></ul> @@ -147,7 +151,7 @@ div.rbtoc1498643224259 li {margin-left: </li><li><a shape="rect" href="#JAX-RSBasics-MessageBodyProviders">Message Body Providers</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSBasics-CustomMessageBodyProviders">Custom Message Body Providers</a></li><li><a shape="rect" href="#JAX-RSBasics-Registeringcustomproviders">Registering custom providers</a></li></ul> </li><li><a shape="rect" href="#JAX-RSBasics-Customizingmediatypesformessagebodyproviders">Customizing media types for message body providers</a></li><li><a shape="rect" href="#JAX-RSBasics-AdvancedHTTP">Advanced HTTP</a></li></ul> -</div><h1 id="JAX-RSBasics-WhatisNewinJAX-RS2.0">What is New in JAX-RS 2.0</h1><h2 id="JAX-RSBasics-Filters">Filters</h2><h3 id="JAX-RSBasics-Server">Server</h3><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerRequestFilter.html" rel="nofollow">ContainerRequestFilter</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerResponseFilter.html" rel="nofollow">ContainerResponseFilter</a> are new server-side request and response filters which can be used to customize various properties of a given request and response.</p><p>ContainerRequestFilter annotated with a <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/PreMatching.html" rel="nofollow">PreMatching</a> annotation will be run before the runtime has matched a request to a specific JAX-RS root resource and method. Prematching filters can be used to aff ect the matching process.</p><p>The request filters without the PreMatching annotation will run after the JAX-RS resource method has been selected.</p><p>ContainerRequestFilter can be used to <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerRequestContext.html#abortWith(javax.ws.rs.core.Response)" rel="nofollow">block</a> a request.</p><p>The filters can be bound to individual resource methods only with the help of custom <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/NameBinding.html" rel="nofollow">NameBinding</a>s.</p><p>Multiple request and response filters can be executed in the specific order by using javax.annotation.Priority annotations. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nofollow">Priorities</a> for more information. Request filters are sorted in the ascending order, response filters - in the descending order.</p><h3 id="JAX-RSBasics-Client">Client</h3><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientRequestFilter.html" rel="nofollow">ClientRequestFilter</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientResponseFilter.html" rel="nofollow">ClientResponseFilter</a> are new client-side request and response filters which can be used to customize various properties of a given request and response.</p><p>ClientRequestFilter can be used to <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientRequestContext.html#abortWith(javax.ws.rs.core.Response)" rel="nofollow">block</a> a request.</p><p>Request filters are sorted in the ascending order, response filters - in the descending order. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nofollow">Priorities</a> for more information.</p><h2 id="JAX-RSBasics-Interceptors">Interceptors</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/ReaderInterceptor.html" rel="nofollow">ReaderInterceptor</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/WriterInterceptor.html" rel="nofollow">WriterInterceptor</a> can be used in addition to filters or on its own to customize requests and responses on server and client sides.</p><p>Interceptors can be useful to customize the reading/writing process and block JAX-RS MessageBodyWriter or MessageBodyReader providers.</p><p>The interceptors used on the server side can be bound to individual resource methods only with the help of custom <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/NameBinding.html" rel="nofollow">NameBinding</a>s.</p><p>All interceptors are sorted in the ascendin g order. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nofollow">Priorities</a> for more information.</p><h2 id="JAX-RSBasics-DynamicFeatures">Dynamic Features</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/DynamicFeature.html" rel="nofollow">Dynamic Feature</a> is a server side feature that can be used to attach request and response filters as well as reader and writer interceptors to specific resource methods. It is an alternative approach to using the NameBindings and offer a finer-grained control over the binding process.</p><h2 id="JAX-RSBasics-Exceptions">Exceptions</h2><p>Dedicated exception classes representing various HTTP error or redirect conditions have been introduced, see the 'javax.ws.rs' Package <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/package-frame.html" rel="nofollow">Exceptions s ection</a>.</p><p>For example, instead of throwing a "new WebApplicationException(404)" one is better to do "new NotFoundException()". The finer-grained exception hierarchy allows for a finer-grained support of exception mappers. It also opens a way to check WebApplicationException and all of its subclasses when catching the HTTP exceptions on the client side.</p><p>Note that on the client side, ProcessingException can be used to catch client-related exceptions while ResponseProcessingException can be used to narrow down the client side exceptions specifically related to processing the response message.</p><h2 id="JAX-RSBasics-Suspendedinvocations">Suspended invocations</h2><p>One of the best JAX-RS 2.0 features is the support for server-side asynchronous invocations. Please see the <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/AsyncResponse.html" rel="nofollow">AsyncResponse</a> documentation which provides a very good overvi ew of this feature.</p><p>See also this <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java">test resource</a>.</p><p>Typically, the resource method accepting AsyncResponse will either store it and start a new thread to finish the request, the method will return and the invocation will be suspended, then eventually another thread (either the one which initiated an internal job or some other thread) will resume the suspended call. Note in this case the invocation will be suspended indefinitely until it is resumed.</p><p>Another approach is to have AsyncResponse suspended for a limited period of time only and also register a <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/TimeoutHandler.html" rel="nofollow">TimeoutHandler</a>. The latter will be invoked when the invocation is resumed by the container after the tim eout has expired and the handler will either complete the invocation or suspend it again till it is ready to finish it.</p><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/CompletionCallback.html" rel="nofollow">CompletionCallback</a> can be registered with AsyncResponse to receive the notifications when the async response has been sent back.</p><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ConnectionCallback.html" rel="nofollow">ConnectionCallback</a> is supported starting from CXF 3.0.0-milestone2.</p><p>This feature can help developers write very sophisticated asynchronous applications.</p><p>Please also see the page about CXF <a shape="rect" href="continuations.html">Continuations</a> API which JAX-RS 2.0 AsyncResponse implementation is based upon and <br clear="none"> <a shape="rect" href="http://cxf.apache.org/docs/servlet-transport.html">how to configure</a> CX FServlet.</p><h2 id="JAX-RSBasics-Parameterconverters">Parameter converters</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/ParamConverterProvider.html" rel="nofollow">ParamConverterProvider</a> can be used to manage the conversion of custom Objects to String and vice versa on the server and client sides, when processing JAX-RS parameters representing URI parts or headers or form elements and when a default conversion mechanism does not work. For example, java.util.Date constructor accepting a String may have to be replaced a custom ParamConverter.</p><h2 id="JAX-RSBasics-Beanparameters">Bean parameters</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/BeanParam.html" rel="nofollow">BeanParam</a> can be used to get JAX-RS parameters representing URI parts or headers or form elements and also contexts injected into a single bean container.</p><p>Note the CXF extension supporting the injection of all the parameters of specific JAX-RS type (example, QueryParam("") MyBean) is different, it only allows to get all the query parameters injected, but it also does not require that bean properties are annotated with QueryParam/etc annotations.</p><h2 id="JAX-RSBasics-ResourceInfo">ResourceInfo</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ResourceInfo.html" rel="nofollow">ResourceInfo</a> is a new JAX-RS context which can be injected into filters and interceptors and checked which resource class and method are about to be invoked.</p><h2 id="JAX-RSBasics-Injectionintosubresources">Injection into subresources</h2><p>Subresources can get JAX-RS contexts injected directly into their fields with the help of <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ResourceContext.html" rel="nofollow">ResourceContext</a>.</p><p>When possible, having a parent resou rce injecting the contexts into a given subresource instance via a setter or constructor can offer a much simpler alternative.</p><h2 id="JAX-RSBasics-Updatestothematchingalgorithm">Updates to the matching algorithm</h2><p>JAX-RS 2.0 supports a proper resource method selection in cases where multiple root resource classes have the same Path value, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div><h1 id="JAX-RSBasics-WhatisNewinJAX-RS2.1">What is New in JAX-RS 2.1</h1><h2 id="JAX-RSBasics-ReactiveClientAPI">Reactive Client API</h2><p>JAX-RS 2.1 introduces <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/client/RxInvoker.java" rel="nofollow">RxInvoker</a> which can help with removing <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/client/InvocationCallback.java" rel="nofollow">InvocationCallback</a>s from the asynchronous client code. </p><h3 id="JAX-RSBasics-CompletionStage">CompletionStage</h3><p>Default <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/client/CompletionStageRxInvoker.java" rel="nofollow">CompletionStageRxInvoker</a> can be accessed via <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/ src/main/java/javax/ws/rs/client/RxInvoker.java" rel="nofollow">Invocation.rx()</a>.</p><h3 id="JAX-RSBasics-RxJavaObservable">RxJava Observable</h3><p>Custom <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/client/RxInvokerProvider.java" rel="nofollow">RxInvokerProvider</a> can be registered with the Client as a provider. CXF ships one such provider, org.apache.cxf.jaxrs.rx.client.ObservableRxInvokerProvider.</p><p>Registering it with the Client allows for working with RxJava Observable by doing <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/client/Invocation.java#L312" rel="nofollow">Invocation.rx(Class<T> clazz)</a>, more specifically,</p><p>Invocation.rx(org.apache.cxf.jaxrs.rx.client.ObservableRxInvoker.class).</p><p>Please see <a shape="rect" href="jax-rs-rxjava.html">JAX-RS RxJava</a> for more information.</p><h2 i d="JAX-RSBasics-CompletableFutureasamethodreturnvalue">CompletableFuture as a method return value</h2><p>In JAX-RS 2.1 one can return CompletableFuture (or CompletionStage) from a resource method without having to deal directly with JAX-RS AsyncResponse API. </p><p>Please see <a shape="rect" href="jax-rs-rxjava.html">JAX-RS RxJava</a> for more information about returning RxJava Observable.</p><h2 id="JAX-RSBasics-ServerSentEvents">Server Sent Events</h2><p>JAX-RS 2.1 provides a <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/tree/master/examples/src/main/java/jaxrs/examples/sse" rel="nofollow">comprehensive support</a> for <a shape="rect" class="external-link" href="https://en.wikipedia.org/wiki/Server-sent_events" rel="nofollow">SSE</a>.</p><p>org.apache.cxf/cxf-rt-rs-sse/3.2.0 dependency will need to be added. CXF SSE implementation current depends on Atmosphere.</p><h2 id="JAX-RSBasics-SubResourcesasClasses">SubResources as Classes</h2><p>Somet imes subresource may need to have the request context information available to them. One valid and simple approach is to pass these contexts to them from the parent class which instantiates a subresource - but sometimes this approach does not work.</p><p>In JAX-RS 2.0 one can use <a shape="rect" class="external-link" href="https://github.com/jax-rs/api/blob/master/jaxrs-api/src/main/java/javax/ws/rs/container/ResourceContext.java" rel="nofollow">ResourceContext</a> to instantiate a subresource instance with the runtime taking care of injecting the contexts if needed. JAX-RS 2.1 introduces a shortcut where returning a subresource class from a subresource locator method, with the runtime istantiating the class and injecting the contexts if needed</p><h2 id="JAX-RSBasics-CXFNIOExtension">CXF NIO Extension</h2><p>Please see <a shape="rect" href="jax-rs-nio.html">JAX-RS NIO</a> for more information about this CXF 3.2.0 extension which is based on the early JAX-RS 2.1 API prototype.</p><h 1 id="JAX-RSBasics-WhatisNewinJAX-RS2.0">What is New in JAX-RS 2.0</h1><h2 id="JAX-RSBasics-Filters">Filters</h2><h3 id="JAX-RSBasics-Server">Server</h3><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerRequestFilter.html" rel="nofollow">ContainerRequestFilter</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerResponseFilter.html" rel="nofollow">ContainerResponseFilter</a> are new server-side request and response filters which can be used to customize various properties of a given request and response.</p><p>ContainerRequestFilter annotated with a <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/PreMatching.html" rel="nofollow">PreMatching</a> annotation will be run before the runtime has matched a request to a specific JAX-RS root resource and method. Prematching filters can be used to affect the matching process.</p><p>The request filters without the PreMatching annotation will run after the JAX-RS resource method has been selected.</p><p>ContainerRequestFilter can be used to <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ContainerRequestContext.html#abortWith(javax.ws.rs.core.Response)" rel="nofollow">block</a> a request.</p><p>The filters can be bound to individual resource methods only with the help of custom <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/NameBinding.html" rel="nofollow">NameBinding</a>s.</p><p>Multiple request and response filters can be executed in the specific order by using javax.annotation.Priority annotations. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nofollow">Priorities</a> for more information. Request filters are sorted in the ascending order, response filters - in the descending order.</p><h3 id="JAX-RSBasics-Client">Client</h3><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientRequestFilter.html" rel="nofollow">ClientRequestFilter</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientResponseFilter.html" rel="nofollow">ClientResponseFilter</a> are new client-side request and response filters which can be used to customize various properties of a given request and response.</p><p>ClientRequestFilter can be used to <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/client/ClientRequestContext.html#abortWith(javax.ws.rs.core.Response)" rel="nofollow">block</a> a request.</p><p>Request filters are sorted in the ascending order, response filters - in the descending order. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nof ollow">Priorities</a> for more information.</p><h2 id="JAX-RSBasics-Interceptors">Interceptors</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/ReaderInterceptor.html" rel="nofollow">ReaderInterceptor</a> and <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/WriterInterceptor.html" rel="nofollow">WriterInterceptor</a> can be used in addition to filters or on its own to customize requests and responses on server and client sides.</p><p>Interceptors can be useful to customize the reading/writing process and block JAX-RS MessageBodyWriter or MessageBodyReader providers.</p><p>The interceptors used on the server side can be bound to individual resource methods only with the help of custom <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/NameBinding.html" rel="nofollow">NameBinding</a>s.</p><p>All interceptors are sorted in the ascending order. See <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/Priorities.html" rel="nofollow">Priorities</a> for more information.</p><h2 id="JAX-RSBasics-DynamicFeatures">Dynamic Features</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/DynamicFeature.html" rel="nofollow">Dynamic Feature</a> is a server side feature that can be used to attach request and response filters as well as reader and writer interceptors to specific resource methods. It is an alternative approach to using the NameBindings and offer a finer-grained control over the binding process.</p><h2 id="JAX-RSBasics-Exceptions">Exceptions</h2><p>Dedicated exception classes representing various HTTP error or redirect conditions have been introduced, see the 'javax.ws.rs' Package <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/package-frame.html" rel="nofollow">Exceptions section</ a>.</p><p>For example, instead of throwing a "new WebApplicationException(404)" one is better to do "new NotFoundException()". The finer-grained exception hierarchy allows for a finer-grained support of exception mappers. It also opens a way to check WebApplicationException and all of its subclasses when catching the HTTP exceptions on the client side.</p><p>Note that on the client side, ProcessingException can be used to catch client-related exceptions while ResponseProcessingException can be used to narrow down the client side exceptions specifically related to processing the response message.</p><h2 id="JAX-RSBasics-Suspendedinvocations">Suspended invocations</h2><p>One of the best JAX-RS 2.0 features is the support for server-side asynchronous invocations. Please see the <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/AsyncResponse.html" rel="nofollow">AsyncResponse</a> documentation which provides a very good overview of th is feature.</p><p>See also this <a shape="rect" class="external-link" href="https://github.com/apache/cxf/blob/master/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java" rel="nofollow">test resource</a>.</p><p>Typically, the resource method accepting AsyncResponse will either store it and start a new thread to finish the request, the method will return and the invocation will be suspended, then eventually another thread (either the one which initiated an internal job or some other thread) will resume the suspended call. Note in this case the invocation will be suspended indefinitely until it is resumed.</p><p>Another approach is to have AsyncResponse suspended for a limited period of time only and also register a <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/TimeoutHandler.html" rel="nofollow">TimeoutHandler</a>. The latter will be invoked when the invocation is resumed by the container after the timeout has expired and the handler will either complete the invocation or suspend it again till it is ready to finish it.</p><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/CompletionCallback.html" rel="nofollow">CompletionCallback</a> can be registered with AsyncResponse to receive the notifications when the async response has been sent back.</p><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ConnectionCallback.html" rel="nofollow">ConnectionCallback</a> is supported starting from CXF 3.0.0-milestone2.</p><p>This feature can help developers write very sophisticated asynchronous applications.</p><p>Please also see the page about CXF <a shape="rect" href="continuations.html">Continuations</a> API which JAX-RS 2.0 AsyncResponse implementation is based upon and <br clear="none"> <a shape="rect" href="http://cxf.apache.org/docs/servlet-transport.html">how to configure </a> CXFServlet.</p><h2 id="JAX-RSBasics-Parameterconverters">Parameter converters</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/ext/ParamConverterProvider.html" rel="nofollow">ParamConverterProvider</a> can be used to manage the conversion of custom Objects to String and vice versa on the server and client sides, when processing JAX-RS parameters representing URI parts or headers or form elements and when a default conversion mechanism does not work. For example, java.util.Date constructor accepting a String may have to be replaced a custom ParamConverter.</p><h2 id="JAX-RSBasics-Beanparameters">Bean parameters</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/BeanParam.html" rel="nofollow">BeanParam</a> can be used to get JAX-RS parameters representing URI parts or headers or form elements and also contexts injected into a single bean container.</p><p>Note the CXF extension supp orting the injection of all the parameters of specific JAX-RS type (example, QueryParam("") MyBean) is different, it only allows to get all the query parameters injected, but it also does not require that bean properties are annotated with QueryParam/etc annotations.</p><h2 id="JAX-RSBasics-ResourceInfo">ResourceInfo</h2><p><a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ResourceInfo.html" rel="nofollow">ResourceInfo</a> is a new JAX-RS context which can be injected into filters and interceptors and checked which resource class and method are about to be invoked.</p><h2 id="JAX-RSBasics-Injectionintosubresources">Injection into subresources</h2><p>Subresources can get JAX-RS contexts injected directly into their fields with the help of <a shape="rect" class="external-link" href="https://jax-rs.github.io/apidocs/2.0/javax/ws/rs/container/ResourceContext.html" rel="nofollow">ResourceContext</a>.</p><p>When possible, having a paren t resource injecting the contexts into a given subresource instance via a setter or constructor can offer a much simpler alternative.</p><h2 id="JAX-RSBasics-Updatestothematchingalgorithm">Updates to the matching algorithm</h2><p>JAX-RS 2.0 supports a proper resource method selection in cases where multiple root resource classes have the same Path value, 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" style="font-size:12px;">@Path("/") public class Root1 { @Path("/1") Added: websites/production/cxf/content/docs/jax-rs-nio.html ============================================================================== --- websites/production/cxf/content/docs/jax-rs-nio.html (added) +++ websites/production/cxf/content/docs/jax-rs-nio.html Tue Aug 29 11:11:59 2017 @@ -0,0 +1,253 @@ + +<!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 - JAX-RS NIO"> + + +<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/shBrushJava.js'></script> +<script> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); +</script> + + + <title> +Apache CXF -- JAX-RS NIO + </title> + </head> +<body onload="init()"> + + +<table width="100%" cellpadding="0" cellspacing="0"> + <tr> + <td id="cell-0-0" colspan="2"> </td> + <td id="cell-0-1"> </td> + <td id="cell-0-2" colspan="2"> </td> + </tr> + <tr> + <td id="cell-1-0"> </td> + <td id="cell-1-1"> </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> > <a href="restful-services.html">RESTful Services</a> > <a href="jax-rs.html">JAX-RS</a> > <a href="jax-rs-nio.html">JAX-RS NIO</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"> </td> + <td id="cell-1-4"> </td> + </tr> + <tr> + <td id="cell-2-0" colspan="2"> </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&lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.0.x/">API 3.0.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul></div> + <!-- NavigationBar --> + </div> + </div> + </div> + </div> + </td> + <td height="100%"> + <!-- Content --> + <div class="wiki-content"> +<div id="ConfluenceContent"><p> </p><p><style type="text/css">/*<![CDATA[*/ +div.rbtoc1504004879982 {padding: 0px;} +div.rbtoc1504004879982 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1504004879982 li {margin-left: 0px;padding-left: 0px;} + +/*]]>*/</style></p><div class="toc-macro rbtoc1504004879982"> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSNIO-NIOExtension">NIO Extension</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSNIO-Introduction">Introduction</a></li><li><a shape="rect" href="#JAX-RSNIO-NIORead">NIO Read</a></li><li><a shape="rect" href="#JAX-RSNIO-NIOWrite">NIO Write</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSNIO-EvenEasierNIOWrite">Even Easier NIO Write</a></li></ul> +</li></ul> +</li></ul> +</div><h1 id="JAX-RSNIO-NIOExtension">NIO Extension</h1><h2 id="JAX-RSNIO-Introduction">Introduction</h2><p>Servlet 3.1 API introduces a support for Non-Blocking IO, see <a shape="rect" class="external-link" href="http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HTML5andServlet31/HTML5andServlet%203.1.html" rel="nofollow">this tutorial</a> for more information.</p><p>The idea is that when the service code reads or writes the stream it does not block at all and only does a read or write action when a servlet container is ready to handle it effectively.</p><p>Early JAX-RS 2.1 API had a server-side prototype to help the JAX-RS service code utilize this Servlet 3.1 NIO features in a JAX-RS friendly way. Unfortunately that prototype was dropped from the final 2.1 API with the future major JAX-RS version expected to provide a much more complete and sophisticated NIO API.</p><p>CXF 3.2.0 has retained the implementation of the original JAX-RS 2.1 NIO API prototype and made it possible for the users to experiment with it.</p><h2 id="JAX-RSNIO-NIORead">NIO Read</h2><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;">@POST +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public void uploadBookStream(@Suspended AsyncResponse response) { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + final byte[] buffer = new byte[4096]; + final LongAdder adder = new LongAdder(); + + new NioReadEntity( + // read handler + in -> { + final int n = in.read(buffer); + if (n > 0) { + adder.add(n); + out.write(buffer, 0, n); + } + }, + // completion handler + () -> { + closeOutputStream(out); + response.resume("Book Store uploaded: " + adder.longValue() + " bytes"); + } + // by default the runtime will resume AsyncResponse with Throwable itself + // if the error handler is not provided + + //, + // error handler + //t -> { + // response.resume(t); + //} + ); +}</pre> +</div></div><h2 id="JAX-RSNIO-NIOWrite">NIO Write</h2><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;">@GET +@Produces(MediaType.TEXT_PLAIN) + public Response getBookStream() throws IOException { + final ByteArrayInputStream in = new ByteArrayInputStream( + IOUtils.readBytesFromStream(getClass().getResourceAsStream("/files/books.txt"))); + + final byte[] buffer = new byte[4096]; + + return Response.ok().entity( + + new NioWriteEntity( + + out -> { + + final int n = in.read(buffer); + if (n >= 0) { +   out.write(buffer, 0, n); + return true; + } + closeInputStream(in); + return false; + } + // by default the runtime will throw the exception itself + // if the error handler is not provided + //, + //throwable -> { + // throw throwable; + //} + )) + .build(); + } + +</pre> +</div></div><h3 id="JAX-RSNIO-EvenEasierNIOWrite">Even Easier NIO Write</h3><p> </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;">import org.apache.cxf.annotations.UseNio; +@GET +@Produces(MediaType.TEXT_PLAIN) +@Path("/is") +@UseNio +public InputStream getBookStreamFromInputStream() throws IOException { + return getClass().getResourceAsStream("/files/books.txt"); +}</pre> +</div></div><p> </p><p> </p></div> + </div> + <!-- Content --> + </td> + </tr> + </table> + </td> + <td id="cell-2-2" colspan="2"> </td> + </tr> + <tr> + <td id="cell-3-0"> </td> + <td id="cell-3-1"> </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=73634834">edit page</a>) + (<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=73634834&showComments=true&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"> </td> + <td id="cell-3-4"> </td> + </tr> + <tr> + <td id="cell-4-0" colspan="2"> </td> + <td id="cell-4-1"> </td> + <td id="cell-4-2" colspan="2"> </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> + Added: websites/production/cxf/content/docs/jax-rs-rxjava.html ============================================================================== --- websites/production/cxf/content/docs/jax-rs-rxjava.html (added) +++ websites/production/cxf/content/docs/jax-rs-rxjava.html Tue Aug 29 11:11:59 2017 @@ -0,0 +1,248 @@ + +<!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 - JAX-RS RxJava"> + + +<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/shBrushJava.js'></script> +<script> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); +</script> + + + <title> +Apache CXF -- JAX-RS RxJava + </title> + </head> +<body onload="init()"> + + +<table width="100%" cellpadding="0" cellspacing="0"> + <tr> + <td id="cell-0-0" colspan="2"> </td> + <td id="cell-0-1"> </td> + <td id="cell-0-2" colspan="2"> </td> + </tr> + <tr> + <td id="cell-1-0"> </td> + <td id="cell-1-1"> </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> > <a href="restful-services.html">RESTful Services</a> > <a href="jax-rs.html">JAX-RS</a> > <a href="jax-rs-rxjava.html">JAX-RS RxJava</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"> </td> + <td id="cell-1-4"> </td> + </tr> + <tr> + <td id="cell-2-0" colspan="2"> </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&lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.0.x/">API 3.0.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul></div> + <!-- NavigationBar --> + </div> + </div> + </div> + </div> + </td> + <td height="100%"> + <!-- Content --> + <div class="wiki-content"> +<div id="ConfluenceContent"><p><style type="text/css">/*<![CDATA[*/ +div.rbtoc1504004879079 {padding: 0px;} +div.rbtoc1504004879079 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1504004879079 li {margin-left: 0px;padding-left: 0px;} + +/*]]>*/</style></p><div class="toc-macro rbtoc1504004879079"> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSRxJava-RxJavarx.Observablesupport">RxJava rx.Observable support</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSRxJava-Introduction">Introduction</a></li><li><a shape="rect" href="#JAX-RSRxJava-Client">Client</a></li><li><a shape="rect" href="#JAX-RSRxJava-Server">Server</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSRxJava-Asamethodreturnvalue">As a method return value</a></li><li><a shape="rect" href="#JAX-RSRxJava-CombiningwithAsyncResponse">Combining with AsyncResponse</a></li></ul> +</li></ul> +</li></ul> +</div><h1 id="JAX-RSRxJava-RxJavarx.Observablesupport">RxJava rx.Observable support</h1><h2 id="JAX-RSRxJava-Introduction">Introduction</h2><p>RxJava 1 rx.Observable is supported on the client and the server side starting from CXF 3.2.0.</p><p>org.apache.cxf/cxf-rt-rs-extension-rx/3.2.0 dependency is required.</p><h2 id="JAX-RSRxJava-Client">Client</h2><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;">import org.apache.cxf.jaxrs.rx.client.ObservableRxInvoker; +import org.apache.cxf.jaxrs.rx.client.ObservableRxInvokerProvider; +  +@Test + public void testObservableWithWebClient() throws Exception { + String address = "http://localhost:" + PORT + "/observable/textAsync"; + WebClient wc = WebClient.create(address, + Collections.singletonList(new ObservableRxInvokerProvider())); + Observable<String> obs = wc.accept("text/plain") + .rx(ObservableRxInvoker.class) + .get(String.class); + obs.map(s -> { + return s + s; + }); + + Thread.sleep(3000); + + obs.subscribe(s -> assertDuplicateResponse(s)); + } + @Test + public void testObservableJaxrs21With404Response() throws Exception { + String address = "http://localhost:" + PORT + "/observable/textAsync404"; + Invocation.Builder b = ClientBuilder.newClient().register(new ObservableRxInvokerProvider()) + .target(address).request(); + b.rx(ObservableRxInvoker.class).get(String.class).subscribe( + s -> { + fail("Exception expected"); + }, + t -> validateT((ExecutionException)t)); + } + + private void validateT(ExecutionException t) { + assertTrue(t.getCause() instanceof NotFoundException); + } + private void assertDuplicateResponse(String s) { + assertEquals("Hello, world!Hello, world!", s); + }</pre> +</div></div><p> </p><h2 id="JAX-RSRxJava-Server">Server</h2><h3 id="JAX-RSRxJava-Asamethodreturnvalue">As a method return value</h3><p>One simply returns an Observable from the method and the runtime will make sure the response is finalized once the Observable flow is complete.</p><p>The only requirement is that one has to register a custom JAX-RS invoker, org.apache.cxf.jaxrs.rx.server.ObservableInvoker. It does all the default JAXRSInvoker does and only checks if Observable is returned - if yes then it links it internally with the JAX-RS AsyncResponse.</p><h3 id="JAX-RSRxJava-CombiningwithAsyncResponse">Combining with AsyncResponse</h3><p> </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;">import org.apache.cxf.jaxrs.rx.server.ListAsyncSubscriber; +import org.apache.cxf.jaxrs.rx.server.JsonStreamingAsyncSubscriber; + +@GET + @Produces("application/json") + @Path("textJsonImplicitListAsync") + public void getJsonImplicitListAsync(@Suspended AsyncResponse ar) { + final HelloWorldBean bean1 = new HelloWorldBean(); + final HelloWorldBean bean2 = new HelloWorldBean("Ciao"); + new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(2000); + } catch (InterruptedException ex) { + // ignore + } + Observable.just(bean1, bean2).subscribe(new ListAsyncSubscriber<HelloWorldBean>(ar)); + } + }).start(); + + } + + // return a JSON array, write to the output stream as soon as the next JSON object becomes available + @GET + @Produces("application/json") + @Path("textJsonImplicitListAsyncStream") + public void getJsonImplicitListStreamingAsync(@Suspended AsyncResponse ar) { + Observable.just("Hello", "Ciao") + .map(s -> new HelloWorldBean(s)) + .subscribeOn(Schedulers.computation()) + .subscribe(new JsonStreamingAsyncSubscriber<HelloWorldBean>(ar)); + }</pre> +</div></div></div> + </div> + <!-- Content --> + </td> + </tr> + </table> + </td> + <td id="cell-2-2" colspan="2"> </td> + </tr> + <tr> + <td id="cell-3-0"> </td> + <td id="cell-3-1"> </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=73634837">edit page</a>) + (<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=73634837&showComments=true&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"> </td> + <td id="cell-3-4"> </td> + </tr> + <tr> + <td id="cell-4-0" colspan="2"> </td> + <td id="cell-4-1"> </td> + <td id="cell-4-2" colspan="2"> </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> +