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

发布于 2024-09-05 14:08:54 字数 1000 浏览 2 评论 0原文

我现在使用 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,但我可以在任何地方。这个行人问题肯定已经得到解决了吗?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

二货你真萌 2024-09-12 14:08:54

请尝试以下操作:

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

或者,MyWebServices 可能具有其他获取 WSDL 位置 URL 的 getXXX 方法

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

慈悲佛祖 2024-09-12 14:08:54

在 CXF 2.6.1 中工作

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

Working in cxf 2.6.1

Client client = ClientProxy.getClient(port);
client.getRequestContext().put(Message.ENDPOINT_ADDRESS, "http://some-valid-endpoint") ;
像极了他 2024-09-12 14:08:54

这对我有用。

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

customerWebService = service.getCustomerWebServicePort();

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

This worked for me.

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

customerWebService = service.getCustomerWebServicePort();

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文