On Fri December 4 2009 10:59:11 am Nathaniel Auvil wrote:
> is there a best practice to create a service Singleton and have all your
> threads use it rather than create it new all the time?

Well, it's kind of  tradeoff of memory vs performance and only you can answer 
that in your application.

When we create a Service object, we need to download and parse the WSDL.     
The WSDL is held in a weak cache so it COULD still be around next time you 
create a service, but it might not be.   If the service is a singleton, it 
would keep it around forever consuming memory.   If you never need it again, 
that's a waste of memory.

Likewise, the client proxies created from the Service could ALSO be 
singletons.  (caveat: see the FAQ about the thread safety of these: 
http://cxf.apache.org/faq.html)    When we create a proxy, we have to create 
JAXBContexts, wire the wsdl information in, map methods, etc.... which is 
expensive.   However, holding onto the proxy consumes memory due to the jaxb 
context, method maps, etc.....   

In general, my recommendation is that if the service will be used pretty 
often, a singleton is definitely appropriate. The cost of creating new proxies 
per request is pretty high so reusing them is definitely a good thing.    If 
the service is not used often, then don't.

One more caveat:  the Service and Proxy objects in the JAX-WS RI are NOT 
thread safe at all.   Thus, from a portability standpoint, once you do this, 
you are kind of tied to CXF.    The RI folks recommend either synchronizing on 
the objects or use a pool.    Personally, I prefer just making the things 
thread safe if possible.   :-)


Dan





> 
> On Fri, Dec 4, 2009 at 10:55 AM, Benson Margulies 
<[email protected]>wrote:
> > The WSDL reader just reads the stream. There could be some sort of
> > option to have it buffer and log. My idea was to buffer a bit so that
> > we had something to log without paying the cost of a full buffer.
> >
> >
> > On Fri, Dec 4, 2009 at 10:47 AM, Nathaniel Auvil
> >
> > <[email protected]> wrote:
> > > Is there a way to have the log interceptors show the request/response
> > > for the WSDL?
> > >
> > > On Fri, Dec 4, 2009 at 10:22 AM, Daniel Kulp <[email protected]> wrote:
> > >> On Fri December 4 2009 10:13:52 am Benson Margulies wrote:
> > >> > Dan, I still wonder what is hitting him to begin with. I have an
> > >> > idea: capture the first 256 bytes of the returned WSDL and include
> > >> > it in the error. I'm musing about how to make the unit test for
> > >> > this.
> > >>
> > >> It's probably the "Cannot find operation...." soap fault that would
> > >> normally
> > >> be generated when you do a get on the service address.
> > >>
> > >> Dan
> > >>
> > >> > On Fri, Dec 4, 2009 at 9:31 AM, Daniel Kulp <[email protected]> wrote:
> > >> > > On Fri December 4 2009 8:43:25 am Nathaniel Auvil wrote:
> > >> > >> ah...when i added a ?wsdl to the URL it worked.  Why does CXF
> > >> > >> need
> >
> > to
> >
> > >> > >> parse the WSDL at runtime?  I have already generated my code.
> > >> > >
> > >> > > That's pretty much what the JAX-WS spec requires.   There are
> > >> > > things in
> > >> > > the WSDL that are not completely represented in code.   The actual
> > >> > > endpoint address is one of them.   Things like policies are
> > >> > > another.
> > >> > >
> > >> > > In MOST cases, you can pass null for the wsdl location and then do
> > >> > > a service.createPort(...) call to create a port with your service
> > >> > > URL and
> > >> > > it will work fine.    For straight soap calls with nothing fancy,
> >
> > the
> >
> > >> > > generated code may be enough in that case.
> > >> > >
> > >> > > Dan
> > >> > >
> > >> > >> On Fri, Dec 4, 2009 at 8:38 AM, Benson Margulies
> > >> > >
> > >> > > <[email protected]>wrote:
> > >> > >> > CXF is trying to dynamically take the WSDL from your service,
> > >> > >> > and something is coming back (perhaps an error page) that is
> > >> > >> > not much like
> > >> > >> > a WSDL. If you manually grab the ?wsdl URL what do you see?
> > >> > >> >
> > >> > >> > On Fri, Dec 4, 2009 at 8:09 AM, Nathaniel Auvil
> > >> > >> >
> > >> > >> > <[email protected]> wrote:
> > >> > >> > > Hi all.  I am using Maven to generate a SOAP client from
> > >> > >> > > WSDL.
> >
> > I
> >
> > >> > >> > > followed the web site example and some other examples i found
> >
> > on
> >
> > >> > >> > > the
> > >> > >> > > net and my classes seemed to generate fine. As a side note i
> > >> > >> > > am using java version "1.6.0_16"
> > >> > >> > >
> > >> > >> > >        <plugin>
> > >> > >> > >                <groupId>org.apache.cxf</groupId>
> > >> > >> > >                <artifactId>cxf-codegen-plugin</artifactId>
> > >> > >> > >                <version>${cxf.version}</version>
> > >> > >> > >                <executions>
> > >> > >> > >                    <execution>
> > >> > >> > >                        <id>generate-sources</id>
> > >> > >> > >                        <phase>generate-sources</phase>
> > >> > >> > >                        <configuration>
> > >> > >> > >                            <client>true</client>
> >
> > <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
> >
> > >> > >> > >                            <wsdlOptions>
> > >> > >> > >                                <wsdlOption>
> > >> > >> > >
> > >> > >> > > <wsdl>${basedir}/src/main/wsdl/oasApi.wsdl</wsdl>
> > >> > >> > >                                    <extraargs>
> > >> > >> > >
> > >> > >> > >                                       
> > >> > >> > > <extraarg>-p</extraarg>
> > >> > >> > >
> > >> > >> > > <extraarg>com.xxx.soap</extraarg> </extraargs>
> > >> > >> > >
> > >> > >> > >                                </wsdlOption>
> > >> > >> > >
> > >> > >> > >                            </wsdlOptions>
> > >> > >> > >                        </configuration>
> > >> > >> > >                        <goals>
> > >> > >> > >                            <goal>wsdl2java</goal>
> > >> > >> > >                        </goals>
> > >> > >> > >                    </execution>
> > >> > >> > >                </executions>
> > >> > >> > >            </plugin>
> > >> > >> > >
> > >> > >> > >
> > >> > >> > >
> > >> > >> > > However, when i create a new xxxService Object as in...
> > >> > >> > >
> > >> > >> > > OaxApiService service = new OaxApiService( url,
> > >> > >> > > OaxApiService.SERVICE );
> > >> > >> > >
> > >> > >> > >
> > >> > >> > > i am getting the following exception....
> > >> > >> > >
> > >> > >> > >
> > >> > >> > >
> > >> > >> > > org.apache.cxf.service.factory.ServiceConstructionException:
> > >> > >> > > Failed
> > >> > >> > > to create service.
> > >> > >> > >    at
> >
> > org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.jav
> >
> > >> > >> >a:9 3)
> > >> > >> >
> > >> > >> > >    at
> >
> > org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:20
> >
> > >> > >> > >5) at
> > >> > >> > > org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
> > >> > >> > > at
> >
> > org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderIm
> >
> > >> > >> >pl. java:65)
> > >> > >> >
> > >> > >> > >    at javax.xml.ws.Service.<init>(Service.java:56)
> > >> > >> > >    at
> > >> > >> > > com.xxx.soap.OaxApiService.<init>(OaxApiService.java:48) at
> > >> > >> > > com.xxx.OaxClient.invoke(OaxClient.java:97)
> > >> > >> > >    at com.xxx.oas.OaxClient.main(OaxClient.java:32)
> > >> > >> > > Caused by: javax.wsdl.WSDLException: WSDLException:
> > >> > >> >
> > >> > >> > faultCode=PARSER_ERROR:
> > >> > >> > > com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected
> > >> > >> > > character
> > >> > >> > > 't'
> > >> > >> >
> > >> > >> > (code
> > >> > >> >
> > >> > >> > > 116) excepted space, or '>' or "/>"
> > >> > >> > >  at [row,col,system-id]:
> > >> > >> > > [2,41,"https://server.xxx.com/oasapi/OaxApi";] at
> >
> > org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.j
> >
> > >> > >> >ava
> > >> > >> >
> > >> > >> >:226)
> > >> > >> >:
> > >> > >> > >    at
> >
> > org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.ja
> >
> > >> > >> >va: 179)
> > >> > >> >
> > >> > >> > >    at
> >
> > org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.jav
> >
> > >> > >> >a:9 1)
> > >> > >> >
> > >> > >> > >    ... 7 more
> > >> > >> > > Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException:
> > >> > >> > > Unexpected
> > >> > >> > > character 't' (code 116) excepted space, or '>' or "/>"
> > >> > >> > >  at [row,col,system-id]:
> > >> > >> > > [2,41,"https://server.xxx.com/oasapi/OaxApi";] at
> >
> > com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java
> >
> > >> > >> > >:64 8) at
> >
> > com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java
> >
> > >> > >> >:29 65)
> > >> > >> >:
> > >> > >> > >    at
> >
> > com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.ja
> >
> > >> > >> >va: 2936)
> > >> > >> >
> > >> > >> > >    at
> >
> > com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:
> > >> > >> >284 8)
> > >> > >> >
> > >> > >> > >    at
> >
> > com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019)
> >
> > >> > >> > > at
> >
> > org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:90
> >
> > >> > >> > >8) at
> >
> > org.apache.cxf.staxutils.StaxUtils.startElement(StaxUtils.java:826)
> >
> > >> > >> > > at
> >
> > org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:86
> >
> > >> > >> > >8) at
> >
> > org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:755)
> >
> > >> > >> > > at
> >
> > org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.j
> >
> > >> > >> >ava
> > >> > >> >
> > >> > >> >:217)
> > >> > >> >:
> > >> > >> > >    ... 9 more
> > >> > >
> > >> > > --
> > >> > > Daniel Kulp
> > >> > > [email protected]
> > >> > > http://www.dankulp.com/blog
> > >>
> > >> --
> > >> Daniel Kulp
> > >> [email protected]
> > >> http://www.dankulp.com/blog
> 

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to