gpt4 book ai didi

java - 从 servlet 调用 Web 服务导致 ClassCastException

转载 作者:行者123 更新时间:2023-11-29 05:57:03 25 4
gpt4 key购买 nike

我已经创建了 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 时,它​​在 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。任何想法如何解决这个问题?我的网络应用程序(包含 servlet 的那个)的 WEB-INF 目录是空的——那里没有 jar 。

最佳答案

你可以尝试设置系统属性

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

这将获取 jre 提供的默认上下文工厂

关于java - 从 servlet 调用 Web 服务导致 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com