I'm attempting to use WS-security with my Apache CXF client. I need to get a hold of the client endpoint so I can add a WSS4J interceptor. However, when I call ClientProxy.getClient()
I get an IllegalArgumentException
with the following message:
not a proxy instance
Code:
MailingService_ServiceLocator serviceLocator = new MailingService_ServiceLocator();
MailingService_PortType port = serviceLocator.getMailingServicePort();
Client client = ClientProxy.getClient(port); // throws exception
...
// Create client interceptor
AuthenticationInterceptor authenticationInterceptor =
new AuthenticationInterceptor(schemaNS, outprops, organizationName, null);
client.getEndpoint().getOutInterceptors().add(authenticationInterceptor);
Trace:
java.lang.IllegalArgumentException: not a proxy instance
at java.lang.reflect.Proxy.getInvocationHandler(Unknown Source)
at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:93)
It turns out I was using the wrong code generation tool. I was using the org.codehaus.mojo axistools-maven-plugin, which gives you a service which extends java.rmi.Remote. However, I needed to use the org.apache.cxf cxf-codegen-plugin, which gives you a service that does implement Proxy.
New code:
New pom: