【问题标题】:CXF ClientProxy getClient "not a proxy instance"CXF ClientProxy getClient“不是代理实例”
【发布时间】:2012-05-10 23:01:42
【问题描述】:

我正在尝试将 WS-security 与我的 Apache CXF 客户端一起使用。我需要获取客户端端点,以便添加 WSS4J 拦截器。但是,当我致电 ClientProxy.getClient() 时,我会收到带有以下消息的 IllegalArgumentException

不是代理实例

代码:

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)

【问题讨论】:

    标签: java cxf wsdl2java


    【解决方案1】:

    原来我使用了错误的代码生成工具。我使用的是 org.codehaus.mojo axistools-maven-plugin,它为您提供了扩展 java.rmi.Remote 的服务。但是,我需要使用 org.apache.cxf cxf-codegen-plugin,它为您提供了一个实现 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>
    

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多