Hi!

I see WriterInterceptorContext could be used, but it also requires
CachedOutputStream to intercept OutputStream, I see this in
JweJsonWriterInterceptor...
So CachedOutputStream bug will be repeated in WriterInterceptorContext



2016-09-20 13:13 GMT+04:00 Sergey Beryozkin <sberyoz...@gmail.com>:

> Hi,
> JAX-RS ContainerRequestContext and ContainerResponseContext, as well as
> WriterInterceptorContext and ReaderInterceptorContext filter contexts all
> allow resetting the entity streams or on the way out - entity objects -
> perhaps that can offer a simpler option for replacing the content...
>
> Cheers, Sergey
>
> On 19/09/16 11:30, Vjacheslav V. Borisov wrote:
>
>> During message.getInterceptorChain().doIntercept(message); I see call to
>> maybeDeleteTempFile() which resets inmem = true;
>> and later csnew.getInputStream() execution leads to if (inmem) { }
>>
>> 2016-09-19 13:05 GMT+04:00 Vjacheslav V. Borisov <slav...@gmail.com>:
>>
>> Hi!
>>>
>>> I have following code (this is interceptror which does regular expression
>>> replacements)
>>>
>>>
>>> https://github.com/ilb/common/blob/master/common-jaxrs/src/
>>> main/java/ru/ilb/common/jaxrs/interceptors/ReplaceOutInterceptor.java
>>>
>>>     private void replaceContents(Message message) {
>>>         OutputStream os = message.getContent(OutputStream.class);
>>>         CachedStream cs = new CachedStream();
>>>         message.setContent(OutputStream.class, cs);
>>>
>>>         message.getInterceptorChain().doIntercept(message);
>>>
>>>         try {
>>>             cs.flush();
>>>             CachedOutputStream csnew = (CachedOutputStream)
>>> message.getContent(OutputStream.class);
>>>
>>>             String contents = IOUtils.toString(csnew.getInputStream());
>>>             for (Map.Entry<String, String> keyValue :
>>> replacements.entrySet()) {
>>>                 contents = contents.replaceAll(keyValue.getKey(),
>>> keyValue.getValue());
>>>             }
>>>             //String replaced=contents.replaceAll(regex, replacement);
>>>             os.write(contents.getBytes(Charset.forName(encoding)));
>>>             os.flush();
>>>
>>>             message.setContent(OutputStream.class, os);
>>>
>>>         } catch (IOException ioe) {
>>>             throw new RuntimeException(ioe);
>>>         }
>>>     }
>>>
>>>
>>>
>>> Howewer,  when response contents length of if less than threshold (128 *
>>> 1024 bytes)
>>> i can get csnew.getInputStream() and get its contents, but when content
>>> is
>>> more than treshold,
>>> i see that in enforceLimits() -> createFileOutputStream() temp file is
>>> created,
>>> but using csnew.getInputStream() I am getting empty stream.
>>>
>>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Reply via email to