You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Stefan Bokor <sb...@vcentrix.net> on 2006/09/24 07:16:44 UTC

How to implement init() for a endpoint service?

Dear Friends,

Problem:

How could I implement a init() function in my service?
What I try to do is to have the container (Tomcat) call
this init() when my service is loaded (or when service
receives the 1st request). This init() function should
basically work as the servlet init() function.
My goal is to use the init() for loading a config file
containing info specific to this service.


Tested:
Note, I'm using the Java2WSDL -> WSDL2Java approach.

It seems that the ServiceLifecycle class could be the way
to go... I have added 'implements ServiceLifecycle' to the
declaration of my service ("XX") impl class, and added the
init() and destroy() methods like this:

-----
public class XXSoapBindingImpl
    implements com.vx.soap.XX, ServiceLifecycle
{
    private static int x = 0;

    public void init(Object ctx) {x++;}
    public void destroy() {}

    public int getX() {return x;}
}
-----

But when I test this service the client always gets 0,
so it seems the init() function in the service is not
called by the container.

I would be thankful for any suggestion, or code snippet.
Thank you,
-stefan


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to implement init() for a endpoint service?

Posted by Michele Mazzucco <Mi...@ncl.ac.uk>.
Stefan,

open services.xml and, after this element

<parameter name="ServiceClass" locked="xsd:false>
	class_name
</parameter>

try to add this line

<parameter name="load-on-startup" locked="false">true</parameter>



Michele

Stefan Bokor wrote:
> Update:
> 
> Ok, getting closer...
> 
> I have realized that I use WSDL2Java with switch -S (deploy
> skeleton), so I have also modified the XXSoapBindingSkeleton
> class. My Skeleton and Impl classes now look like this:
> 
> ----
> public class XXSoapBindingSkeleton
>   implements com.vx.soap.XX,
>              org.apache.axis.wsdl.Skeleton,
>              javax.xml.rpc.server.ServiceLifecycle  // added
> {
>   private com.vx.soap.XX impl;
>   ...
> 
>   // added
>   public void init(Object ctx) throws ServiceException {
>     ((ServiceLifecycle) impl).init(ctx);
>   }
>   public void destroy() {
>     ((ServiceLifecycle) impl).destroy();
>   }
> 
>   ...
> }
> 
> 
> public class XXSoapBindingImpl
>   implements com.vx.soap.XX,
>              ServiceLifecycle  // added
> {
>   String info = "none";
> 
>   // added
>   public void init(Object ctx) throws ServiceException {
>     info = "inited";
>   }
> 
>   public void destroy() {}
> 
>   public String getX() {return info;}
> }
> -----
> 
> On client side I execute getX() two times like this:
> 
> -----
>   clnt = new XXSoapBindingStub(url, null);
>   String ret = clnt.getX();
>   ret += ", " + clnt.getX();
>   ...
> -----
> 
> And the return is "inited, inited" - the init() in the service
> is being called each time the client invokes getX(). I would
> expect init() to be only called the 1st time, e.g.: the return
> should be "inited, empty".
> 
> BTW, I deploy the service with scope "Application".
> 
> Do I miss something? Do I need to configure Tomcat too?
> Thank you,
> -stefan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: How to implement init() for a endpoint service?

Posted by Stefan Bokor <sb...@vcentrix.net>.
Update:

Ok, getting closer...

I have realized that I use WSDL2Java with switch -S (deploy
skeleton), so I have also modified the XXSoapBindingSkeleton
class. My Skeleton and Impl classes now look like this:

----
public class XXSoapBindingSkeleton
   implements com.vx.soap.XX,
              org.apache.axis.wsdl.Skeleton,
              javax.xml.rpc.server.ServiceLifecycle  // added
{
   private com.vx.soap.XX impl;
   ...

   // added
   public void init(Object ctx) throws ServiceException {
     ((ServiceLifecycle) impl).init(ctx);
   }
   public void destroy() {
     ((ServiceLifecycle) impl).destroy();
   }

   ...
}


public class XXSoapBindingImpl
   implements com.vx.soap.XX,
              ServiceLifecycle  // added
{
   String info = "none";

   // added
   public void init(Object ctx) throws ServiceException {
     info = "inited";
   }

   public void destroy() {}

   public String getX() {return info;}
}
-----

On client side I execute getX() two times like this:

-----
   clnt = new XXSoapBindingStub(url, null);
   String ret = clnt.getX();
   ret += ", " + clnt.getX();
   ...
-----

And the return is "inited, inited" - the init() in the service
is being called each time the client invokes getX(). I would
expect init() to be only called the 1st time, e.g.: the return
should be "inited, empty".

BTW, I deploy the service with scope "Application".

Do I miss something? Do I need to configure Tomcat too?
Thank you,
-stefan


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org