java - CXF 客户端代理 getClient "not a proxy instance"

标签 java cxf wsdl2java

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

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,它为您提供了一个实现代理的服务。

新代码:

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>

关于java - CXF 客户端代理 getClient "not a proxy instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10543306/

相关文章:

java - 从 Java 应用程序将数据导入 Cassandra 2 的最快方法是什么?

cxf - 使用 Camel cxf “No binding factory… http://schemas.xmlsoap.org/soap/registered”时出错(但在Eclipse中有效)

java - CXF 2.7 给出 common.ToolException : Non unique body parts error

java - 我们可以从 WSDL 生成 java 文件吗

java - 如何模拟类的每个实例

java - Dropwizard 集成测试与 TestResource

java - 使用 Apache CXF wsdl2java 生成具有完整构造函数的类

java - 更改 CXF Web 服务上的响应字符集

intellij-idea - IntelliJ Idea 11-没有菜单可以从WSDL生成Java代码

java - 无法在 super 账本结构中调用链码