2014-07-02 33 views
8

cxf + wss4j'yi maven kullanarak kullanmaya çalışıyor. Herhangi bir derleme sorunu olmadan hem hizmeti hem de müşteriyi oluşturdu. Servis tomcat iyi çalışır.
Sayı: İstemci kodu çalıştırdığınızda, ben olsun "java.lang.NoSuchMethodError: org.apache.xml.security.utils.I18n.init (Ljava/util/ResourceBundle;) V". Bu sınıf, cxf dağılımı ile birlikte gelen xmlsec kavanozundadır. hizmet projesi içincxf + wss4j + maven NoSuchMethod hatası

pom.xml: kullanıcı adı belirteci denemek WSS4J kullanarak, istemci kodu: İstemci projesinde

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

Düzenleme için

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

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

istemci WSS4J yapılandırma:

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

hizmet WSS4J yapılandırma:

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

cevap

8

CXF 3.0.0 WSS4J 1.6.15 ile çalışmaz. Bunun yerine WSS4J 2.0.0 kullanmanız gerekir.

Colm.

+0

maven olmadan denendi - cxf'ye geri taşındı 2.7.7. İstemciden kaldırıldı xmlsec.jar ve sunucuda xmlsec.jar 1.3.0 kullanılır. Hem istemcide hem de serviste wss4j 1.6.15, şimdi çalışıyor. –

+2

WSS4J 2.x, maven'de bir kavanoz artefaktı gibi görünmemektedir. Bir zip dosyası var, ancak normal gradle/pom türünü kullanmak, kaynağı almak ve kodu yerel olarak oluşturmak için şu anda işe yaramıyor gibi görünüyor. WSS4J 2.x kavanozları dünyada başka bir yere mi ev sahipliği yapıyor? – Christian

+0

Ayrıca W44S4J 2.x kavanozları ile ilgileniyorum ... Herkes? –

4

Bende aynı sorun vardı. Bu WSS4J ilgili daha fazla ayrıntı için 2.0.0 göçü "WSS4J-ws-güvenlik-ortak-2.0.3.jar"

bağımlılığı kullanılarak çözülmesi, pl "http://ws.apache.org/wss4j/migration/wss4j20.html"

+0

Bu bağımlılığı bir IntelliJ projesine eklemek nasıl olurdu? –

+0

https://mvnrepository.com/artifact/org.apache.wss4j/wss4j/2.1.7 – Nacho

+0

Teşekkür ederiz. 'org.apache.wss4j.common.ext.WSPasswordCallback pc = (org.apache.wss4j.common.ext.WSPasswordCallback) geri çağrılarını kullanarak çözdük [0]; pc.setPassword (parola); ' Bazı bağımlılık nedeniyle wss4j-1.6.19.jar dosyasını kullanmak zorunda. Yukarıdaki sınıf, wss4j-ws-security-common-2.1.5.jar dosyasından – Vins

0

aksi takdirde bir hata var, sen pom türü olarak ekleyin emin olun.

<repositories> 
     <repository> 
      <id>central</id> 
      <url>http://central.maven.org/maven2/</url> 
      <releases> 
       <enabled>true</enabled> 
      </releases> 
     </repository> 
    </repositories> 

sne bunu: o kesin bulabilmesi Bu

<dependency> 
     <groupId>org.apache.wss4j</groupId> 
     <artifactId>wss4j</artifactId> 
     <version>2.1.7</version> 
     <type>pom</type> 
    </dependency> 

Ayrıca maven merkez depo belirtmek için emin olun sizin pom içinde bağımlılık olmak büyük önem taşımaktadır.