开发者

jax-ws on glassfish3 init method

开发者 https://www.devze.com 2022-12-25 16:17 出处:网络
I\'ve createdsimple jax-ws (anotated Java 6 class to web service) service and deploied it on glassfish v3. The web.xml

I've created simple jax-ws (anotated Java 6 class to web service) service and deploied it on glassfish v3. The web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
  <servlet-name>MyServiceName</servlet-name>
  <description>Blablabla</description>
  <servlet-class>com.foo-bar.somepackage.TheService</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>MyServiceName</servlet-name>
  <url-pattern>/MyServiceName</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>

There is no sun-jaxws.xml in the war. The service works fine but I have 2 issues: I'm using apache common configuration package to read my configuration, so i have init function that calls configuration stuff. 1. How can I configure init method for jaxws service (like i can do for the servlets for example) 2. the load on startup parameter i开发者_Go百科s not affecting the service, I see that for every request init function called again (and c-tor). How can I set scope for my service?

Thanks a lot,


How can I configure init method for jaxws service (like i can do for the servlets for example)

JAX-WS endpoints, both web and EJB, can have optional life-cycle methods that are automatically called if present. Any method can be used as a life-cycle method with the correct annotation:

  • @PostConstruct - Called by the container before the implementing class begins responding to web service clients.

  • @PreDestroy - Called by the container before the endpoint is removed from operation

So annotating your init() method with @PostConstruct should do the trick.

the load on startup parameter is not affecting the service, I see that for every request init function called again

Try to use the suggested annotation first. And if you are still facing unexpected behavior, post your code.


Thanks for the quick answer, Pascal.

BTW, I warmly suggest to use a "valid" servlet 2.5 or servlet 3.0 web.xml (using a version attribute in the web-app element and the xsd declaration).

I'm using 2.5 version, I just didn't paste this part in my post

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:j2ee="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<description>WebTier for the Login Manager Service</description>
<display-name>LoginManagerWAR</display-name>

<servlet>
    <description>Endpoint for Login Manager Web Service</description>
    <display-name>LoginManagerControllerService</display-name>
    <servlet-name>LoginManagerController</servlet-name>
    <servlet-class>loginmanager.controller.LoginManagerController</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>LoginManagerController</servlet-name>
    <url-pattern>/LoginManagerControllerService</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>54</session-timeout>
</session-config>

The PostConstruct works fine , thank you, but load-on-startup still didn't happen.

@WebService(
name="LoginManagerController",
serviceName="LoginManagerControllerService"
)

public class LoginManagerController {   
private ILoginManager manager;

@Resource
private WebServiceContext wsContext;

@PostConstruct
private void init(){
     .....
    }

More over, now every client request makes 2 init() calls of the webservice: like I can see in chainsaw, first called init() of the service, then it called again and then the actually client's function (I print the hash code of the webservice class instance and it the same instance for both calls!!!):

> Message Inside init() method ... controller=31641446

> Message login manager = 11229828

> .....init of elements....blablabla.....

> Message Exiting init() method

> Message Inside init() method ... controller=31641446

> Message login manager = 32361523

The controller is the service and the manager (wich hash code has been changed from first call to the second) created inside the init () of the controller.

I failed to understand what is wrong ....

UPDATE It seems like a to glassfish v3 related issue (maybe my env setup or glassfish configuration). I tried this war on Sailfin and Glassfish V2 and its perfectly working ....

0

精彩评论

暂无评论...
验证码 换一张
取 消