Dilan Dilan - 11 days ago 5
Java Question

What are the duties of WSServletContenxtListener and WSServlet

I am studding Web Services written in java. When I go through some articles in the internet I found the above two classes has been used for developing a SOAP Web Service. The article mentioned as

WSServletContenxtListener:

The listener class(com.sun.xml.ws.transport.http.servlet.WSServletContextListener) mentioned above is the web service context listener, which initializes the web service context when the application context is initialized and creates a web service delegate which is used to delegate all future web service requests and route them to appropriate end point implementation defined in the sun-jaxws.xml mentioned below. This stores the created delegate in the container servlet context, so that the delegate can be accessed by other servlets.

WSServlet:

The servlet definition and it’s mapping is used to intercept the url-pattern that should be considered as web service request.

The class(com.sun.xml.ws.transport.http.servlet.WSServlet) acts as a dispatching servlet that routes the request to appropriate implementation class through the delegate received from the servlet context created by the listener as stated above.

But I have a little confusion about the different tasks done by these two classes. According to my knowledge I guess that WSServlet is used to intercept all the incoming requests to the web service but I am having the doubt about the duty of WSServletContenxtListener

Please anybody help me to clarify this clearly...

Answer

WSServletContenxtListener is a class for receiving notification events about web service context listener.

if you take a look at the class documentaion here , you can see the following methods that gets called when a something triggers a notification event about the web service :

attributeAdded, attributeRemoved , attributeReplaced , contextDestroyed , contextInitialized , createContainer , createDelegate .

Hope that Helps .