You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Mike Williams <mi...@mikesbox.com> on 2003/04/23 03:41:41 UTC

Re: how to automatically config a SOAP component when SOAP server starts?

Now why didn't I think of that :(

Good suggestion Rick! :)

Mike


On Tue, 2003-04-22 at 19:35, Rick Rineholt wrote:
> How about in the class that is your service having a static section ?
> Think this would only be called once no matter what the scope is:
> 
> public class myservice { ...
>   static {
>      // ... initialize code here...
> }
> }
> 
> Rick Rineholt
> "The truth is out there...  All you need is a better search engine!"
> 
> rineholt@us.ibm.com
> 
> 
> 
> Please respond to soap-user@ws.apache.org 
> 
> To:        soap-user@ws.apache.org
> cc:         
> Subject:        Re: how to automatically config a SOAP component when
> SOAP server        starts?
> 
> 
> 
> On Mon, 2003-04-21 at 04:37, Steve Cheng wrote:
> > Hello,
> >
> > I'm new to SOAP and I have a simple question.
> >
> > For example, I want to provide a SOAP method "getNumber()", this
> > method is associated with a backend database which I have to
> configure
> > first by calling "initialize()".
> >
> > Different than "getNumber()", "initialize()" would be only called
> once
> > and called automatically when the SOAP server is started, so is
> there
> > anyway I can do that? or should it be called in the construtor or
> > main() of my SOAP component?
> >
> > Thanks in advance.
> >
> > Steve
> 
> Steve,
> 
> Hello yourself :)
> 
> You have a few choices on how to handle this.  You can add it to the
> constructor of your service class and if you deploy your service in
> Application scope it will only be ran once, since only one instance of
> your class will be created.
> 
> If you use any of the other scopes, Session or Request, it will get
> called more than once.  You could handle this case by making your
> initialize method static synchronized and having it set a static
> boolean
> field to signal that it's been ran.  This would work but you would
> have
> to call it either in your getNumber method or in the constructor and
> pay
> the synchronization penalty each time.
> 
> Another solution that I've used before is to create a separate servlet
> that runs in the same context as the soap servlet.  This servlet would
> take care of any initialization that you need to happen.  This can be
> setup by adding something like the following to soaps web.xml.  You
> would of course have to create your new servlet and add it to the
> soap/WEB-INF/classes directory :)
> 
> <servlet>
> <servlet-name>initServlet</servlet-name>
> <servlet-class>com.yourcompany.YourInitServlet</servlet-class>
> <load-on-startup>-1</load-on-startup>
> </servlet>
> 
> 
> Hope this helps,
> Mike
> 
> --
> 
> ---------------------------
> May The Source Be With You!
> http://www.mikesbox.com