webservice之jax-ws实现方式(服务端)
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实现方式(服务端)的更多相关文章
- node.js中ws模块创建服务端和客户端,网页WebSocket客户端
		
首先下载websocket模块,命令行输入 npm install ws 1.node.js中ws模块创建服务端 // 加载node上websocket模块 ws; var ws = require( ...
 - 微信小程序访问webservice(wsdl)+ axis2发布服务端(Java)
		
0.主要思路:使用axis2发布webservice服务端,微信小程序作为客户端访问.步骤如下: 1.服务端: 首先微信小程序仅支持访问https的url,且必须是已备案域名.因此前期的服务器端工作需 ...
 - cxf webservice生成客户端代码及调用服务端遇到的问题
		
1. 从网上下载cxf开发的工具 apache-cxf-3.1.4.zip, 解压文件,找到apache-cxf-3.1.4\bin目录,里面包含一个wsdl2java文件 2. 设置环境变量 1. ...
 - JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)
		
前言:我之前是从事C#开发的,因公司项目目前转战JAVA&ANDROID开发,由于对JAVA的各种不了解,遇到的也是重重困难.目前在做WEBSERVICE提供数据支持,看了网上相关大片的资料也 ...
 - React 服务端渲染最佳解决方案
		
最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...
 - http服务端架构演进
		
摘要 在详解http报文相关文章中我们介绍了http协议是如何工作的,那么构建一个真实的网站还需要引入组件呢?一些常见的名词到底是什么含义呢? 什么叫正向代理,什么叫反向代理 服务代理与负载均衡的差别 ...
 - React 服务端渲染方案完美的解决方案
		
最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...
 - 判断python socket服务端有没有关闭的方法
		
通过 getattr(socket, '_closed') 的返回值可以判断服务端的运行状态. True 是关闭状态,False 是运行中. import socket ip = 'localhost ...
 - webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
		
1.定义接口 package org.WebService.ws.annotation; import javax.jws.WebService; @WebService public interfa ...
 - Maven搭建webService (二) 创建服务端---使用web方式发布服务
		
今天和大家分享 使用 web方式发布 webService 服务端.客户端 1.首先创建 一个web工程(增加Maven依赖) 2.增加Maven依赖包,如下: <!-- spring core ...
 
随机推荐
- [转帖]《Linux性能优化实战》笔记(24)—— 动态追踪 DTrace
			
使用 perf 对系统内核线程进行分析时,内核线程依然还在正常运行中,所以这种方法也被称为动态追踪技术.动态追踪技术通过探针机制来采集内核或者应用程序的运行信息,从而可以不用修改内核和应用程序的代码就 ...
 - [转帖]linux中Shell日期转为时间戳的方法
			
http://www.nndssk.com/xtwt/169617hFPRvq.html shell中获取时间戳的方式为:date -d "$currentTime" +%s $ ...
 - js判断一个时间是否在某一个时间段内
			
很多时候,我们需要对时间进行处理: 比如说:获取当前的时间 判断某一个时间是否在一段时间内:如果在显示出某一个按钮: 让用户可以操作:如果不在,按钮隐藏 这个时候,我们就需要对时间进行处理了 < ...
 - MySQL数据库精选(从入门使用到底层结构)
			
基本使用MySQL 通用语法及分类 DDL: 数据定义语言,用来定义数据库对象(数据库.表.字段) DML: 数据操作语言,用来对数据库表中的数据进行增删改 DQL: 数据查询语言,用来查询数据库中表 ...
 - 如何通过gRPC传输文件
			
在gRPC中,可以通过将文件分割成多个小块,然后使用流式RPC将这些小块发送到服务器来传输文件.以下是一个简单的示例,展示了如何在gRPC中实现文件传输. 首先,我们需要定义一个服务来处理文件传输.在 ...
 - 小白学k8s(4)使用k8s发布go应用
			
k8s发布go应用 前言 部署 镜像打包 编写yaml文件 使用ingress 什么是ingress呢 ingress与ingress-controller ingress 部署ingress 配置i ...
 - SqlSugar分组查询
			
一.分组查询和使用 1.1 语法 只有在聚合对象需要筛选的时候才会用到Having,一般分组查询用不到可以去掉 var list = db.Queryable<Student>() ...
 - Linux基础命令 [补档-2023-06-28]
			
Linux基础命令 1-1.命令的基本格式  Linux系统命令的通用格式为:  command [-options] [parameter]  其中  -command 命令本身  -op ...
 - 2、Web前端学习规划:HTML - 学习规划系列文章
			
今天先写Web前端最基本的语言:HTML.目前已经到了HTML5版本,作为Web基本语言,笔者认为这个是最先需要学习的语言. 1. 简介: HTML(HyperText Markup Languag ...
 - 小知识:安装系统后唯独搜不到自己的Wi-Fi
			
遇到的问题,笔记本在安装Win10系统后在可用Wi-Fi热点中唯独搜不到自己的Wi-Fi. 咨询宽带售后的技术人员,说可能是因为我目前使用的是Wi-Fi 6,而我的笔记本可能是网卡过旧,不支持Wi-F ...