我想使用 Wildfly 10.0 构建 Jax-ws Web 服务,我希望此 Web 服务具有有状态 session (在 session 上读写), 我已经搜索过了,我看到了以下链接: https://docs.oracle.com/cd/E14571_01/web.1111/e13734/stateful.htm#WSADV234
不幸的是 session 代码没有工作 当我调用使用 session 的 sayHello 方法时,时间结束并返回(异常:java.lang.NullPointerException 消息:java.lang.NullPointerException)。
我正在使用 Eclipse Mars、动态网络服务、Wildfly 10.0 和网络服务(服务器:使用 Wildfly 10.0,网络服务运行时:Apache Axis,并为此项目使用 ear 文件)
代码是:
package com.sample;
@WebService(targetNamespace = "http://sample.com/", serviceName = "Test1Service", portName = "Test1Port")
@Stateful
public class Test1 {
@Resource
private WebServiceContext wsContext;
@WebMethod
public String sayHello() {
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST))
.getSession();
if (session == null)
throw new WebServiceException("No HTTP Session found");
String item = "";
try {
item = (String) session.getAttribute("name1");
} catch (Exception e) {
e.printStackTrace();
}
if (item == null || item.equals(""))
item = "good";
session.setAttribute("name1", item);
return "Hello " + session.getAttribute("name1");
}
@WebMethod
public int setValue(int x) {
return x;
}
}
请注意 setValue 方法成功运行,但 sayHello 方法无效
最佳答案
谢谢大家
问题:我使用的是 Axis 而不是 Axis2,其中 Axis2 支持 Http session 。
关于java - wildfly 10.0、jax-ws 和有状态 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37346396/