我无法将参数从应用程序传递给处理程序。 在EJB中,我调用我的webservice:
MyNameWSService service = new MyNameWSService(URL); //MyNameWSService = class with annotation @WebServiceClient
((BindingProvider)service.getMyNameWSPort()).getRequestContext().put("login", login);
HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
service.setHandlerResolver(handlerResolver);
service.getMyNameWSPort().callMyMethod();
在HeaderHandlerResolver中我尝试读取我的参数“login”,但它是null:
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {
public boolean handleMessage(SOAPMessageContext smc) {
...
System.out.println(smc.get("login")); //it's null, why?
}
...
}
我创建了HeaderHandlerResolver,以便将SOAP-Security Header添加到soap请求,并且登录/密码可能不同。
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.PortInfo;
public class HeaderHandlerResolver implements HandlerResolver {
public List<Handler> getHandlerChain(PortInfo portInfo) {
List<Handler> handlerChain = new ArrayList<Handler>();
HeaderHandler hh = new HeaderHandler();
handlerChain.add(hh);
return handlerChain;
}
}
答案 0 :(得分:1)
好的,谢天谢地,我重写了我的代码,它开始工作了:
MyNameWSService service = new MyNameWSService(URL); //MyNameWSService = class with annotation @WebServiceClient
MyNameWSPort servicePort = service.getMyNameWSPort()
((BindingProvider)servicePort).getRequestContext().put("login", login);
HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
service.setHandlerResolver(handlerResolver);
servicePort.callMyMethod();
答案 1 :(得分:0)
这不适合您,因为每次拨打service.getMyNameWSPort()
都会获得新的代理。
你打电话两次:
您用于调用Web服务的第二个代理尚未使用您的login
对象更新其请求上下文。