Getting the endpoint for a CXF client for ws-security

I am writing a CXF client. Now I need to integrate security. I have these classes created from wsdl2java: MyService , MyServiceProxy , MyServiceHttpBindingStub , MyServiceHttpService and MyServiceHttpServiceLocator .

So far, I have used the MyServiceProxy class for service requests. Following the tutorial, I have to somehow get an Endpoint so that I can do this:

 endpoint.getOutInterceptors().add(wssOut); 

The guide explains using the ClientProxy helper class as follows:

 Client client = ClientProxy.getClient(port); Endpoint endpoint = client.getEndpoint(); 

But how to create port from my classes? When I do this:

 MyService port = (new MyServiceHttpServiceLocator()).getMyServiceHttpPort(); 

and put this port in the ClientProxy method, I get a runtime error:

  java.lang.IllegalArgumentException: not a proxy instance 

So, how can I get the port so that I can pass it to ClientProxy.getClient() ?

+4
source share
2 answers

Have you tried creating an instance of the service and then extracting the port from this instance? Here's an example of how to get the port differently in the Apache CXF link below, in the "Logging - for Client-Side Logging" section. Please note that the steps may vary depending on the version of CXF you are using. Another recommendation is to use a configuration file, if possible in your case. See Security Examples in the samples directory. Debugging and Logging

  MyService ws = new MyService(); MyPortType port = ws.getPort(); Client client = ClientProxy.getClient(port); 
+1
source

Obtaining a SOAP port (without translation):

 MyService service= new MyService(SERVICE_URL, SERVICE_NAME); Operation port = service.getMyServiceSOAP12Port(); Client client = ClientProxy.getClient(port); Endpoint cxfEndpoint = client.getEndpoint(); 
+1
source

Source: https://habr.com/ru/post/1390621/


All Articles