zoukankan      html  css  js  c++  java
  • 用 Eclipse 开发 WebService 项目

    1、安装tomcat

    2、安装CXF

    一、为新渠道webservice加入到项目中
    首先,创建一个springboot项目,名为webservice-baffle(附件中)。
    第二步,新建web service 服务端
    右击webservice-baffle项目,新建“other”,在弹出框中选择“web service”,出现如下弹出框
    截图中:
    1、web service type:选择 Top down java bean web service
    2、web service的http url
    3、选择tomcat,如果没有环境,自己下载tomcat并安装配置下
    4、选择apache CXF 2.x,如果没有,自己下载和安装下
    下一步,出现如下提示框,默认到完成。
    最后,生成一个WebServiceProject项目。
    第三步:将生产的java类拷贝到webservice-baffle项目中:

    第四步:注册webservice接口到servlet中:
    该操作的代码在com.xxx.xxx.config.EndpointConfig.java
    @Configuration
    public class CxfConfig {
     
        @Autowired
        private Bus bus;   //private SpringBus bus;
        @Autowired
        private CommonService commonService;
     
        //  配置CXF服务发布,默认服务是在host:port/services/发布地址
        // 访问地址 http://127.0.0.1:8080/Service/common?wsdl
        @Bean
        public Endpoint another_endpoint() {
            EndpointImpl endpoint = new EndpointImpl(bus, commonService);
            endpoint.publish("/common");   //发布地址
            return endpoint;
        }
        // 访问地址 http://127.0.0.1:8080/Service/hello?wsdl
        @Bean
        public Endpoint endpoint() {
            EndpointImpl endpoint = new EndpointImpl(bus,  new HelloServiceImpl());
            endpoint.publish("/hello");    //发布地址
            return endpoint;
        }
    完成。

     

    问题:

    1、与Spring整合问题
    Caused by: org.apache.cxf.ws.policy.PolicyException: These policy alternatives can not be satisfied: 
    {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SupportingTokens
    {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}UsernameToken
    at org.apache.cxf.ws.policy.AssertionInfoMap.checkEffectivePolicy(AssertionInfoMap.java:166)
    at org.apache.cxf.ws.policy.PolicyVerificationInInterceptor.handle(PolicyVerificationInInterceptor.java:101)

    解决方法
    esb-server.xml配置增加
    <cxf:bus>
    <cxf:properties>
    <entry key="org.apache.cxf.message.Message.ENCODING" value="UTF-8"/>
    </cxf:properties>
    <cxf:features>
    <cxf:logging/>
    <p:policies enabled="false" />
    </cxf:features>
    </cxf:bus>

        @Bean(name = Bus.DEFAULT_BUS_ID)
        public SpringBus springBus() {
            SpringBus springBus = new SpringBus();
            WSPolicyFeature wpf = new WSPolicyFeature();
            wpf.setEnabled(false);
            Collection<Feature> features = springBus.getFeatures();
            features.add(wpf);
            return springBus;
        }
  • 相关阅读:
    js浅拷贝和深拷贝
    使用slice和concat对数组的深拷贝和浅拷贝
    JS数组常用方法---8、concat方法
    JS数组常用方法---7、join方法
    js中将类数组转换为数组的几种方法
    JS 使用const声明常量的本质(很多人都有误解)
    JS中对象数组按照对象的某个属性进行排序
    vue源码分析参考---2、数据代理
    vue源码分析参考---1、准备工作
    ES6课程---5、形参默认值
  • 原文地址:https://www.cnblogs.com/duanxz/p/4368229.html
Copyright © 2011-2022 走看看