2016-08-16 12 views
0

I以下のCXF設定クラスがあります。CXFのWS-Policyの設定

package de.wps.ztr.config; 

import org.apache.cxf.Bus; 
import org.apache.cxf.bus.spring.SpringBus; 
import org.apache.cxf.jaxws.EndpointImpl; 
import org.apache.cxf.ws.policy.attachment.external.PolicyAttachment; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.Profile; 

import javax.xml.ws.Endpoint; 

@Configuration 
public class CxfConfig { 

    @Bean(name = Bus.DEFAULT_BUS_ID) 
    public SpringBus springBus() { 
     final SpringBus springBus = new SpringBus(); 
     return springBus; 
    } 

    @Bean 
    public MyService myService() { 
     return new MyService(); 
    } 

    @Bean 
    public Endpoint myServiceEndpoint() { 
     final EndpointImpl endpoint = new EndpointImpl(springBus(), MyService()); 

     endpoint.publish("..."); 

     return endpoint; 
    } 

} 

CXFバスを構成し、エンドポイントを発行しています。私は、そのエンドポイントのWSポリシーを設定したいと思います。ポリシーは外部ファイルで定義されています。ここで説明されたXML設定ファイルを使用してこれを実現する方法:

CXF dokumentation

これはCXFのサイトからの例です:

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xmlns:cxf="http://cxf.apache.org/core" 
     xmlns:p="http://cxf.apache.org/policy" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd 
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"> 
    <jaxws:endpoint id="CRMService" 
      xmlns:serviceNamespace="http://services.talend.org/CRMService" 
      serviceName="serviceNamespace:CRMServiceProvider" 
      endpointName="serviceNamespace:CRMServicePort" 
      implementor="#CRMServiceBean" 
      address="/CRMServiceProvider"> 
      <jaxws:features> 
       <p:policies> 
        <wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="classpath:/saml.policy"/> 
       </p:policies> 
      </jaxws:features> 
    </jaxws:endpoint> 
</beans> 
質問です

、私はプログラム的に同じことを行うことができますどのようにAPIを使用していますか?

答えて

0

外部からポリシーを取得し、現在のメッセージ用に構築します。

Neethiライブラリを使用してWS-Policy XMLを解析します。 結果ポリシーオブジェクトをPolicyConstants.POLICY_OVERRIDEメッセージコンテンツプロパティに格納します。

このカスタムポリシーインターセプタは、CXF PolicyInInterceptorまたはPolicyOutInterceptorの前に呼び出されることが重要です。 CXFは自動的にこのプロパティに格納されたポリシーを認識し、最も優先度の高いポリシーを使用します。

http://cxf.apache.org/using-ws-policy-in-cxf-projects

あなたは、いくつかのコード例を見つけることができます:SEIまたは実装クラスで http://www.programcreek.com/java-api-examples/index.php?source_dir=tesb-rt-se-master/policies/validation-policy/src/test/java/org/talend/esb/policy/schemavalidate/tests/policy/AbstractPolicyTest.java

0

使用@Policiesまたは@Policy注釈。 アノテーションにポリシーのURIを指定します。 参照http://cxf.apache.org/docs/annotations.html

import org.apache.cxf.annotations.Policies; 
import org.apache.cxf.annotations.Policy; 
     @WebService 
     /* 
     * Attaching Endpoint level Policy 
     */ 
     @Policy(uri = "policy.xml") 
     public interface HelloWorld { 

      /** 
      * Accepts username and greets with message 
      * @param username 
      * @return message 
      */ 
      /* 
      * Attaching Policy using annotation for sending encrypted & signed body 
      */ 
      @Policies({ 
       @Policy(uri = "methodPolicy.xml") 
      }) 
      String sayHi(String username); 

    } 
関連する問題