CXF ClientProxy getClient“不是代理实例” [英] CXF ClientProxy getClient "not a proxy instance"

查看:439
本文介绍了CXF ClientProxy getClient“不是代理实例”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将WS-security与我的Apache CXF客户端一起使用。我需要保留客户端端点,以便可以添加WSS4J拦截器。但是,当我调用 ClientProxy.getClient()时,会收到 IllegalArgumentException 并显示以下消息:

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

代码:

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);

跟踪:

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)


推荐答案

原来我是使用错误的代码生成工具。我使用的是org.codehaus.mojo axistools-maven-plugin,它为您提供了扩展java.rmi.Remote的服务。但是,我需要使用org.apache.cxf cxf-codegen-plugin,它可以为您提供实现代理的服务。

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.

新代码:

MailingService_Service mss = new MailingService_Service();
MailingService service = mss.getMailingServicePort();

ClientImpl client = (ClientImpl) ClientProxy.getClient(service);

新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>

这篇关于CXF ClientProxy getClient“不是代理实例”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆