为CXF自动生成Web服务动态提供WebMethod操作?

时间:2013-11-27 13:50:22

标签: java web-services soap cxf

我正在使用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网址吗?

1 个答案:

答案 0 :(得分:0)

如果有人知道更好的解决方案,可以采用以下方法:

Map<String, Object> rc = ((BindingProvider) port).getRequestContext();
rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT);