1

我创建了 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 的 common/lib 目录中。当系统尝试对用户进行身份验证并调用 validatePassword 方法时,一切都很好。

现在,当我尝试从 Web 应用程序(使用自定义登录模块的相同)中的 servlet 调用 UserService 时,会引发异常:

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)

servlet 如下所示:

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);
    }
}

我正在使用 JBoss 5.1 EAP。任何想法如何解决这个问题?我的 Web 应用程序(包含 servlet)的 WEB-INF 目录是空的 - 那里没有 jar。

4

1 回答 1

3

您可以尝试设置系统属性

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

这将获取 jre 提供的默认 contextfactory

于 2012-08-01T04:49:10.007 回答