cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: consuming multipart/mixed
Date Wed, 12 Dec 2012 10:03:48 GMT
Hi Stephan

I've realized one more option is actually there, simply explicitly 
register MultipartProvider and exclude "multipart/mixed" by setting a 
restricted produceMediaTypes list value, say containing only 
multipart/related or form-data.

Though the option with the custom provider is probably cleaner.
Perhaps we could've made MultipartProvider optional, but I thought 
supporting multiparts was a pretty fundamental requirement, so it's 
enabled by default at the moment

Cheers, Sergey


On 12/12/12 07:56, Klevenz, Stephan wrote:
> Jep, that sounds good and seems to be exactly what I need.
>
> Many Thanks!
>
> Greetings,
> Stephan
>
> On 12/11/12 6:32 PM, "Sergey Beryozkin"<sberyozkin@gmail.com>  wrote:
>
>> Hi Stephan
>>
>> On 11/12/12 16:47, Klevenz, Stephan wrote:
>>> Hi Sergey,
>>>
>>> Thanks for already fast reply.
>>>
>>> I have attached a thread dump and the involved class was
>>> AttachmentInInterceptor.
>>>
>>> I assume the MultipartBody will work and I could also access the stream
>>> via injected MessageContext. The problem is that both, MultipartBody and
>>> MessageContext, are CXF dependencies. Our code, at least for this part,
>>> should depend on JAX-RS API only.
>>>
>>> So is there an option to tell CXF not to handle multipart/mixed
>>> messages?
>>
>> Sure, can you please extend CXF MultipartProvider and override its
>> readFrom and return false if it is InputStream.class ?
>> Or probably better yet, register a custom JAX-RS MessageBodyReader which
>> will have @Consumes("multipart/mixed"), and typed on InputStream, and
>> return the input stream immediately in its readFrom.
>>
>> I guess with CXF 2.7.1 you can also use JAX-RS 2.0 ReaderInterceptor to
>> get the same done
>>
>> HTH
>>
>> Cheers, Sergey
>>
>>>
>>> Regards,
>>> Stephan
>>>
>>>
>>> org.apache.cxf.jaxrs.provider.MultipartProvider readFrom()
>>>
>>> org.apache.cxf.interceptor. AttachmentInInterceptor handleMessage()
>>>
>>>
>>>
>>> Thread [qtp14633156-18 - /odata.svc/$batch] (Suspended (breakpoint at
>>> line
>>> 60 in AttachmentInInterceptor))
>>>           owns: PhaseInterceptorChain  (id=65)
>>>
>>>
>>> AttachmentInputInterceptor(AttachmentInInterceptor).handleMessage(Message
>>> )
>>> line: 60
>>>           MessageContextImpl.createAttachments(String) line: 235
>>>           MessageContextImpl.get(Object) line: 73
>>>           ThreadLocalMessageContext.get(Object) line: 38
>>>           AttachmentUtils.getMultipartBody(MessageContext, String,
>>> String,
>>> String) line: 89
>>>           AttachmentUtils.getAttachments(MessageContext, String, String,
>>> String) line: 94
>>>           MultipartProvider.readFrom(Class<Object>, Type, Annotation[],
>>> MediaType, MultivaluedMap<String,String>, InputStream) line: 136
>>>           JAXRSUtils.readFromMessageBody(Class<T>, Type, Annotation[],
>>> InputStream, MediaType, List<MediaType>, Message) line: 1038
>>>           JAXRSUtils.processParameter(Class<?>, Type, Annotation[],
>>> Parameter, MultivaluedMap<String,String>, Message,
>>> OperationResourceInfo)
>>> line: 614
>>>           JAXRSUtils.processParameters(OperationResourceInfo,
>>> MultivaluedMap<String,String>, Message) line: 578
>>>           JAXRSInInterceptor.processRequest(Message) line: 238
>>>           JAXRSInInterceptor.handleMessage(Message) line: 89
>>>           PhaseInterceptorChain.doIntercept(Message) line: 262
>>>           ChainInitiationObserver.onMessage(Message) line: 122
>>>
>>> ServletDestination(AbstractHTTPDestination).invoke(ServletConfig,
>>> ServletContext, HttpServletRequest, HttpServletResponse) line: 211
>>>           ServletController.invokeDestination(HttpServletRequest,
>>> HttpServletResponse, AbstractHTTPDestination) line: 213
>>>           ServletController.invoke(HttpServletRequest,
>>> HttpServletResponse)
>>> line: 154
>>>
>>> CXFNonSpringJaxrsServlet(CXFNonSpringServlet).invoke(HttpServletRequest,
>>> HttpServletResponse) line: 129
>>>
>>>
>>> CXFNonSpringJaxrsServlet(AbstractHTTPServlet).handleRequest(HttpServletRe
>>> qu
>>> est, HttpServletResponse) line: 187
>>>
>>> CXFNonSpringJaxrsServlet(AbstractHTTPServlet).doPost(HttpServletRequest,
>>> HttpServletResponse) line: 110
>>>
>>> CXFNonSpringJaxrsServlet(HttpServlet).service(HttpServletRequest,
>>> HttpServletResponse) line: 727
>>>
>>> CXFNonSpringJaxrsServlet(AbstractHTTPServlet).service(ServletRequest,
>>> ServletResponse) line: 166
>>>           ServletHolder.handle(Request, ServletRequest, ServletResponse)
>>> line: 547
>>>           ServletHandler.doHandle(String, Request, HttpServletRequest,
>>> HttpServletResponse) line: 480
>>>           SessionHandler.doHandle(String, Request, HttpServletRequest,
>>> HttpServletResponse) line: 225
>>>           ServletContextHandler(ContextHandler).doHandle(String, Request,
>>> HttpServletRequest, HttpServletResponse) line: 940
>>>           ServletHandler.doScope(String, Request, HttpServletRequest,
>>> HttpServletResponse) line: 409
>>>           SessionHandler.doScope(String, Request, HttpServletRequest,
>>> HttpServletResponse) line: 186
>>>           ServletContextHandler(ContextHandler).doScope(String, Request,
>>> HttpServletRequest, HttpServletResponse) line: 874
>>>           ServletContextHandler(ScopedHandler).handle(String, Request,
>>> HttpServletRequest, HttpServletResponse) line: 117
>>>           HandlerCollection.handle(String, Request, HttpServletRequest,
>>> HttpServletResponse) line: 149
>>>           Server(HandlerWrapper).handle(String, Request,
>>> HttpServletRequest,
>>> HttpServletResponse) line: 110
>>>           Server.handle(HttpConnection) line: 345
>>>
>>>
>>> SelectChannelConnector$SelectChannelHttpConnection(HttpConnection).handle
>>> Re
>>> quest() line: 441
>>>           HttpConnection$RequestHandler.content(Buffer) line: 936
>>>           HttpParser.parseNext() line: 801
>>>           HttpParser.parseAvailable() line: 224
>>>
>>>
>>> SelectChannelConnector$SelectChannelHttpConnection(AsyncHttpConnection).h
>>> an
>>> dle() line: 52
>>>           SelectChannelEndPoint.handle() line: 586
>>>           SelectChannelEndPoint$1.run() line: 44
>>>           QueuedThreadPool.runJob(Runnable) line: 598
>>>           QueuedThreadPool$3.run() line: 533
>>>           Thread.run() line: not available
>>>
>>>
>>>
>>>
>>> On 12/11/12 2:46 PM, "Sergey Beryozkin"<sberyozkin@gmail.com>   wrote:
>>>
>>>> Stephan, by the way, I'm not seeing
>>>>
>>>> 'MailAttachmentInterceptor' in CXF source...
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 11/12/12 13:44, Sergey Beryozkin wrote:
>>>>> Hi Stephan
>>>>>
>>>>> On 11/12/12 13:17, Klevenz, Stephan wrote:
>>>>>> Dear CXF Gurus and Community!
>>>>>>
>>>>>> I want to consume a multipart/mixed payload via a stream like shown
>>>>>> in
>>>>>> the example code below. Unfortunately it seems that injected stream
>>>>>> is
>>>>>> already closed and can not be used anymore. Debugging CXF shows that
>>>>>> a
>>>>>> MailAttachmentInterceptor has taken the stream before it is injected.
>>>>>> Is there an option to avoid that behavior?
>>>>>>
>>>>>> Thanks in advance.
>>>>>>
>>>>>> Greetings,
>>>>>> Stephan
>>>>>>
>>>>>>
>>>>>> @POST
>>>>>> @Consumes("multipart/mixed")
>>>>>> @Produces("multipart/mixed")
>>>>>> public StreamingOutput createItem(InputStream requestBodyStream)
{
>>>>>> /* read the requestBodyStream like a normal input stream */
>>>>>> return new StreamingOutput() {
>>>>>>
>>>>>> public void write(OutputStream output) throws IOException,
>>>>>> WebApplicationException {
>>>>>> byte[] out = /* get some bytes to write */
>>>>>> output.write(out);
>>>>>> }
>>>>>> })
>>>>>> }
>>>>>>
>>>>>>
>>>>> Can you replace the above with
>>>>>
>>>>> public StreamingOutput createItem(MultipartBody body) {
>>>>>
>>>>> // assuming a single attachment:
>>>>> InputStream is =
>>>>> body.getRootAttachment().getObject(InputStream.class);
>>>>> //or
>>>>>
>>>>> InputStream is = body.getAttachmentObject("partId",
>>>>> InputStream.class);
>>>>>
>>>>> }
>>>>>
>>>>> Quite a few other options are also possible, please see
>>>>>
>>>>> http://cxf.apache.org/docs/jax-rs-multiparts.html
>>>>>
>>>>> Let me know please if it works for you
>>>>> HTH, Sergey
>>>
>


Mime
View raw message