Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为CXF自动生成的webservice动态提供WebMethod操作?_Java_Web Services_Soap_Cxf - Fatal编程技术网

Java 为CXF自动生成的webservice动态提供WebMethod操作?

Java 为CXF自动生成的webservice动态提供WebMethod操作?,java,web-services,soap,cxf,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

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

如果有人知道更好的解决方案,这里有一种可能性:

Map<String, Object> rc = ((BindingProvider) port).getRequestContext();
rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT);
Map rc=((BindingProvider)端口).getRequestContext();
put(BindingProvider.ENDPOINT\u ADDRESS\u属性,ENDPOINT);

如果您使用的是cxf-maven-code-gen-plugin
cxf-code-gen-plugin
您可以使用以下配置
classpath指定wsdl位置:wsdl/kp.wsdl
这里我为wsdlLocations配置类路径。这可能有点不相关,但你可以尝试这样的方法。但是我没有看到像您这样配置操作,我已经用maven配置了wsdl位置。请注意,我要求指定enpoint,因为我得到的所有wsdl都包含localhost作为URL!