A bit of newbie on Webservices, but here's a tricky one I'm struggling with finding a better way to implement. See code below: instead of having to invoke the setClientIPAddress
method on each webservice method, is there a way of doing this just once ? 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.
@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
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. Any suggestions on how to better this code?
Thanks in advance.
Try:
@PostContruct
@javax.jws.WebMethod(exclude=true)
public void init()
{
wsBean.setClientIPAddress(getClientIPAdd);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.