[英]JAX-WS Webservice Class initialisation block in a
A bit of newbie on Webservices, but here's a tricky one I'm struggling with finding a better way to implement. Web服务方面有一些新手,但是我正在努力寻找一种更好的实现方法,这是一个棘手的难题。 See code below: instead of having to invoke the
setClientIPAddress
method on each webservice method, is there a way of doing this just once ? 请参见下面的代码:不必在每个webservice方法上调用
setClientIPAddress
方法,有没有一种方法可以只执行一次? ie I tried the following: 即我尝试了以下方法:
// initialisation block
{
WSBean wsBean = new WSBean();
wsBean.setClientIPAddress(getClientIPAdd);
}
this compiles ok but I get a runtime error. 这样可以编译,但是出现运行时错误。 Webservice class doesn't seem to like the initialisation block.
Webservice类似乎不喜欢初始化块。
@javax.jws.WebService(targetNamespace = "http://baseentity.com/", serviceName = "WSBeanService", portName = "WSBeanPort", wsdlLocation = "WEB-INF/wsdl/WSBeanService.wsdl")
public class WSBeanDelegate {
WSBean wsBean = new WSBean();
public String getBaseInfoList(String baseID) {
wsBean.setClientIPAddress(getClientIPAdd); //
return wsBean.getBaseInfoList(transactionID);
}
public String getBaseEntityInfo(String entityID) {
wsBean.setClientIPAddress(getClientIPAdd);
return wsBean.getBaseEntityInfo(entityID);
}
@WebMethod
private String getClientIPAdd()
{
MessageContext mc = this.wsContext.getMessageContext();
HttpServletRequest req = (HttpServletRequest)mc.get("javax.xml.ws.servlet.request");
return req.getRemoteAddr();
}
I've tried using @PostContruct, as shown below: 我尝试使用@PostContruct,如下所示:
@PostContruct
private void init()
{
wsBean.setClientIPAddress(getClientIPAdd);
}
but i get the following error: "illegalaccessexception with modifiers private". 但我收到以下错误:“带有私有修饰符的非法访问”。
However, declaring the method as public also requires defining the same method in the bean/wsdl file, which is not i want do do. 但是,将方法声明为公共方法还需要在bean / wsdl文件中定义相同的方法,这不是我想要做的。 Any suggestions on how to better this code?
关于如何改进此代码的任何建议?
Thanks in advance. 提前致谢。
Try: 尝试:
@PostContruct
@javax.jws.WebMethod(exclude=true)
public void init()
{
wsBean.setClientIPAddress(getClientIPAdd);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.