Skip to main content

Adding an interceptor to WebService

No replies
Joined: 2010-07-11

Hi Folks,

I'm trying to add an interceptor to a WebService class so that SOAP calls are intercepted. I have it working but not the way I need it to work: it will work using a URL that it generates itself, but not using the url that I specify in web.xml


@WebService(name="WSNew", targetNamespace="", serviceName="WSNewService", portName="WSNewPort")
public class WSNew implements WebServiceContextProvider

private WebServiceContext context;

public String getMe()
return "me";

public WebServiceContext getWsContext()
return context;

important bits of web.xml:
<?xml version="1.0" encoding="UTF-8"?>



* I only added the @Stateless to get the @Interceptors annotation to be recognised, I don't intend to use this class as an EJB
* same behaviour if serviceName, portName not specified in @WebService

The app is deployed as a .war file. When I access the endpoint via http://localhost:8080/WSNewService/WSNew then it all works splendidly. But my web.xml should make it use http://localhost:8080/ws/new, and that's not working. It fails with this in the logs:

[#|2013-01-04T15:49:31.491+1100|INFO|glassfish3.1.2||_ThreadID=58;_ThreadName=Thread-4;|PWC1412: WebModule[null] ServletContext.log():PWC1409: Marking servlet WSNew as unavailable|#]

[#|2013-01-04T15:49:31.492+1100|WARNING|glassfish3.1.2||_ThreadID=58;_ThreadName=Thread-4;|StandardWrapperValve[WSNew]: PWC1382: Allocate exception for servlet WSNew
java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
at com.sun.enterprise.web.WebContainer.createServletInstance(
at com.sun.enterprise.web.WebModule.createServletInstance(
at org.apache.catalina.core.StandardWrapper.loadServlet(
at org.apache.catalina.core.StandardWrapper.allocate(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardPipeline.doInvoke(
at org.apache.catalina.core.StandardPipeline.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.doService(
at org.apache.catalina.connector.CoyoteAdapter.service(
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(
at com.sun.grizzly.http.ProcessorTask.doProcess(
at com.sun.grizzly.http.ProcessorTask.process(
at com.sun.grizzly.http.DefaultProtocolFilter.execute(
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(
at com.sun.grizzly.DefaultProtocolChain.execute(
at com.sun.grizzly.DefaultProtocolChain.execute(
at com.sun.grizzly.http.HttpProtocolChain.execute(
at com.sun.grizzly.ProtocolChainContextTask.doCall(
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(
at com.sun.grizzly.util.AbstractThreadPool$

I've tried replacing the servlet-class with (something I saw on the internet somewhere), and that makes the exception go away, but the wsdl at that location is empty.

Is anyone able to tell me if this is likely to be a bug? Is there anything else I can try?


-- David