dev@glassfish.java.net

Re: JAX-WS client memory usage

From: Marshall Pierce <marshall_at_genius.com>
Date: Thu, 26 Aug 2010 18:06:52 -0700

On 08/26/2010 11:40 AM, Rama Pulavarthi wrote:
> On 08/25/2010 04:32 PM, Marshall Pierce wrote:
>> On 08/25/2010 10:39 AM, Rama Pulavarthi wrote:
>>> Yes, JAXBContext is threasafe. You can use UsesJAXBContextFeature on the
>>> client side. Please see the sample from jax-ws unit tests at
>>> http://fisheye5.cenqua.com/browse/jax-ws-sources/jaxws-unit/testcases/fromjava/custom_client_jaxbcontext
>>>
>>>
>>
>> I've looked at the various constructors of UsesJAXBContextFeature, but
>> I'm not seeing how to accomplish the goal of reusing one JAXBRIContext
>> object. Should I create a UsesJAXBContextFeature that always returns
>> the same JAXBRIContext object? If so, where do I get the JAXBRIContext
>> instance to reuse?
>>
> I have n't verified this, Let us know if this works.
>
> As all of your client proxies share the same SEI and WSDL definition,
> then you try something like this.
>
> new JAXBContextFactory() {
> JAXBRIContext jaxbCtxt = null;
> public JAXBRIContext createJAXBContext(@NotNull SEIModel sei,
> @NotNull List<Class> classesToBind, @NotNull List<TypeReference>
> typeReferences) throws JAXBException {
> if(jaxbCtxt ==null) {
> jaxbCtxt =
> JAXBContextFactory.DEFAULT.createJAXBContext(sei,classesToBind,typeReferences);
> }
> return jaxbctxt;
> }
> };
>
> thanks,
> Rama Pulavarthi

Rama,
I tried this approach (caching the response of the default factory
impl), but this is what happens the *second* time I try to create a
proxy off of the service:

java.lang.NullPointerException
        at
com.sun.xml.ws.client.sei.SEIMethodHandler.<init>(SEIMethodHandler.java:92)
        at
com.sun.xml.ws.client.sei.SyncMethodHandler.<init>(SyncMethodHandler.java:84)
        at com.sun.xml.ws.client.sei.SEIStub.<init>(SEIStub.java:82)
        at
com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:639)
        at
com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:342)
        at
com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:324)
        at javax.xml.ws.Service.getPort(Service.java:133)
        at com.genius.crm.sf.jaxwsstub.SforceService.getSoap(SforceService.java:70)