为ws-security获取CXF客户端的端点 [英] Obtaining Endpoint for a CXF client for ws-security
问题描述
我正在编写CXF客户端。现在,我必须集成安全性。
我有从wsdl2java生成的这些类: MyService
, MyServiceProxy
, MyServiceHttpBindingStub
, MyServiceHttpService
和 MyServiceHttpServiceLocator
。
I'm writing a CXF client. Now I have to integrate security.
I'm having these classes generated from wsdl2java: MyService
, MyServiceProxy
, MyServiceHttpBindingStub
, MyServiceHttpService
and MyServiceHttpServiceLocator
.
直到现在,我一直在使用 MyServiceProxy
类向服务发出请求。按照手册,我必须以某种方式获得端点
,这样我才能做到:
Until now I was using the MyServiceProxy
class for making requests to the service. Following the manual, I must somehow obtain an Endpoint
so I can do this:
endpoint.getOutInterceptors().add(wssOut);
在手册中通过使用 ClientProxy
像这样的帮助器类:
In the manual it's explained by using the ClientProxy
helper class like this:
Client client = ClientProxy.getClient(port);
Endpoint endpoint = client.getEndpoint();
但是如何正确地从中创建端口
我的课程?当我这样做时:
But how to properly create the port
from my classes? When I do:
MyService port = (new MyServiceHttpServiceLocator()).getMyServiceHttpPort();
将该端口放到ClientProxy方法中,出现运行时错误:
and put that port to the ClientProxy method, I get a runtime error:
java.lang.IllegalArgumentException: not a proxy instance
那么,如何获取端口,以便能够将其传递给 ClientProxy.getClient()
?
So, how can I obtain the port so that I'd be able to pass it to ClientProxy.getClient()
?
推荐答案
获取SOAP端口有效(不强制转换):
Getting the SOAP port works (without cast):
MyService service= new MyService(SERVICE_URL, SERVICE_NAME);
Operation port = service.getMyServiceSOAP12Port();
Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
这篇关于为ws-security获取CXF客户端的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!