Author: buildbot Date: Mon Feb 16 12:47:12 2015 New Revision: 940345 Log: Production update by buildbot for cxf
Modified: websites/production/cxf/content/cache/docs.pageCache websites/production/cxf/content/docs/jax-rs-multiparts.html websites/production/cxf/content/docs/jaxrs-services-description.html Modified: websites/production/cxf/content/cache/docs.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/cxf/content/docs/jax-rs-multiparts.html ============================================================================== --- websites/production/cxf/content/docs/jax-rs-multiparts.html (original) +++ websites/production/cxf/content/docs/jax-rs-multiparts.html Mon Feb 16 12:47:12 2015 @@ -117,30 +117,19 @@ Apache CXF -- JAX-RS Multiparts <td height="100%"> <!-- Content --> <div class="wiki-content"> -<div id="ConfluenceContent"><p></p><p></p><p></p><p></p><p><span class="inline-first-p" style="font-size:2em;font-weight:bold"> JAX-RS : Support for Multiparts </span></p><p></p><p></p><p></p><p></p><p></p> +<div id="ConfluenceContent"><p> </p><p> </p><p> </p><p> </p><p> <span class="inline-first-p" style="font-size:2em;font-weight:bold">JAX-RS : Support for Multiparts</span> </p><p> </p><p> </p><p> </p><p> </p><p><style type="text/css">/*<![CDATA[*/ +div.rbtoc1424090804782 {padding: 0px;} +div.rbtoc1424090804782 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1424090804782 li {margin-left: 0px;padding-left: 0px;} -<style type="text/css">/*<![CDATA[*/ -div.rbtoc1419015802186 {padding: 0px;} -div.rbtoc1419015802186 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1419015802186 li {margin-left: 0px;padding-left: 0px;} - -/*]]>*/</style><div class="toc-macro rbtoc1419015802186"> +/*]]>*/</style></p><div class="toc-macro rbtoc1424090804782"> <ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSMultiparts-Readingattachments">Reading attachments</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSMultiparts-MultipartannotationandOptionalattachments">Multipart annotation and Optional attachments</a></li></ul> -</li><li><a shape="rect" href="#JAX-RSMultiparts-Writingattachments">Writing attachments</a></li><li><a shape="rect" href="#JAX-RSMultiparts-Uploadingfiles">Uploading files</a></li><li><a shape="rect" href="#JAX-RSMultiparts-Readinglargeattachments">Reading large attachments</a> -<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSMultiparts-Formsandmultiparts">Forms and multiparts</a></li></ul> +</li><li><a shape="rect" href="#JAX-RSMultiparts-Writingattachments">Writing attachments</a></li><li><a shape="rect" href="#JAX-RSMultiparts-UploadingfileswithClientAPI">Uploading files with Client API</a></li><li><a shape="rect" href="#JAX-RSMultiparts-Readinglargeattachments">Reading large attachments</a> +<ul class="toc-indentation"><li><a shape="rect" href="#JAX-RSMultiparts-Formsandmultiparts">Forms and multiparts</a></li><li><a shape="rect" href="#JAX-RSMultiparts-Content-DispositionUTF-8filenames">Content-Disposition UTF-8 file names</a></li></ul> </li><li><a shape="rect" href="#JAX-RSMultiparts-XOPsupport">XOP support</a></li><li><a shape="rect" href="#JAX-RSMultiparts-NoteaboutStruts">Note about Struts</a></li></ul> -</div> - -<h1 id="JAX-RSMultiparts-Readingattachments">Reading attachments</h1> - -<p>Individual parts can be mapped to StreamSource, InputStream, DataSource or custom Java types for which message body readers are available.</p> - -<p>For example:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div><h1 id="JAX-RSMultiparts-Readingattachments">Reading attachments</h1><p>Individual parts can be mapped to StreamSource, InputStream, DataSource or custom Java types for which message body readers are available.</p><p>For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/jaxbjson") @Produces("text/xml") public Response addBookJaxbJson( @@ -149,39 +138,20 @@ public Response addBookJaxbJson( throws Exception { } ]]></script> -</div></div> - -<p>Note that in this example it's expected that the root part named 'rootPart' is a text-xml Book representation, while a part named 'book2' is a Book JSON sequence.</p> - -<p>All attachment parts can be accessed as a list of <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java">Attachment</a> with Attachment making it easy to deal with a given part:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>Note that in this example it's expected that the root part named 'rootPart' is a text-xml Book representation, while a part named 'book2' is a Book JSON sequence.</p><p>All attachment parts can be accessed as a list of <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java">Attachment</a> with Attachment making it easy to deal with a given part:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST public void addAttachments(List<Attachment> atts) throws Exception { } ]]></script> -</div></div> - -<p>For example, Attachment class can be used to get to a <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java">Content-Disposition</a> header, when dealing with the form submission of files.</p> - -<p>Similarly, the whole request body can be represented as a <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java">MultipartBody</a>:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>For example, Attachment class can be used to get to a <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ContentDisposition.java">Content-Disposition</a> header, when dealing with the form submission of files.</p><p>Similarly, the whole request body can be represented as a <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java">MultipartBody</a>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST public void addAttachments(MultipartBody body) throws Exception { body.getAllAtachments(); body.getRootAttachment(); } ]]></script> -</div></div> - -<p>When handling complex multipart/form-data submissions (such as those containing files) MultipartBody (and Attachment) need to be used directly. In simpler cases, when every form part can be captured by a String, the following code will suffice:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>When handling complex multipart/form-data submissions (such as those containing files) MultipartBody (and Attachment) need to be used directly. In simpler cases, when every form part can be captured by a String, the following code will suffice:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Consumes("multipart/form-data") public void addForm1(@FormParam("name") String title, @FormParam("id") Long id) throws Exception { } @@ -196,13 +166,8 @@ public void addForm2(@FormParam("&q public void addForm3(MultivaluedMap<String, String> formData) throws Exception { } ]]></script> -</div></div> - -<p>When working with either List of Attachments or MultipartBody, one may want to process the individual parts with the help of some custom procedures. Starting from CXF 2.3.0 it is also possible to do the following:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>When working with either List of Attachments or MultipartBody, one may want to process the individual parts with the help of some custom procedures. Starting from CXF 2.3.0 it is also possible to do the following:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST public void addAttachments(MultipartBody body) throws Exception { Book book = body.getAttachmentObject("bookPart", Book.class); } @@ -215,55 +180,24 @@ public void addAttachments(List<Attac } ]]></script> -</div></div> - - - - -<p>When a user code has <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java">MessageContext</a> injected, <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java">AttachmentUtils</a> can also be used by the application code.</p> - -<p>Please see these <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/MultipartStore.java">test resource class</a> and <a shape="rect" class="external-link" href="http://sberyozkin.blogspot.com/2009/02/multiparts-in-cxf-jaxrs.html" rel="nofollow">blog entry</a> for more examples.</p> - -<h2 id="JAX-RSMultiparts-MultipartannotationandOptionalattachments">Multipart annotation and Optional attachments</h2> - -<p>When you write the code like this</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>When a user code has <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContext.java">MessageContext</a> injected, <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java">AttachmentUtils</a> can also be used by the application code.</p><p>Please see these <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/MultipartStore.java">test resource class</a> and <a shape="rect" class="external-link" href="http://sberyozkin.blogspot.com/2009/02/multiparts-in-cxf-jaxrs.html" rel="nofollow">blog entry</a> for more examples.</p><h2 id="JAX-RSMultiparts-MultipartannotationandOptionalattachments">Multipart annotation and Optional attachments</h2><p>When you write the code lik e this</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/jaxbjson") @Produces("text/xml") public Response addBookJaxbJson( @Multipart("rootPart") Book2 b1, @Multipart("book2") Book b2) {} ]]></script> -</div></div> - -<p>the runtime will return a 400 status if either "rootPart" or "book2" parts can not be found in the multipart payload.<br clear="none"> -Starting from 2.5.1 it is possible to request the runtime to report a null value in case of missing parts:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>the runtime will return a 400 status if either "rootPart" or "book2" parts can not be found in the multipart payload.<br clear="none"> Starting from 2.5.1 it is possible to request the runtime to report a null value in case of missing parts:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/jaxbjson") @Produces("text/xml") public Response addBookJaxbJson( @Multipart("rootPart") Book2 b1, @Multipart(value = "book2", required = false) Book b2) {} ]]></script> -</div></div> - -<p>The above code requires the "rootPart" part be available and can handle the case where the "book2" part is missing. </p> - -<h1 id="JAX-RSMultiparts-Writingattachments">Writing attachments</h1> - -<p>Starting from 2.2.4 it is also possible to write attachments to the output stream, both on the client and server sides.</p> - -<p>On the server side it is sufficient to update the @Produces value for a given method:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -public class Resource { +</div></div><p>The above code requires the "rootPart" part be available and can handle the case where the "book2" part is missing.</p><h1 id="JAX-RSMultiparts-Writingattachments">Writing attachments</h1><p>Starting from 2.2.4 it is also possible to write attachments to the output stream, both on the client and server sides.</p><p>On the server side it is sufficient to update the @Produces value for a given method:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[public class Resource { private List<Book> books; @Produces("multipart/mixed;type=text/xml") public List<Book> getBooksAsMultipart() { @@ -276,15 +210,8 @@ public class Resource { } } ]]></script> -</div></div> - -<p>Note that a 'type' parameter of the 'multipart/mixed' media type indicates that all parts in the multiparts response should have a Content-Type header set to 'text/xml' for both getBooksAsMultipart() and getBookAsMultipart() method responses. The getBooksAsMultipart() response will have 3 parts, the first part will have its Content-ID header set to "root.mess...@cxf.apache.org", the next parts will have '1' and '2' ids. The getBookAsMultipart() response will have a single part only with its Content-ID header set to "root.mess...@cxf.apache.org".</p> - -<p>When returning mixed multiparts containing objects of different types, you can either return a Map with the media type string value to Object pairs or MultipartBody: </p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -public class Resource { +</div></div><p>Note that a 'type' parameter of the 'multipart/mixed' media type indicates that all parts in the multiparts response should have a Content-Type header set to 'text/xml' for both getBooksAsMultipart() and getBookAsMultipart() method responses. The getBooksAsMultipart() response will have 3 parts, the first part will have its Content-ID header set to "root.mess...@cxf.apache.org", the next parts will have '1' and '2' ids. The getBookAsMultipart() response will have a single part only with its Content-ID header set to "root.mess...@cxf.apache.org".</p><p>When returning mixed multiparts containing objects of different types, you can either return a Map with the media type string value to Object pairs or MultipartBody:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[public class Resource { private List<Book> books; @Produces("multipart/mixed") public Map<String, Object> getBooks() { @@ -305,17 +232,8 @@ public class Resource { } ]]></script> -</div></div> - -<p>Similarly to the method returning a list in a previous code fragment, getBooks() will have the response serialized as multiparts, where the first part will have its Content-ID header set to "root.mess...@cxf.apache.org", the next parts will have ids like '1', '2', etc. </p> - -<p>In getBooks2() one can control the content ids of individual parts.</p> - -<p>You can also control the contentId and the media type of the root attachment by using a Multipart annotation:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -public class Resource { +</div></div><p>Similarly to the method returning a list in a previous code fragment, getBooks() will have the response serialized as multiparts, where the first part will have its Content-ID header set to "root.mess...@cxf.apache.org", the next parts will have ids like '1', '2', etc.</p><p>In getBooks2() one can control the content ids of individual parts.</p><p>You can also control the contentId and the media type of the root attachment by using a Multipart annotation:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[public class Resource { @Produces("multipart/form-data") @Multipart(value = "root", type = "application/octet-stream") public File testGetImageFromForm() { @@ -323,49 +241,24 @@ public class Resource { } } ]]></script> -</div></div> - -<p>One can also have lists or maps of DataHandler, DataSource, Attachment, byte arrays or InputStreams handled as multiparts. </p> - -<p>On the client side multiparts can be written the same way. For example:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ - -WebClient client = WebClient.create("http://books"); +</div></div><p>One can also have lists or maps of DataHandler, DataSource, Attachment, byte arrays or InputStreams handled as multiparts.</p><p>On the client side multiparts can be written the same way. For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[WebClient client = WebClient.create("http://books"); client.type("multipart/mixed").accept("multipart/mixed"); List<Attachment> atts = new LinkedList<Attachment>(); atts.add(new Attachment("root", "application/json", new JSONBook())); atts.add(new Attachment("image", "application/octet-stream", getImageInputStream())); List<Attachment> atts = client.postAndGetCollection(atts, Attachment.class); ]]></script> -</div></div> - -<p>Note a new WebClient.postAndGetCollection which can be used for a type-safe retrieval of collections. A similar WebClient.getCollection has also been added.</p> - -<p>When using proxies, a Multipart annotation attached to a method parameter can also be used to set the root contentId and media type. Proxies do not support at the moment multiple method parameters annotated with Multipart (as opposed to the server side) but only a single multipart parameter:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -public class Resource { +</div></div><p>Note a new WebClient.postAndGetCollection which can be used for a type-safe retrieval of collections. A similar WebClient.getCollection has also been added.</p><p>When using proxies, a Multipart annotation attached to a method parameter can also be used to set the root contentId and media type. Proxies do not support at the moment multiple method parameters annotated with Multipart (as opposed to the server side) but only a single multipart parameter:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[public class Resource { @Produces("multipart/mixed") @Consumes("multipart/form-data") @Multipart(value = "root", type = "application/octet-stream") public File postGetFile(@Multipart(value = "root2", type = "application/octet-stream") File file) {} } ]]></script> -</div></div> - -<p>A method-level Multipart annotation will affect the writing on the server side and the reading on the client side. A parameter-level Multipart annotation will affect writing on the client (proxy) side and reading on the server side. You don't have to use Multipart annotations.</p> - -<h1 id="JAX-RSMultiparts-Uploadingfiles">Uploading files</h1> - -<p>At the moment the only way to upload a file is to use a MultipartBody, Attachment or File:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ - -WebClient client = WebClient.create("http://books");t +</div></div><p>A method-level Multipart annotation will affect the writing on the server side and the reading on the client side. A parameter-level Multipart annotation will affect writing on the client (proxy) side and reading on the server side. You don't have to use Multipart annotations.</p><h1 id="JAX-RSMultiparts-UploadingfileswithClientAPI">Uploading files with Client API</h1><p>At the moment the only way to upload a file is to use a MultipartBody, Attachment or File:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[WebClient client = WebClient.create("http://books");t client.type("multipart/form-data"); ContentDisposition cd = new ContentDisposition("attachment;filename=image.jpg"); Attachment att = new Attachment("root", imageInputStream, cd); @@ -378,18 +271,8 @@ client.post(att); client.post(getClass().getResource("image.png").getFile()); ]]></script> -</div></div> - -<p>Using File provides a simpler way as the runtime can figure out how to create a ContentDisposition from a File.</p> - - -<h1 id="JAX-RSMultiparts-Readinglargeattachments">Reading large attachments</h1> - -<p>One can use the following properties to set up folder, memory threshold and max size (from CXF 2.4.4 and 2.5) values when dealing with large attachments:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ -<beans> +</div></div><p>Using File provides a simpler way as the runtime can figure out how to create a ContentDisposition from a File.</p><h1 id="JAX-RSMultiparts-Readinglargeattachments">Reading large attachments</h1><p>One can use the following properties to set up folder, memory threshold and max size (from CXF 2.4.4 and 2.5) values when dealing with large attachments:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<beans> <jaxrs:server id="bookstore1"> <jaxrs:properties> <entry key="attachment-directory" value="/temp/bookstore1"/> @@ -401,93 +284,29 @@ client.post(getClass().getResource(" </jaxrs:server> </beans> ]]></script> -</div></div> - -<p>Note that such properties can be set up on a per-endpoint basis. Alternatively you can set "attachmentDirectory", "attachmentThreshold" and "attachmentMaxSize" properties directly on either org.apache.cxf.jaxrs.provider.MultipartProvider or, when dealing with multipart/form-data payloads, org.apache.cxf.jaxrs.provider.FormEncodingProvider.</p> - -<p>Alternatively, you might want to set the following system properties which will apply to all endpoints:</p> - -<p>> -Dorg.apache.cxf.io.CachedOutputStream.Threshold=102400 <br clear="none"> -and<br clear="none"> -> -Dorg.apache.cxf.io.CachedOutputStream.OutputDirectory=/temp</p> - -<p>Starting from CXF 2.5.0 and 2.4.4:<br clear="none"> -> -Dorg.apache.cxf.io.CachedOutputStream.MaxSize=10000000</p> - -<p>Note that if a given attachment exceeds the maximum size property (default is no-limit) then HTTP 413 status will be returned. </p> - -<h2 id="JAX-RSMultiparts-Formsandmultiparts">Forms and multiparts</h2> - -<p>The <a shape="rect" class="external-link" href="http://www.w3.org/TR/html401/interact/forms.html" rel="nofollow">Forms in HTML documents</a> recommendation <a shape="rect" class="external-link" href="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2" rel="nofollow">suggests</a> that multipart/form-data requests should mainly be used to upload files.</p> - -<p>As mentioned in the previous section, one way to deal with multipart/form-data submissions is to deal directly with a CXF JAXRS Attachment class and get a Content-Disposition header and/or the underlying input stream.</p> - -<p>It is now possible (since 2.2.5) to have individual multipart/form-data parts read by registered JAX-RS MessageBodyReaders, something that is already possible to do for types like multipart/mixed or multipart/related.</p> - -<p>For example 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/resources/attachmentFormJson">request</a> can be handled by a method with the following signature:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>Note that such properties can be set up on a per-endpoint basis. Alternatively you can set "attachmentDirectory", "attachmentThreshold" and "attachmentMaxSize" properties directly on either org.apache.cxf.jaxrs.provider.MultipartProvider or, when dealing with multipart/form-data payloads, org.apache.cxf.jaxrs.provider.FormEncodingProvider.</p><p>Alternatively, you might want to set the following system properties which will apply to all endpoints:</p><p>> -Dorg.apache.cxf.io.CachedOutputStream.Threshold=102400 <br clear="none"> and<br clear="none"> > -Dorg.apache.cxf.io.CachedOutputStream.OutputDirectory=/temp</p><p>Starting from CXF 2.5.0 and 2.4.4:<br clear="none"> > -Dorg.apache.cxf.io.CachedOutputStream.MaxSize=10000000</p><p>Note that if a given attachment exceeds the maximum size property (default is no-limit) then HTTP 413 status will be returned.</p><h2 id="JAX-RSMultiparts-Formsandmultiparts">Forms and multiparts</h2><p>The <a shape="rect" class="ext ernal-link" href="http://www.w3.org/TR/html401/interact/forms.html" rel="nofollow">Forms in HTML documents</a> recommendation <a shape="rect" class="external-link" href="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2" rel="nofollow">suggests</a> that multipart/form-data requests should mainly be used to upload files.</p><p>As mentioned in the previous section, one way to deal with multipart/form-data submissions is to deal directly with a CXF JAXRS Attachment class and get a Content-Disposition header and/or the underlying input stream.</p><p>It is now possible (since 2.2.5) to have individual multipart/form-data parts read by registered JAX-RS MessageBodyReaders, something that is already possible to do for types like multipart/mixed or multipart/related.</p><p>For example 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/resources/attachmentFormJson">request</a> can be handled by a method with the following signature:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/jsonform") @Consumes("multipart/form-data") public Response addBookJsonFromForm(Book b1) {...} ]]></script> -</div></div> - -<p>Similarly, 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/resources/attachmentFormJsonJaxb">request</a> can be handled by a method with the following signature:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>Similarly, 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/resources/attachmentFormJsonJaxb">request</a> can be handled by a method with the following signature:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/jsonjaxbform") @Consumes("multipart/form-data") public Response addBookJaxbJsonForm(@Multipart("jsonPart") Book b1, @Multipart("jaxbPart") Book b2) {} ]]></script> -</div></div> - -<p>Note that once a request has more than two parts then one needs to start using @Mutipart, the values can refer to either ContentId header or to ContentDisposition/name. Note that at the moment using @Multipart is preferred to using @FormParam unless a plain name/value submission is dealt with. The reason is that @Multipart can also specify an expected media type of the individual part and thus act similarly to a @Consume annotation.</p> - -<p>When dealing with multiple parts one can avoid using @Multipart and just use List, ex, List\<Atachment\>, List\<Book\>, etc.</p> - -<p>Finally, multipart/form-data requests with multiple files (file uploads) can be supported too. For example, 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/resources/attachmentFormJsonFiles">request</a> can be handled by a method with the signature like :</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ -@POST +</div></div><p>Note that once a request has more than two parts then one needs to start using @Mutipart, the values can refer to either ContentId header or to ContentDisposition/name. Note that at the moment using @Multipart is preferred to using @FormParam unless a plain name/value submission is dealt with. The reason is that @Multipart can also specify an expected media type of the individual part and thus act similarly to a @Consume annotation.</p><p>When dealing with multiple parts one can avoid using @Multipart and just use List, ex, List\<Atachment\>, List\<Book\>, etc.</p><p>Finally, multipart/form-data requests with multiple files (file uploads) can be supported too. For example, 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/resources/attachmentFormJsonFiles">request</a> can be handled by a method with the signature like :</p><div class="code panel pdl" style="b order-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@POST @Path("/books/filesform") @Produces("text/xml") @Consumes("multipart/form-data") public Response addBookFilesForm(@Multipart("owner") String name, @Multipart("files") List<Book> books) {} ]]></script> -</div></div> - -<p>If you need to know the names of the individual file parts embedded in a "files" outer part (such as "book1" and "book2"), then please use List<Attachment> instead. It is currently not possible to use a Multipart annotation to refer to such inner parts but you can easily get the names from the individual Attachment instances representing these inner parts.</p> - -<p>Note that it is only the last request which has been structured according to the recommendation on how to upload multiple files but it is more complex than the other simpler requests linked to in this section. </p> - -<p>Please note that using JAX-RS FormParams is recommended for dealing with plain application/www-url-encoded submissions consisting of name/value pairs only.</p> - - -<h1 id="JAX-RSMultiparts-XOPsupport">XOP support</h1> - -<p>CXF JAXRS clients and endpoints can support <a shape="rect" class="external-link" href="http://www.w3.org/TR/xop10/" rel="nofollow">XML-binary Optimized Packaging (XOP)</a>.<br clear="none"> -What it means at a practical level is that a JAXB bean containing binary data is serialized using a multipart packaging, with the root part containing non-binary data only but also linking to co-located parts containing the actual binary payloads. Next it is deserialized into a JAXB bean on the server side.</p> - -<p>If you'd like to experiment with XOP then you need to set an "mtom-enabled" property on CXF jaxrs endpoints and clients.<br clear="none"> -Please see <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/JAXRSMultipartTest.java">JAXRSMultipartTest</a> (testXopWebClient) and <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/MultipartStore.java">MultipartStore</a> (addBookXop) for more details.</p> - -<h1 id="JAX-RSMultiparts-NoteaboutStruts">Note about Struts</h1> - -<p>If you are using CXF and <a shape="rect" class="external-link" href="http://struts.apache.org/2.2.1/index.html">Struts2</a> within the same application and expecting CXF to process multipart/form-data payloads then you need to make sure Struts2 dispatcher is not consuming the request input stream.</p> - -<p>One option is to let Struts2 handle URIs matching some specific patterns only, for example:</p> - -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[ -<web-app> +</div></div><p>If you need to know the names of the individual file parts embedded in a "files" outer part (such as "book1" and "book2"), then please use List<Attachment> instead. It is currently not possible to use a Multipart annotation to refer to such inner parts but you can easily get the names from the individual Attachment instances representing these inner parts.</p><p>Note that it is only the last request which has been structured according to the recommendation on how to upload multiple files but it is more complex than the other simpler requests linked to in this section.</p><p>Please note that using JAX-RS FormParams is recommended for dealing with plain application/www-url-encoded submissions consisting of name/value pairs only.</p><h2 id="JAX-RSMultiparts-Content-DispositionUTF-8filenames">Content-Disposition UTF-8 file names</h2><p>Starting from CXF 3.0.4 it is possible to specify a Content-Disposition file names in a UTF-8 format, using a "filename*" Content-Di sposition extension parameter as opposed to the "filename" one.</p><p>Please see <a shape="rect" class="external-link" href="https://tools.ietf.org/html/rfc6266" rel="nofollow">RFC 6266</a> and <a shape="rect" class="external-link" href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java;h=6eeedd42e965f4df8390ee6077222b34e1520732;hb=HEAD">this unit test</a> for more information. </p><h1 id="JAX-RSMultiparts-XOPsupport">XOP support</h1><p>CXF JAXRS clients and endpoints can support <a shape="rect" class="external-link" href="http://www.w3.org/TR/xop10/" rel="nofollow">XML-binary Optimized Packaging (XOP)</a>.<br clear="none"> What it means at a practical level is that a JAXB bean containing binary data is serialized using a multipart packaging, with the root part containing non-binary data only but also linking to co-located parts containing the actual binary payloads. Next it is deserialized into a JAX B bean on the server side.</p><p>If you'd like to experiment with XOP then you need to set an "mtom-enabled" property on CXF jaxrs endpoints and clients.<br clear="none"> Please see <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/JAXRSMultipartTest.java">JAXRSMultipartTest</a> (testXopWebClient) and <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/MultipartStore.java">MultipartStore</a> (addBookXop) for more details.</p><h1 id="JAX-RSMultiparts-NoteaboutStruts">Note about Struts</h1><p>If you are using CXF and <a shape="rect" class="external-link" href="http://struts.apache.org/2.2.1/index.html">Struts2</a> within the same application and expecting CXF to process multipart/form-data payloads then you need to make sure Struts2 dispatcher is not consuming the request input stream.</p><p>One option is to let Struts2 handle URIs matching some specific patterns only, for example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<web-app> <filter> <filter-name>struts2</filter-name> <filter-class> @@ -506,9 +325,7 @@ Please see <a shape="rect" class="extern </filter-mapping> </web-app> ]]></script> -</div></div> - -<p>Alternatively,disabling a "struts.multipart.parser" property might help.</p></div> +</div></div><p>Alternatively,disabling a "struts.multipart.parser" property might help.</p></div> </div> <!-- Content --> </td> Modified: websites/production/cxf/content/docs/jaxrs-services-description.html ============================================================================== --- websites/production/cxf/content/docs/jaxrs-services-description.html (original) +++ websites/production/cxf/content/docs/jaxrs-services-description.html Mon Feb 16 12:47:12 2015 @@ -118,11 +118,11 @@ Apache CXF -- JAXRS Services Description <!-- Content --> <div class="wiki-content"> <div id="ConfluenceContent"><p> </p><p> </p><p> </p><p> <span class="inline-first-p" style="font-size:2em;font-weight:bold">JAX-RS Services Description</span> </p><p> </p><p> </p><p> </p><p><style type="text/css">/*<![CDATA[*/ -div.rbtoc1419015837746 {padding: 0px;} -div.rbtoc1419015837746 ul {list-style: disc;margin-left: 0px;} -div.rbtoc1419015837746 li {margin-left: 0px;padding-left: 0px;} +div.rbtoc1424090804525 {padding: 0px;} +div.rbtoc1424090804525 ul {list-style: disc;margin-left: 0px;} +div.rbtoc1424090804525 li {margin-left: 0px;padding-left: 0px;} -/*]]>*/</style></p><div class="toc-macro rbtoc1419015837746"> +/*]]>*/</style></p><div class="toc-macro rbtoc1424090804525"> <ul class="toc-indentation"><li><a shape="rect" href="#JAXRSServicesDescription-WADLoverview">WADL overview</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAXRSServicesDescription-Basicexample">Basic example</a></li><li><a shape="rect" href="#JAXRSServicesDescription-WADLwithreferences">WADL with references</a></li><li><a shape="rect" href="#JAXRSServicesDescription-SharingdeclarationsbetweenmultipleWADLs">Sharing declarations between multiple WADLs</a></li></ul> </li><li><a shape="rect" href="#JAXRSServicesDescription-WADL-firstDevelopment">WADL-first Development</a> @@ -135,7 +135,7 @@ div.rbtoc1419015837746 li {margin-left: </li><li><a shape="rect" href="#JAXRSServicesDescription-CustomizingWADLGeneration">Customizing WADL Generation</a> <ul class="toc-indentation"><li><a shape="rect" href="#JAXRSServicesDescription-RepresentingexplicitJAXBcollections">Representing explicit JAXB collections</a></li><li><a shape="rect" href="#JAXRSServicesDescription-RepresentingexternalschemasandnonJAXBtypes">Representing external schemas and non JAXB types</a></li><li><a shape="rect" href="#JAXRSServicesDescription-Changingthebaseaddress">Changing the base address</a></li></ul> </li></ul> -</li><li><a shape="rect" href="#JAXRSServicesDescription-java2wadlMavenplugin">java2wadl Maven plugin</a></li><li><a shape="rect" href="#JAXRSServicesDescription-ServicelistingsandWADLqueries">Service listings and WADL queries</a></li><li><a shape="rect" href="#JAXRSServicesDescription-WADLinJSONformat">WADL in JSON format</a></li><li><a shape="rect" href="#JAXRSServicesDescription-HidinglinkstoJAXRSendpointsfromtheservicespage">Hiding links to JAXRS endpoints from the services page</a></li></ul> +</li><li><a shape="rect" href="#JAXRSServicesDescription-java2wadlMavenplugin">java2wadl Maven plugin</a></li><li><a shape="rect" href="#JAXRSServicesDescription-WADLTransformations">WADL Transformations</a></li><li><a shape="rect" href="#JAXRSServicesDescription-ServicelistingsandWADLqueries">Service listings and WADL queries</a></li><li><a shape="rect" href="#JAXRSServicesDescription-WADLinJSONformat">WADL in JSON format</a></li><li><a shape="rect" href="#JAXRSServicesDescription-HidinglinkstoJAXRSendpointsfromtheservicespage">Hiding links to JAXRS endpoints from the services page</a></li></ul> </div><p>CXF JAX-RS supports (Web Application Description Language|http://www.w3.org/Submission/wadl] (WADL). <br clear="none"> Users can use WADL documents to generate the initial code and have WADL auto-generated on demand.</p><h1 id="JAXRSServicesDescription-WADLoverview">WADL overview</h1><p>WADL is a resource-centric description language which has been designed to facilitate the modeling, description and testing of<br clear="none"> RESTful Web applications. Please check the official <a shape="rect" class="external-link" href="http://www.w3.org/Submission/wadl/" rel="nofollow">page</a> for more information, this section provides a brief overview of main WADL constructs.</p><h2 id="JAXRSServicesDescription-Basicexample">Basic example</h2><p>A top level WADL document element is called "application". Usually it may contain a "grammars" section and "resources" element with one or more top-level "resource" elements, with each one representing a specific root resource, for example:</p ><div class="code panel pdl" style="border-width: 1px;"><div >class="codeContent panelContent pdl"> <script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:ns="http://superbooks"> <grammars> @@ -377,7 +377,7 @@ wg.setSchemaLocations(Collections.single --> <representation mediaType="application/xml" element="prefix1:thebook2"/> ]]></script> -</div></div><p>If no JAXB is used then you can attach an <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java">XMLName</a> annotation to method input or output types. Alternatively, you can register an instance of <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementQNameResolver.java">ElementQNameResolver</a> with the WadlGenerator which will be used for creating wadl:representation/@element values.</p><h3 id="JAXRSServicesDescription-Changingthebaseaddress">Changing the base address</h3><p>Starting from CXF 2.6.2 it is possible to affect the base address specified in the auto-generated WADL (in wadl:resources/@base attribute).<br clear="none"> WADLGenerator can be indirectly configured by setting a jaxrs:server/@publishedEndpointUrl attribute, similarly to the way CXF WS DL generator can be configured by setting a jaxws:endpoint/@publishedEndpointUrl attribute.</p><h1 id="JAXRSServicesDescription-java2wadlMavenplugin">java2wadl Maven plugin</h1><p>CXF 3.0.0 and 2.7.11 introduce java2wadl plugin for generating WADL at the build time:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>If no JAXB is used then you can attach an <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/XMLName.java">XMLName</a> annotation to method input or output types. Alternatively, you can register an instance of <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ElementQNameResolver.java">ElementQNameResolver</a> with the WadlGenerator which will be used for creating wadl:representation/@element values.</p><h3 id="JAXRSServicesDescription-Changingthebaseaddress">Changing the base address</h3><p>Starting from CXF 2.6.2 it is possible to affect the base address specified in the auto-generated WADL (in wadl:resources/@base attribute).<br clear="none"> WADLGenerator can be indirectly configured by setting a jaxrs:server/@publishedEndpointUrl attribute, similarly to the way CXF WS DL generator can be configured by setting a jaxws:endpoint/@publishedEndpointUrl attribute.</p><p> </p><h1 id="JAXRSServicesDescription-java2wadlMavenplugin">java2wadl Maven plugin</h1><p>CXF 3.0.0 and 2.7.11 introduce java2wadl plugin for generating WADL at the build time:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[<groupId>org.apache.cxf</groupId> <artifactId>cxf-java2wadl-plugin</artifactId> <version>3.0.0</version> @@ -423,7 +423,7 @@ wg.setSchemaLocations(Collections.single </plugins> </build> ]]></script> -</div></div><p>Note that Javadoc can be properly supported by enabling the "parsejavadoc" execution and a docProvider property.</p><h1 id="JAXRSServicesDescription-ServicelistingsandWADLqueries">Service listings and WADL queries</h1><p>Links to WADL instances for RESTful endpoints are available from {base endpointaddress}/services, in addition to SOAP endpoints if any.</p><p>For example, given</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>Note that Javadoc can be properly supported by enabling the "parsejavadoc" execution and a docProvider property.</p><h1 id="JAXRSServicesDescription-WADLTransformations">WADL Transformations</h1><p>Starting from CXF 3.0.4 it is possible to configure WADLGenerator with a 'stylesheetReference' property pointing to a local XSLT template. </p><p>If an 'applyStylesheetLocally' property is disabled (default) then a generated WADL XML representation will include an XML XSLT processing instruction pointing to a template with the browser downloading it in the next step and doing the transformation itself. Otherwise WADLGenerator will attempt to do a local transformation before returning a response to the browser.</p><p>This feature can help with further enhancing the generated WADL XML with some simple transformations (example, adding some information to WADL XML that is not possible to get from the annotated JAX-RS resources) or convert it to HTML.</p><h1 id="JAXRSServic esDescription-ServicelistingsandWADLqueries">Service listings and WADL queries</h1><p>Links to WADL instances for RESTful endpoints are available from {base endpointaddress}/services, in addition to SOAP endpoints if any.</p><p>For example, given</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[Base address : 'http://localhost:8080' WAR name : 'store' CXFServlet : '/books/*'