开发者

ClassCastException in Annotated WebService in JBoss & Java 6

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">
    <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)


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.


I had the same problem with JBoss AS 6.1, I have an application on this server with annotated WebServices and deployed succesfully, but not in a new one; analyzing the problem I realized that my new WAR application had a WEB-INF/lib/ directory with some JAX JARs that JBoss already has, but maybe in some different version, so I removed WEB-INF/lib/, redeployed the WebApplication and everything worked. I think this could be a ClassLoader issue or maybe the JAX version I used to develop my WebService in NetBeans was not compatible with JBoss AS 6.1.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜