【问题标题】:wildfly 10.0, jax-ws and stateful sessionWildfly 10.0、jax-ws 和有状态会话
【发布时间】:2016-05-20 12:09:32
【问题描述】:

我想使用 Wildfly 10.0 构建 Jax-ws Web 服务,并且我想要这个具有状态会话的 Web 服务(在会话上读取和写入), 我已经搜索过了,我看到了下面的链接: https://docs.oracle.com/cd/E14571_01/web.1111/e13734/stateful.htm#WSADV234

不幸的是会话代码没有工作 当我调用使用会话的 sayHello 方法时,时间结束并返回(异常:java.lang.NullPointerException 消息:java.lang.NullPointerException)。

我正在使用 Eclipse Mars、动态 Web 服务、Wildfly 10.0 和 Web 服务(服务器:使用 Wildfly 10.0,Web 服务运行时: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 方法没有工作

【问题讨论】:

    标签: java eclipse web-services wildfly-10


    【解决方案1】:

    谢谢大家,

    问题:我使用的是 Axis 而不是 Axis2,其中 Axis2 支持 Http 会话。

    【讨论】:

      猜你喜欢
      • 2013-11-15
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      相关资源
      最近更新 更多