Hi
On 20/05/13 21:28, Penmatsa, Vinay wrote:
Hi,
I have a REST service based on JAX-WS Provider and Dispatch (implementing 
Provider<DataSource>). Until now, I accept/produce only XML. Now, I have to 
support attachments.
Now, it seems like request should be "multipart/related" as only 
AttachmentInInterceptor is part of the chain by default. I could probably change that to 
use AttachmentInputInterceptor instead. The question is how can I can I return 
MultipartBody? Is there in-built support for that or should I create my own DataSource 
and handle with an custom out interceptor?

Adding @Consumes("multipart/related") should be enough to get DataSource representing the root attachment, and similarly adding

@Produces("multipart/related") is nearly enough to get out DataSource converted to the multipart payload, except that you also need to specify the content type of this root type, so it can look like this:

@Produces("multipart/related;type=application/xml")
@Consumes("multipart/related")
public DataSource a(DataSource ds) {
    return ds;
}

My understanding you'd like to have a 100% portable code, right ?

Note that up to CXF 3.0-SNAPSHOT, the input 'ds' parameter will represent the root part of the incoming payload. The response DataSource also represents the root part of the outgoing attachment. I think it is rarely that someone will want to have 'ds' (in this case) representing the actual non-parsed multipart payload or manually build the actual multipart body, so originally I went that path.

In CXF 3.0, due to JAX-RS 2.0 TCK 'insistence' on the types like DataSource, InputStream, byte[] be supported by basic pre-packaged providers, the above will slightly change to:

@Produces("multipart/related;type=application/xml")
@Consumes("multipart/related")
@Multipart
public DataSource a(@Multipart DataSource ds) {
    return ds;
}

Where CXF @Multipart annotation marks in and out parameters as multipart bodies. Without @Multipart the 1st example above will produce a portable but more complex code (meaning DataSource will have to be manually parsed or used to create the out payload manually)

Sergey




Thanks,
Vinay




Reply via email to