Java 用于动态端点的 Apache CXF 客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3018883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache CXF Client for Dynamic Endpoints
提问by andyczerwonka
I'm now using Apache CXF as a web services client for a .NET service to get around NTLM authentication. It works great, but I'm wondering why I can't seem to be able to set the web service target endpoint. CXF seems to want the WSDL at runtime for some strange reason - not sure. It takes the physical endpoint from the WSDL, which works fine in test environments I guess, but at deployment time it's sure to change.
我现在使用 Apache CXF 作为 .NET 服务的 Web 服务客户端来绕过 NTLM 身份验证。它工作得很好,但我想知道为什么我似乎无法设置 Web 服务目标端点。出于某种奇怪的原因,CXF 似乎希望在运行时使用 WSDL - 不确定。它从 WSDL 获取物理端点,我猜它在测试环境中工作正常,但在部署时它肯定会改变。
Here's some code to demonstrate:
下面是一些代码来演示:
MyWebServices service = new MyWebServices ();
MyWebServicesSoap port = service.getMyWebServicesSoap12();
// Turn off chunking so that NTLM can occur
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
port.doSomethingUseful();
Again, there is no place that I can see in the CXF client API that allows me to set the service endpoint. Not that I can see anyway. In this case, the target is http://localhost/integration/webservices/mywebservices.asmx, but I could be anywhere. Surely this pedestrian problem is solved somehow?
同样,在 CXF 客户端 API 中没有任何地方可以让我设置服务端点。反正我看不到。在这种情况下,目标是http://localhost/integration/webservices/mywebservices.asmx,但我可以在任何地方。当然,这个行人问题以某种方式解决了?
采纳答案by Kevin
Try the following:
请尝试以下操作:
MyWebServicesSoap port = service.getMyWebServicesSoap12();
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
Alternatively, MyWebServices
might have other getXXX methods that take a URL for the WSDL location
或者,MyWebServices
可能有其他获取 WSDL 位置 URL 的 getXXX 方法
回答by Shahzad Mughal
Working in cxf 2.6.1
在 cxf 2.6.1 中工作
Client client = ClientProxy.getClient(port);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "http://some-valid-endpoint") ;
回答by Fholisani Mashegana
This worked for me.
这对我有用。
String customerEndPoint = "https://localhost:8080/customerService/v1"
customerWebService = service.getCustomerWebServicePort();
((BindingProvider) customerWebService).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
customerEndPoint);