1.什么是webservice?

webservice是一种远程资源调用技术,它的实现方式主要分为两种,

第一种是jaxws方式,它是面向方法的,它的数据类型是xml是基于soap实现传输;

第二种是jaxrs方式,它是面向资源的,它的数据类型是xml或json是基于http协议实现传输。

2.jaxws简单应用

服务端:

第一步:创建一个简单的web项目,略

第二步:添加webService的依赖jar包,配置web.xml

 <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
注:版本需与springboot对应 否则启动就会报错
在https://mvnrepository.com/artifact/org.apache.cxf/cxf-spring-boot-starter-jaxws查找到jaxws的各种版本,进入之后可以看到对应的springboot版本

问题详情:
Description: Parameter 1 of constructor in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type ‘org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath’ that could not be found. The following candidates were found but could not be injected:
- Bean method ‘dispatcherServletRegistration’ in ‘DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration’ not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet Action: Consider revisiting the entries above or defining a bean of type ‘org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath’ in your configuration. Process finished with exit code 1

启动报错(版本问题)

第三步:编写代码

 1 import com.test.demo.service.IDataReceiverService;
2 import org.apache.cxf.Bus;
3 import org.apache.cxf.jaxws.EndpointImpl;
4 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.context.annotation.Bean;
6 import org.springframework.context.annotation.Configuration;
7
8 import javax.xml.ws.Endpoint;
9
10 /**
11 * 〈cxf配置〉
12 * 默认:services
13 * http://127.0.0.1:6689/services/receiveData
14 * cxf-path配置路径:
15 * http://127.0.0.1:6689/soap/receiveData
16 */
17 @Configuration
18 public class CxfConfig {
19
20 @Autowired
21 private Bus bus;
22
23 @Autowired
24 private IDataReceiverService dataReceiverService;
25
26
27 /**
28 * 数据站点服务(总入口)
29 *
30 * @return
31 */
32 @Bean
33 public Endpoint getReceiveData() {
34 EndpointImpl endpoint = new EndpointImpl(bus, dataReceiverService);
35 endpoint.publish("/receiveData");
36 return endpoint;
37 }
38
39 }

CxfConfig

 1 package com.test.demo.service;
2
3
4 import com.test.demo.entity.ReceiveMsg;
5
6 import javax.jws.WebMethod;
7 import javax.jws.WebParam;
8 import javax.jws.WebService;
9
10 /**
11 * 接收数据处理服务类
12 *
13 * @Author: zhangt
14 * @Date: 2021/9/11 11:46
15 */
16
17 @WebService
18 public interface IDataReceiverService {
19
20
21 /**
22 * 接收数据接口
23 *
24 * @param receiveMsg 数据
25 * @return
26 */
27 @WebMethod
28 String getReceiveMsg(@WebParam(name = "ROOT") ReceiveMsg receiveMsg);
29
30 }

service

 1 package com.test.demo.service.impl;
2
3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.convert.Convert;
5 import com.test.demo.entity.ReceiveMsg;
6 import com.test.demo.entity.ResultMsg;
7 import com.test.demo.entity.UploadData;
8 import com.test.demo.service.IDataReceiverService;
9 import com.test.demo.util.ReceiveMsgUtil;
10 import lombok.extern.slf4j.Slf4j;
11 import org.dom4j.DocumentException;
12 import org.springframework.stereotype.Component;
13
14 import javax.jws.WebService;
15 import java.util.List;
16 import java.util.Map;
17
18 @WebService(serviceName = "receiverService", // 与接口中指定的name一致
19 targetNamespace = "http://service.demo.test.com", // 与接口中的命名空间一致,一般是接口的包名倒序排
20 endpointInterface = "com.test.demo.service.IDataReceiverService"// 接口地址
21 )
22 @Slf4j
23 @Component
24 public class DataReceiverServiceImpl implements IDataReceiverService {
25
26 /**
27 * 接收数据接口
28 *
29 * @param receiveMsg 数据
30 * @return
31 */
32 @Override
33 public String getReceiveMsg(ReceiveMsg receiveMsg) {
34
35 //解析报文,转化为需要写成文件的数据
36 UploadData uploadData = new UploadData();
37 String dataId = receiveMsg.getDATAID();
38 uploadData.setDataId(dataId);
39 //是否加密 (1 表示业务数据为密文传输,0 表示明文)
40 int sec = Convert.toInt(receiveMsg.getSEC());
41 uploadData.setHavePwd(sec);
42
43 //数据为明文时
44 if (1 == sec) {
45 //解码业务报文
46 try {
47 //获取解密后的业务数据
48 String data = ReceiveMsgUtil.decodeStr(receiveMsg.getBUSINESSCONTENT());
49 List<Map<String, Object>> list = ReceiveMsgUtil.xmlToList(data);
50 log.info("数据为list:{}", list);
51 uploadData.setBusinessData(list);
52 if (CollUtil.isEmpty(list)) {
53 return ResultMsg.getMessage(ResultMsg.BUSINESS_DATA_ANALYZE_ERROR);
54 }
55 } catch (DocumentException e) {
56 log.info("xml数据格式不正确!", e);
57 return ResultMsg.getMessage(ResultMsg.XML_ERROR);
58 } catch (Exception e) {
59 log.info("base64解码错!", e);
60 return ResultMsg.getMessage(ResultMsg.BASE64_ERROR);
61 }
62 }
63
64 return ResultMsg.getMessage(ResultMsg.SUCCESS);
65 // return uploadData.getReplyData();
66 }
67
68 }

serviceImpl

1 server:
2 port: 6689
3 spring:
4 application:
5 name: cxfDemo
6 # profiles:
7 # active: dev
8 cxf:
9 path: /soap #默认services

yml

第四步:启动项目,查看wsdl说明书

这里面的路径注意cxf在web中的配置:

参数说明:

@WebService:在接口上申明,表示该接口是一个webService服务;
@WebMethod:在接口方法上声明,表示该方法是一个webService服务方法;

@WebService(endpointInterface="cn.linc.cxf.interfaces.ServiceUI",serviceName="userService"):在该接口实现类定义;

endpointInterface:表示接口服务终端接口名;
serviceName:服务名称;
wsdl解读:有五个节点:服务视图,服务协议和参数的描述,服务实现,参数描述,参数类型描述。

调用展示:


原理解析:
  可以分为三个角色:服务提供者,服务消费者,服务注册中心uddi
  首先由服务提供者发布服务并且在注册中心uddi进行注册
  然后由服务消费者订阅服务,在注册中心uddi上查询到符合条件的服务
  服务注册中心返回服务条件服务的描述文件给服务订阅者
  订阅者根据描述文件进行服务端的服务调用,并返回数据。

工具:

加解密:https://tool.oschina.net/encrypt

soapUI:https://www.soapui.org/downloads/soapui/

参考:

https://blog.csdn.net/qiaodaima0/article/details/100765613

https://www.cnblogs.com/xiechenglin/p/10500558.html

https://www.cnblogs.com/shuaijie/articles/5913750.html

webservice之jax-ws实现方式(服务端)的更多相关文章

  1. node.js中ws模块创建服务端和客户端,网页WebSocket客户端

    首先下载websocket模块,命令行输入 npm install ws 1.node.js中ws模块创建服务端 // 加载node上websocket模块 ws; var ws = require( ...

  2. 微信小程序访问webservice(wsdl)+ axis2发布服务端(Java)

    0.主要思路:使用axis2发布webservice服务端,微信小程序作为客户端访问.步骤如下: 1.服务端: 首先微信小程序仅支持访问https的url,且必须是已备案域名.因此前期的服务器端工作需 ...

  3. cxf webservice生成客户端代码及调用服务端遇到的问题

    1.  从网上下载cxf开发的工具 apache-cxf-3.1.4.zip, 解压文件,找到apache-cxf-3.1.4\bin目录,里面包含一个wsdl2java文件 2. 设置环境变量 1. ...

  4. JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)

    前言:我之前是从事C#开发的,因公司项目目前转战JAVA&ANDROID开发,由于对JAVA的各种不了解,遇到的也是重重困难.目前在做WEBSERVICE提供数据支持,看了网上相关大片的资料也 ...

  5. React 服务端渲染最佳解决方案

    最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...

  6. http服务端架构演进

    摘要 在详解http报文相关文章中我们介绍了http协议是如何工作的,那么构建一个真实的网站还需要引入组件呢?一些常见的名词到底是什么含义呢? 什么叫正向代理,什么叫反向代理 服务代理与负载均衡的差别 ...

  7. React 服务端渲染方案完美的解决方案

    最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...

  8. 判断python socket服务端有没有关闭的方法

    通过 getattr(socket, '_closed') 的返回值可以判断服务端的运行状态. True 是关闭状态,False 是运行中. import socket ip = 'localhost ...

  9. webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)

    1.定义接口 package org.WebService.ws.annotation; import javax.jws.WebService; @WebService public interfa ...

  10. Maven搭建webService (二) 创建服务端---使用web方式发布服务

    今天和大家分享 使用 web方式发布 webService 服务端.客户端 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <!-- spring core ...

随机推荐

  1. 【转帖】GPT4All开源的聊天机器人

    GPT4All是一个开源的聊天机器人,它基于LLaMA的大型语言模型训练而成,使用了大量的干净的助手数据,包括代码.故事和对话.它可以在本地运行,不需要云服务或登录,也可以通过Python或Types ...

  2. [转帖]LTP使用和分析

    一.安装及编译流程 1.下载LTP LTP 项目目前位于 GitHub,项目地址:https://github.com/linux-test-project/ltp . 获取最新版可以执行以下命令: ...

  3. [转帖]kubernetes calico网络

    https://plantegg.github.io/2022/01/19/kubernetes%20calico%E7%BD%91%E7%BB%9C/ cni 网络 cni0 is a Linux ...

  4. pytest-数据驱动

    今天介绍两种实现数据驱动的方法,json和excel,我们以获取企业微信token接口为例,共 有两个参数corpid&corpsecret 一.json 方法一:@pytest.mark.p ...

  5. CDP技术系列(三):百万级QPS的人群命中服务接口性能优化指南

    一.背景介绍 CDP系统提供了强大的标签和群体的构建能力,面对海量数据的标签和群体,我们采用了Bitmap+ClickHouse的存储与计算方案.详细内容可以参考之前文章. 有了群体之后,它们被广泛的 ...

  6. 【构造,树】【Loj】Loj6669 Nauuo and Binary Tree

    2023.7.3 Problem Link 交互库有一棵 \(n\) 个点的二叉树,你每次可以询问两个点之间的距离,猜出这棵二叉树.\(n\le 3000\),询问次数上限 \(30000\). 首先 ...

  7. canvas操作图片像素点保证你看的明明白白

    开场白 今天遇到一个场景:就是更改一个图片的颜色: 当听到这个.我直呼好家伙:这个是要上天了呀. 但是仔细一思考:借助canvas好像也能实现: 于是下来研究了一下,并不难: 我们下面来看看怎么实现的 ...

  8. 同步存储读取vuex中store中的值

    main.js import store from "./store"; Vue.prototype.$store = store; 在 store中的index.js中 impo ...

  9. mysql系列基础篇03----约束

    一.概述 1.概念:约束是作用于表中字段上的规则,用于限制存储在表中的数据 2.目的:保证数据库中数据的正确,有效性和完整性. 3.分类  二.约束演示 创建一个用户表 create table my ...

  10. Libevent [补档-2023-08-29]

    libevent的使用 8-1 安装 ​ 自己百度一下,安装它不是特别难,加油!!! 8-2 libevent介绍 ​ 它是一个开源库,用于处理网络和定时器等等事件.它提供了跨平台的API,能够在不同 ...