Wildfly 10.0を使用してJax-ws Webサービスを構築したいが、このWebサービスをステートフルセッション(セッションで読み書き)したい、 これを検索した下記のリンクを参照してください。 https://docs.oracle.com/cd/E14571_01/web.1111/e13734/stateful.htm#WSADV234wildfly 10.0、jax-ws、ステートフルセッション
を私はセッションを使用sayHelloメソッドを呼び出すと残念ながらセッションコードdid'n作業 は、時間が終了して返された(例外:java.lang.NullPointerExceptionがメッセージ:java.lang.NullPointerExceptionが) 。
私は、Eclipse火星、動的なウェブサービス、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メソッドが