You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jorg Heymans <jo...@gmail.com> on 2016/04/08 13:18:41 UTC

ReflectionServiceFactoryBean performance - continued

Hi,

I would like to revive this thread [1], and figure out how to make cxf not
instantiate a new jaxbcontext per <jaxws:client> element. Currently
jaxb/cxf is consuming about 800mb of heap after startup (the jaxb context
we need to use is huge)

It was suggested that i could inject a singleton context myself :

  <jaxws:client ...>
    <jaxws:dataBinding>
      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <constructor-arg index="0" ref="globalSfcContext"/>
      </bean>
    </jaxws:dataBinding>
  </jaxws:client>

This failed because of missing wrapper classes (the webservices we use are
defined with BARE parameter style). These are generated dynamically by CXF
using asm and apparently this makes that cxf does not reuse the one
generated jaxbcontext across the 15 client definitions we have.

Could it not be considered a missing feature of cxf that it fails to use a
single generated context for BARE style webservices ? The jax-rs
implementation seems to have a way to force a single context:
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-SingleJAXBContextandextrauserclasses
,
is something similar not feasible for jaxws ?

Thanks,
Jorg Heymans

Re: ReflectionServiceFactoryBean performance - continued

Posted by Jorg Heymans <jo...@gmail.com>.
Hi,

After some more detailed step debugging, i figured that by overriding below
method in JAXBDataBinding i could trick cxf into reusing the same
jaxbcontext:

    @Override
    public JAXBContextCache.CachedContextAndSchemas
createJAXBContextAndSchemas(Set<Class<?>> classes, String defaultNs) throws
JAXBException {

//        //add user extra class into jaxb context
//        if (extraClass != null && extraClass.length > 0) {
//            for (Class<?> clz : extraClass) {
//                classes.add(clz);
//            }
//        }
//        if (scanPackages) {
        JAXBContextCache.scanPackages(classes);
//        }
//        addWsAddressingTypes(classes);

        return JAXBContextCache.getCachedContextAndSchemas(classes, "
http://same.namespace", null, null, true);

    }

I had to comment out some lines accessing private fields but it did not
seem to have an impact. After that the key part to make it work is to set
the namespace to a fixed string because it is used as a lookup key in the
jaxb context cache. Normally different services have different namespaces
so i wonder how the context cache can ever return a cached context for
different services.

Maybe there could be an attribute on <jaxws:client> allowing for a cache
key to be set ? That way the user could decide which services share a jaxb
context.


Thanks,
Jorg



On Fri, Apr 8, 2016 at 1:18 PM Jorg Heymans <jo...@gmail.com> wrote:

> Hi,
>
> I would like to revive this thread [1], and figure out how to make cxf not
> instantiate a new jaxbcontext per <jaxws:client> element. Currently
> jaxb/cxf is consuming about 800mb of heap after startup (the jaxb context
> we need to use is huge)
>
> It was suggested that i could inject a singleton context myself :
>
>   <jaxws:client ...>
>     <jaxws:dataBinding>
>       <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>         <constructor-arg index="0" ref="globalSfcContext"/>
>       </bean>
>     </jaxws:dataBinding>
>   </jaxws:client>
>
> This failed because of missing wrapper classes (the webservices we use are
> defined with BARE parameter style). These are generated dynamically by CXF
> using asm and apparently this makes that cxf does not reuse the one
> generated jaxbcontext across the 15 client definitions we have.
>
> Could it not be considered a missing feature of cxf that it fails to use a
> single generated context for BARE style webservices ? The jax-rs
> implementation seems to have a way to force a single context:
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-SingleJAXBContextandextrauserclasses ,
> is something similar not feasible for jaxws ?
>
> Thanks,
> Jorg Heymans
>