2016-08-16 1 views
0

나는 다음과 같은 CXF 구성 클래스가 있습니다CXF WS-정책 구성

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을 구문 분석합니다. 결과 Policy 오브젝트를 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); 

    }