我正在使用CXF
自动生成soap webservice类。结果将包含WSDL/XSD
文件中的硬编码URL。
@WebService(...)
@XmlSeeAlso(...)
@SOAPBinding(...)
public interface AutoGeneratedPortType {
@WebResult(...)
@WebMethod(action = "http://localhost:8080/TheService") //that's the problem
public MyRsp service(
@WebParam(...)
MyReq parameters
) throws FaultMessage;
}
因此,我首先必须浏览所有WSDL
文件并用生产的URL
替换本地主机(这对于所有文件都适用于Notepad ++,但仍然可以工作)。
问题:每次我获得WSDL的API都提供更新的文件时,我必须重复这些步骤。
在调用服务方法时,我宁愿以某种方式“覆盖”webmethod动作参数:
AutoGeneratedPortType port = new MyService().geAutoGeneratedPort();
port.service(req);
但这可能吗?我可以动态提供生成的@WebMethod
网址吗?
答案 0 :(得分:0)
如果有人知道更好的解决方案,可以采用以下方法:
Map<String, Object> rc = ((BindingProvider) port).getRequestContext();
rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT);