views:

36

answers:

1

I am using JBoss 4.0 for creating a simple Web Service using the @WebService annotation as described in http://www.jtraining.com/blogs/java-web-services-getting-started.html. However, when I hit the service as if it is a servlet (as per the instructions in this article), I am getting a ClassCastException stating that my annotated webservice class cannot be cast to javax.servlet.Servlet.

Where am I going wrong?

The classes are given below:

//SimpleServiceWS.java    
import javax.jws.WebService;

@WebService()
public interface SimpleServiceWS {
    public String simpleMethod();
}

//SimpleServiceImpl.java
import javax.jws.WebService;

@WebService( serviceName="SimpleService", portName="SimpleServicePort", endpointInterface="edu.shyam.ws.SimpleServiceWS")
public class SimpleServiceImpl implements SimpleServiceWS {

    public String simpleMethod() {
        return "Simple response";
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
    <display-name>Service</display-name>
    <welcome-file-list>
        <welcome-file>/SimpleServiceWS</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>SimpleServiceWS</servlet-name>
        <servlet-class>edu.shyam.ws.SimpleServiceWS</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SimpleServiceWS</servlet-name>
        <url-pattern>/SimpleService</url-pattern>
    </servlet-mapping>
</web-app>

The stacktrace is as follows:

java.lang.ClassCastException: SimpleServiceImpl cannot be cast to javax.servlet.Servlet
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:130)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Unknown Source)
+1  A: 

It looks like JBoss 4.0 is not enough to run web services you way you are trying to run them. Out of the box, JBoss 4.0.5 (latest 4.0 version) has an old implementation of JBossWS. You need newer version of JBossWS that will work with annotations on JDK 1.5 and above.

Note: Both, interface and the class work in Jboss 5.1.0 and in 4.2.3. It might be easier for you to just get another version of JBoss AS.

Georgy Bolyuba
Thanks Georgy! In fact even before I saw your comment, I upgraded to JBoss 5.0. Thanks again for your kind support!
Shyam