cxf + wss4j + maven NoSuchMethod 错误

2023-11-24

尝试使用maven使用cxf+wss4j。创建服务和客户端,没有任何编译问题。该服务在tomcat中运行良好。
Issue:当我运行客户端代码时,我得到“java.lang.NoSuchMethodError:org.apache.xml.security.utils.I18n.init(Ljava/util/ResourceBundle;)V”。这个类位于 xmlsec jar 中,它随 cxf 发行版一起提供。

服务项目的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>userNameTokenService</groupId>
    <artifactId>userNameTokenService</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.security</groupId>
            <artifactId>wss4j</artifactId>
            <version>1.6.15</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webXml>WebContent\WEB-INF\web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>


客户端项目的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>userNameTokenClient</groupId>
  <artifactId>userNameTokenClient</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
      <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.security</groupId>
            <artifactId>wss4j</artifactId>
            <version>1.6.15</version>
        </dependency>
      <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.6.RELEASE</version>
        </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

编辑: 使用wss4j尝试用户名令牌,客户端代码:

public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        HelloWorld helloworld= (HelloWorld) context.getBean("helloClient");
        HelloRequest hreq = new HelloRequest();
        hreq.setRequestMsg("This is client");
        HelloResponse hres = helloworld.sayHello(hreq);
        System.out.println(hres.getResponseMsg());
    }

客户端 wss4j 配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <bean id="logInBound" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
    <bean id="logOutBound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
    <jaxws:client id="helloClient" serviceClass="com.ddmwsst.helloworld.HelloWorld"
        address="http://localhost:8080/userNameTokenService/services/HelloWorld">
        <jaxws:inInterceptors>
            <ref bean="logInBound" />
        </jaxws:inInterceptors>
        <jaxws:outInterceptors>
            <ref bean="logOutBound" />
            <ref bean="outbound-security" />
        </jaxws:outInterceptors>
    </jaxws:client>

    <!-- WSS4JOutInterceptor for incorporating a UsernameToken in a SOAP -->
    <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"
        id="outbound-security">
        <constructor-arg>
            <map>
                <entry key="action" value="UsernameToken" />
                <entry key="user" value="dummy" />
                <!--entry key="passwordType" value="PasswordText"/ -->
                <entry key="passwordCallbackClass" value="client.ClientPasswordCallback" />
            </map>
        </constructor-arg>
    </bean>
</beans>

服务 wss4j 配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <bean id="logInBound" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
    <bean id="logOutBound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
    <!-- WSS4JInInterceptor for processing a UsernameToken from the SOAP -->
    <bean id="inbound-security" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
        <constructor-arg>
            <map>
                <entry key="action" value="UsernameToken" />
                <!--entry key="passwordType" value="PasswordText"/ -->
                <entry key="passwordCallbackClass" value="server.ServerPasswordCallback" />
            </map>
        </constructor-arg>
    </bean>

    <jaxws:endpoint id="helloWorld" implementor="server.HelloWorldImpl"
        address="/HelloWorld">
        <jaxws:inInterceptors>
            <ref bean="logInBound" />
            <ref bean="inbound-security" />
        </jaxws:inInterceptors>
        <jaxws:outInterceptors>
            <ref bean="logOutBound" />
        </jaxws:outInterceptors>
    </jaxws:endpoint>
</beans>

CXF 3.0.0 不适用于 WSS4J 1.6.15。您需要改用 WSS4J 2.0.0。

Colm.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

cxf + wss4j + maven NoSuchMethod 错误 的相关文章

随机推荐

  • 查找枚举值中设置的最高标志

    我使用带有 flags 属性的枚举作为跟踪状态的方式 示例如下 Created 1 Completed 2 Dispatched 4 在不写任何过于严格的内容的情况下 如果检查这个 则执行那个 如果检查那个 则执行此操作 我希望能够找到已设
  • 使用 C# 以编程方式打开超级按钮栏、电源栏和开始菜单

    如何以编程方式打开 魅力酒吧 电源选项 开始菜单 在 Windows 8 中 我希望能够从我的 C 应用程序中打开它们 找不到我需要的文档 Thanks 我敢打赌发送 Windows 密钥 以及其他密钥 根据需要 就足够了 这是关于如何通过
  • 如何更改默认 LLDB 设置

    有时我需要使用 LLDB 打印长字符串 默认 LLDB 设置会修剪打印的字符串 我必须输入以下内容 set set target max string summary length 10000 下次运行时 此设置不会保留 有没有办法设置它以
  • Tinymce html5占位符通过从textarea读取属性

    对于标准文本区域我使用这个plugin创建一个占位符 我如何扩展tinymce 以便它也以这种方式工作 例如 默认值是从 textarea 属性中读取的 然后在用户聚焦于 iframe 时清除 与 CKEditor 类似 http alfo
  • 传递的数组会丢失除第一个元素之外的所有元素

    我有一个奇怪的问题 我最近将我的应用程序从本地 xampp 安装迁移到 SUSE Enterprise Server 11 一切正常 但这一件事让我发疯 我找不到解决方案 使用以下语法通过 GET 或 POST 传递数组时 search d
  • 单引号字符串字符串插值

    我正在尝试使用 Rails 在 ActionMailer 中设置电子邮件地址 在硬编码之前 但我们现在希望将它们设为 ENV 变量 这样我们就不需要每次电子邮件更改时都修改代码 目前的定义方式如下 from Name of Person l
  • cmake:读取并编译动态生成的 cpp 文件列表

    我有一个自定义工具 可以处理给定的 IDL 文件列表并生成许多 cpp 和 h 文件作为输出 我想将这些文件添加到要在我的 CMakeLists 中编译的内容列表中 并对这些文件对 IDL 的依赖关系进行建模 为了简单起见 我将声明对任何
  • 在 JSP 中启用 JavaServerPages 标准标记库 (JSTL)

    我觉得我错过了一些东西 从表面上看 JSP 开箱即用 支持标签 如这个问题的答案显示 这个人问了一个纯 jsp 问题并得到了涉及标签的答案 但是如果我尝试运行给定的代码
  • 如何在角度材料日期选择器上添加蒙版

    我最近开始使用角度材料来构建角度形式 其中我需要使用角度材料日期选择器 但无法在输入元素上添加任何掩码 我希望用户只能输入数字并在输入时将其格式化为日期格式 MM DD YYYY html div class example contain
  • 从文本文件中删除空行[重复]

    这个问题在这里已经有答案了 我有一个文本文件 其中有一些空行 意思是上面没有任何东西并且只是占用空间的线条 它看起来像这样 The quick brown fox jumped over the lazy dog 我需要它看起来像这样 Th
  • C++ 如何避免浮点运算错误[重复]

    这个问题在这里已经有答案了 我正在编写一个以浮点数递增的循环 但我遇到了以下示例所示的浮点算术问题 for float value 2 0 value lt 2 0 value 0 2 std cout lt lt value lt lt
  • 使用中央数据库在多用户环境中更新实体框架数据

    让我解释一下标题 我在应用程序中使用实体框架代码优先 测试应用程序 出于调试目的TestApp连接到 SQLExpress 数据库 中央数据库服务器 为了简单起见 数据库包含一张表 Products TestApp 在数据网格中显示数据库中
  • 创建文件时出现 System.UnauthorizedAccessException

    我试图编写代码以便记录错误消息 我试图用日期命名该文件 并希望每天创建一个新的日志文件 经过一番查看后 我得到了以下代码 class ErrorLog public void WriteErrorToFile string error ht
  • 为什么在字符指针上使用 strcat 会崩溃? [复制]

    这个问题在这里已经有答案了 为什么这段代码会崩溃 正在使用strcat字符指针非法 include
  • 更新 iframe、历史记录和 URL。然后使其与后退按钮一起使用

    当点击浏览器上的后退按钮时 我在更新 URL 时遇到问题 我正在 Firefox 上进行测试 更新我使用的 iframe 的 src 属性后replaceState更新历史记录 如果我在此之后点击后退按钮 iframe 将返回到上一页 但
  • opencart php自定义页面不使用“信息”功能

    我想在 opencart 中创建一个自定义页面 我知道我可以使用管理区域在信息部分放置一个自定义页面 但是我想要的是一个指向其他几个页面的控制器 我不完全明白如何做到这一点 在 codeigniter 中 您将创建一个控制器和一个视图 如果
  • Python:更改 Windows 7 主音量

    我希望能够在 Python 中控制主音量 不是针对应用程序 而是针对当前活动扬声器 这似乎是一个棘手的话题 我尝试用 C 来做 但我什至无法让它在那里工作 有办法做到这一点吗 Windows 7 x64 请注意 这个问题之前没有得到回答 因
  • Camera2 API 自动对焦与三星 S5

    我正在 Samsung S5 上使用新的 Camera2 API 该设备报告的支持的硬件级别是LEGACY 这很好 但是 我似乎无法自动对焦该设备 触发自动对焦的请求如下所示 previewRequestBuilder set Captur
  • 拒绝使用ajax调用Rest服务器设置不安全标头“Cookie”

    我正忙于构建一个与我的 Drupal Rest 服务器 模块 服务 连接的 Phonegap 应用程序 我的 Drupal 网站 PHP 的代码为 header Access Control Allow Origin 当我尝试使用以下代码连
  • cxf + wss4j + maven NoSuchMethod 错误

    尝试使用maven使用cxf wss4j 创建服务和客户端 没有任何编译问题 该服务在tomcat中运行良好 Issue 当我运行客户端代码时 我得到 java lang NoSuchMethodError org apache xml s