Reputation: 6271
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)
Upvotes: 3
Views: 12984
Reputation: 6271
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:
MailingService_Service mss = new MailingService_Service();
MailingService service = mss.getMailingServicePort();
ClientImpl client = (ClientImpl) ClientProxy.getClient(service);
New pom:
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/myWsdl.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Upvotes: 1