我已经创建了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方法时,一切都很好。
现在,当我尝试从servlet中调用UserService时,该servlet位于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)
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应用程序的WEB-INF目录(包含servlet的目录)是空的 - 没有罐子。
答案 0 :(得分:3)
您可以尝试设置系统属性
<强> javax.xml.bind.JAXBContext = com.sun.xml.internal.bind.v2.ContextFactor 强>
这将获取jre
提供的默认contextfactory