<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">I meant use the ContentType of entity
from ClientRequestContext instead of Accept. <br>
<br>
For the accept type and response content type dismatch, this is
something server side should handle and http 406 should be
returned for this case. <br>
If accept type is application/json with response content type is
application/xml is replied by other server, and user still wants
to consume <br>
this application/xml type result and cache can still support
this. WDYT ?<br>
<br>
<br>
On 10/22/2018 02:38 PM, Petr Jurak wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAL1mVq84fko-qTR_K6SAS2G7LeZdQ6qSyKPZ4VhnfKpkUUZjXg@mail.gmail.com">
<div dir="ltr">Yep, this will and actually this was the original
idea to use Accept instead of Content-Type. But I had some
doubts if this is good solution.
<div><br>
</div>
<div>Let me sum it up what I want to do:</div>
<div>Use Accept if present, if not use Content-Type. Charset
will not be taken into account.</div>
<div><br>
</div>
<div>Note: as an example, Content-Type is application/xml and
Accept is application/json, so it will be stored with
application/json, but the real content is XML. This is my main
concern.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Petr</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Mon, Oct 22, 2018 at 4:53 AM Jim Ma <<a
href="mailto:ema@redhat.com" moz-do-not-send="true">ema@redhat.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div class="m_2682786173733405280moz-cite-prefix">Can we
only use the request uri + method + request mediaType as
the cache key ?<br>
Will this resolve these two issues ?<br>
<br>
Thanks,<br>
Jim<br>
<br>
On 10/18/2018 03:27 PM, Petr Jurak wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I was looking into RESTEASY-2038 [1].
I'm not sure how to handle this
correctly so I need to know your
opinion.</div>
<div><br>
</div>
<div>In the <i>org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor</i>
there is a method for storing response
in the cache containing this part. </div>
<div><br>
</div>
<div>
<div><i>String contentType = (String)
response.getHeaderString(HttpHeaders.CONTENT_TYPE);</i></div>
<div><i>byte[] cached =
ReadFromStream.readFromStream(1024,
response.getEntityStream());<br>
</i></div>
<div><i>MediaType mediaType =
MediaType.valueOf(contentType);<br>
</i></div>
<div><i>final BrowserCache.Entry entry =
cache.put(request.getUri().toString(), mediaType,</i></div>
<div><i> response.getHeaders(),
cached, expires, etag,
lastModified);</i></div>
</div>
<div><br>
</div>
<div>Later, once the same GET method is
executed, the interceptor checks if
there is an entry in the cache for the
given Accept type.</div>
<div><br>
</div>
<div><i>BrowserCache.Entry entry =
getEntry(request);</i><br>
</div>
<div><br>
</div>
<div>In the getEntry method it checks for
the type</div>
<div><i><br>
</i></div>
<div>
<div><i>entry = cache.get(uri, accept);</i></div>
<div><i>if (entry != null) return entry;</i></div>
<div><i>if
(MediaTypeHelper.isTextLike(accept))</i></div>
<div><i>{</i></div>
<div><i> entry = cache.get(uri,
accept.withCharset("UTF-8"));</i></div>
<div><i> if (entry != null) return
entry;</i></div>
<div><i>}</i></div>
</div>
<div><br>
</div>
<div>Let's assume that resource returns
XML data with Content-Type:
application/xml;charset=UTF-8</div>
<div>and the client sends Accept:
application/xml</div>
<div>So the very first request adds into
the cache entry for
application/xml;charset=UTF-8 because it
is taken from Content-Type header.</div>
<div><br>
</div>
<div>Subsequent request gets the cached
value (expecting that entry is not
expired), although it cannot find it
under application/xml, it is found under
application/xml;charset=UTF-8 because of
this:</div>
<div><i><br>
</i></div>
<div><i>cache.get(uri,
accept.withCharset("UTF-8"));</i><br>
</div>
<div><br>
</div>
<div>The problem is if decide to change
the code to use Accept instead of
current Content-Type, we can't be sure
if there is Accept header in the request
and we're not sure about response
encoding.<br>
</div>
<div><br>
</div>
<div>Also the statement in Jira regarding
content type mismatch: like Accept is
application/json, but resource returns
application/xml and to store it under
application/json instead of
application/xml is IMHO wrong (coding
issue). I believe that it should be
stored per actual content type.</div>
<div><br>
</div>
<div>Your thoughts?</div>
<div><br>
</div>
<div>Thanks!</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Petr</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>[1] <a
href="https://issues.jboss.org/browse/RESTEASY-2038"
target="_blank" moz-do-not-send="true">https://issues.jboss.org/browse/RESTEASY-2038</a><br
clear="all">
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset
class="m_2682786173733405280mimeAttachmentHeader"></fieldset>
<br>
<pre>_______________________________________________
resteasy-dev mailing list
<a class="m_2682786173733405280moz-txt-link-abbreviated" href="mailto:resteasy-dev@lists.jboss.org" target="_blank" moz-do-not-send="true">resteasy-dev@lists.jboss.org</a>
<a class="m_2682786173733405280moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/resteasy-dev" target="_blank" moz-do-not-send="true">https://lists.jboss.org/mailman/listinfo/resteasy-dev</a>
</pre>
</blockquote>
<p><br>
</p>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr">
<p
style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-weight:bold;margin:0px;padding:0px;font-size:14px;text-transform:uppercase"><span>PETR</span> <span>JURAK</span></p>
<p
style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:10px;margin:0px
0px 4px;text-transform:uppercase"><span>SENIOR
SOFTWARE ENGINEER</span><span
style="color:rgb(170,170,170);margin:0px"></span></p>
<p
style="font-family:overpass,sans-serif;margin:0px;font-size:10px;color:rgb(153,153,153)"><a
href="https://www.redhat.com/"
style="color:rgb(0,136,206);margin:0px"
target="_blank" moz-do-not-send="true">Red Hat <span><br>
<br>
</span></a></p>
<table
style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:medium"
border="0">
<tbody>
<tr>
<td width="100px"><a href="https://red.ht/sig"
target="_blank" moz-do-not-send="true"><img
src="https://www.redhat.com/files/brand/email/sig-redhat.png"
moz-do-not-send="true" height="auto"
width="90"></a></td>
<td style="font-size:10px">
<div><a href="https://redhat.com/trusted"
style="color:rgb(204,0,0);font-weight:bold"
target="_blank" moz-do-not-send="true">TRIED.
TESTED. TRUSTED.</a></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<p><br>
</p>
</body>
</html>