用于动态端点的Apache CXF客户端

时间:2010-06-10 22:05:02

标签: java web-services cxf client-side

我现在使用Apache CXF作为.NET服务的Web服务客户端来绕过NTLM身份验证。它工作得很好,但我想知道为什么我似乎无法设置Web服务目标端点。 CXF似乎在运行时希望WSDL出于某种奇怪的原因 - 不确定。它需要来自WSDL的物理端点,我认为它在测试环境中工作正常,但在部署时它肯定会改变。

以下是一些要演示的代码:

        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();

同样,我无法在CXF客户端API中看到允许我设置服务端点的地方。不是我能看到的。在这种情况下,目标是http://localhost/integration/webservices/mywebservices.asmx,但我可以在任何地方。当然这个行人问题以某种方式解决了?

3 个答案:

答案 0 :(得分:44)

尝试以下方法:

MyWebServicesSoap port = service.getMyWebServicesSoap12();
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint); 

或者,MyWebServices可能有其他getXXX方法为WSDL位置提供URL

答案 1 :(得分:11)

使用cxf 2.6.1

Client client = ClientProxy.getClient(port);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "http://some-valid-endpoint") ;

答案 2 :(得分:1)

这对我有用。

String customerEndPoint = "https://localhost:8080/customerService/v1"

customerWebService = service.getCustomerWebServicePort();

((BindingProvider) customerWebService).getRequestContext()
                        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                customerEndPoint);

相关问题