首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CXF WS-Policy配置

CXF WS-Policy配置
EN

Stack Overflow用户
提问于 2016-08-16 23:24:25
回答 2查看 1.3K关注 0票数 0

我有以下CXF配置类:

代码语言:javascript
复制
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站点的示例:

代码语言:javascript
复制
<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以编程方式做同样的事情?

EN

回答 2

Stack Overflow用户

发布于 2016-08-26 02:01:24

从外部位置获取策略并为当前消息构建策略。

使用Neethi库解析WS-Policy XML。将结果策略对象存储到PolicyConstants.POLICY_OVERRIDE消息内容属性中。

重要的是,此自定义策略拦截器在CXF PolicyInInterceptor或PolicyOutInterceptor之前调用。则CXF将自动识别存储在此属性中的策略,并以最高优先级使用它。

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

您可以找到几个代码示例: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
EN

Stack Overflow用户

发布于 2017-05-17 19:40:55

在sei或实现类中使用@Policies@Policy注释。在注释中指定策略的uri。参考http://cxf.apache.org/docs/annotations.html

代码语言:javascript
复制
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);

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38978763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档