Is it necessary to close JAX-WS port?
In some tutorials (e.g. here, here and here) it is suggested to close the JAX-WS port by casting it to com.sun.xml.ws.Closeable
e.g.
MyPortType port = MyService.getMyPort();
... do some operations on WS proxy ...
((com.sun.xml.ws.Closeable) port).close();
This approach will not work for proxies, returned by JaxWsPortProxyFactoryBean
, as it advices only target WS interface and javax.xml.ws.BindingProvider
.
So my question is: Is it necessary to close the port (taking in mind that it is re-usable in application)? If it is better to close the port (and probably nullify it?), how开发者_高级运维 to organize correctly lifecycle of ports (by implementation the created Spring proxies will always be singletons)?
The JavaDoc for com.sun.xml.ws.Closeable
reads:
This signals the implementation of certain specs (like WS-ReliableMessaging and
WS-SecureConversation) to terminate sessions that they create during the life
time of a proxy object. This is not a mandatory operation, so the application
does not have to call this method.
Also Closing WSIT Reliable Messaging Connections note reads:
Calling close() method provides a way for WSIT components, such as Reliable
Messaging and Secure Conversations to do clean-up activities related to client
instance. Sometimes calling close() can be avoided without harmful effects.
No, I don't believe this is necessary. It is up to the JAX-WS subsystem to manage its own lifecycle, the ports need not be closed.
This is consist with the behaviour of JaxWsPortProxyFactoryBean
, if you look at the source code. It does not attempt to do anything with the Port on context shutdown, which Spring FactoryBeans will generally do.
精彩评论