[ 
https://issues.apache.org/jira/browse/CXF-6837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15236847#comment-15236847
 ] 

Neal Hu commented on CXF-6837:
------------------------------

Sample shows we need a list in the cache, suppose we only have single value in 
the cache:
Teacher extends Person
First request:
write Teacher object with the http header "Teacherwritable"="false", then we 
select ParentProvider and addto cache with the key="Teacher-xxxx".

Second requst:
write Teacher object with the http header "Teacherwritable"="true", then get  
ParentProvider and write, but now the nearest provider is ChildProvider.
{code:java}
@Provider
public class ParentProvider implements MessageBodyWriter<Person> {

        @Context HttpHeaders headers;
        
        @Override
        public long getSize(Person arg0, Class<?> arg1, Type arg2, Annotation[] 
arg3, MediaType arg4) { 
                return 0;
        }

        @Override
        public boolean isWriteable(Class<?> arg0, Type t, Annotation[] arg2, 
MediaType arg3) {

        
                return true;
        }

        @Override
        public void writeTo(Person arg0, Class<?> arg1, Type arg2, Annotation[] 
arg3, MediaType arg4,
                        MultivaluedMap<String, Object> arg5, OutputStream arg6) 
throws IOException, WebApplicationException {
                // TODO Auto-generated method stub
                arg6.write("hello Person".getBytes());
        }

}
{code}

{code:java}
@Provider
public class ChildProvider implements MessageBodyWriter<Teacher> {

        @Context HttpHeaders headers;
        
        @Override
        public long getSize(Teacher arg0, Class<?> arg1, Type arg2, 
Annotation[] arg3, MediaType arg4) {        
                return 0;
        }

        @Override
        public boolean isWriteable(Class<?> arg0, Type t, Annotation[] arg2, 
MediaType arg3) {
                // TODO Auto-generated method stub
                if(headers.getHeaderString("Teacherwritable") == "true"){
                        return true;
                }
        
                return false;
        }

        @Override
        public void writeTo(Teacher arg0, Class<?> arg1, Type arg2, 
Annotation[] arg3, MediaType arg4,
                        MultivaluedMap<String, Object> arg5, OutputStream arg6) 
throws IOException, WebApplicationException {
                // TODO Auto-generated method stub
                arg6.write("hello Teacher".getBytes());
        }

}
{code}

> Add cache for MessageBodyReader/Writer
> --------------------------------------
>
>                 Key: CXF-6837
>                 URL: https://issues.apache.org/jira/browse/CXF-6837
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 3.1.5, 3.0.8
>         Environment: windows
>            Reporter: Neal Hu
>             Fix For: 3.2.0
>
>         Attachments: ListAProvider.java, ListBProvider.java, 
> ProviderCache.java, ProviderFactory.patch, Resource.java, beans.xml, web.xml
>
>
> CXF selects the msgBodyReader/writer in the reader/writer list for every 
> request, which has big impact to the performance. Jersey also has the cache 
> in 
> org.glassfish.jersey.message.internal.MessageBodyFactory._getMessageBodyReader(...).
>  I have tried add the cache for CXF in ProviderFactory and been proved that 
> it has improved 7-8% for json requests in JMeter. Please let me know if you'd 
> like me to add the enhancement for CXF. Thanks. 
> http://cxf.547215.n5.nabble.com/MessageBodyReader-Writer-cache-td5767091.html



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to