title: CXF WS-Policy configuration
body: <p>I have the following CXF configuration class:</p>
  
  <pre><code>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;
      }
  
  }
  </code></pre>
  
  <p>which configures the CXF Bus and publishes an endpoint. I want to configure WS Policy for that endpoint. The policy is defined in an external file. How to achieve this using a XML configuration file is explained here:</p>
  
  <p><a href="http://cxf.apache.org/docs/how-to-define-policies.html" rel="nofollow">CXF dokumentation</a></p>
  
  <p>This is an example from the CXF site:</p>
  
  <pre><code>&lt;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"&gt;
      &lt;jaxws:endpoint id="CRMService"
              xmlns:serviceNamespace="http://services.talend.org/CRMService"
              serviceName="serviceNamespace:CRMServiceProvider"
              endpointName="serviceNamespace:CRMServicePort"
              implementor="#CRMServiceBean"
              address="/CRMServiceProvider"&gt;
              &lt;jaxws:features&gt;
                  &lt;p:policies&gt;
                      &lt;wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" URI="classpath:/saml.policy"/&gt;
                  &lt;/p:policies&gt;
              &lt;/jaxws:features&gt;
      &lt;/jaxws:endpoint&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>The question is, how can I do the same thing programmatically using the API?</p>