Java 从servlet调用web服务会导致ClassCastException

Java 从servlet调用web服务会导致ClassCastException,java,servlets,jboss,jax-ws,Java,Servlets,Jboss,Jax Ws,我已经创建了JBoss登录模块,它工作得非常好。样本如下: public class UserLoginModule extends UsernamePasswordLoginModule { private static UserService userService; @Override public void initialize(Subject subject, CallbackHandler callbackHandler,

我已经创建了JBoss登录模块,它工作得非常好。样本如下:

public class UserLoginModule extends UsernamePasswordLoginModule {
   private static UserService userService;

   @Override
   public void initialize(Subject subject, CallbackHandler callbackHandler,
                      Map<String, ?> sharedState, Map<String, ?> options) {
   super.initialize(subject, callbackHandler, sharedState, options);
   String wsdlUrl = (String) options.get("wsdlURL");
   UserService.initialize(wsdlUrl);
   userService = new UserService();
}

@Override
protected boolean validatePassword(String inputPassword, 
                                  String expectedPassword) {
    boolean result = false;

    try {
       String response =
       userService.getUserPort().checkOperator(getUsername(), inputPassword);

       if(RESULT_OK.equals(response)) {
          result = true;
       } else {
             result = false;
       }
    } catch(Exception e) {
        log.error("Error when invoking UserService!", e);
    }
        return result;
   }
}
我正在使用JBoss 5.1 EAP。
有没有办法解决这个问题?我的WEB应用程序的WEB-INF目录(包含servlet的目录)为空-没有JAR。

您可以尝试设置系统属性

javax.xml.bind.JAXBContext=com.sun.xml.internal.bind.v2.ContextFactor


这将获取jre提供的默认contextfactory

WEB-INF/lib为空。只有来自JBoss的标准JAR。它在直接从登录模块调用web服务时起作用。从servlet调用时出现了一个问题…表面上看,您可能有两个(或更多)不同的类加载器加载了
com.sun.xml.bind.v2.runtime.JAXBContextImpl
和/或
com.sun.xml.internal.bind.api.JAXBRIContext
。从stacktrace(SOAPFaultBuilder创建)中可以看到,只有在另一端(web服务实现)出现异常时,才会出现问题。当服务没有抛出任何异常时,调用该服务的一侧也没有异常,并且一切正常。。。
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
    com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(SOAPFaultBuilder.java:533)
    com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:107)
    com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
    $Proxy173.unblockOperator(Unknown Source)
    pl.servlet.UserServlet.doPost(UserServlet.java:93)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
public class UserServlet extends HttpServlet {
    private static Logger logger = Logger.getLogger(UserServlet.class.getName());
    private static UserService userService;

    @Override
    public void init() throws ServletException {
        super.init();
        userService = new UserService();
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
    throws  ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
    throws ServletException, IOException {
        String result = null;
        String login = req.getParameter("login");
        result = userService.getUserPort().unblockOperator(login);
    }
}