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. [转帖]使用 TiUP 升级 TiDB

    本文档适用于以下升级路径: 使用 TiUP 从 TiDB 4.0 版本升级至 TiDB 7.1. 使用 TiUP 从 TiDB 5.0-5.4 版本升级至 TiDB 7.1. 使用 TiUP 从 Ti ...

  2. 【转帖】SQUID TIME_WAIT值过高引起的服务器被拖慢

    https://www.diewufeiyang.com/post/895.html 查看TCP的连接状态值: # netstat -n | awk '/^tcp/ {++S[$NF]} END {f ...

  3. [转帖]ldconfig命令

    https://linux265.com/course/linux-command-ldconfig.html ldconfig命令的作用主要是在默认搜寻目录/lib和/usr/lib以及动态库配置文 ...

  4. Springboot 使用nacos鉴权的简单步骤

    Springboot 使用nacos鉴权的简单步骤 背景 前端时间nacos爆出了漏洞. 因为他的默认token固定,容易被利用. 具体的问题为: QVD-2023-6271 漏洞描述:开源服务管理平 ...

  5. [转帖]JVM 参数

    https://www.cnblogs.com/xiaojiesir/p/15636100.html 我们可以在启动 Java 命令时指定不同的 JVM 参数,让 JVM 调整自己的运行状态和行为,内 ...

  6. BAdI:INVOICE_UPDATE 导致MM Invoice Doc. Missing

    Symptom:发票校验过程中,对应发票号生成,FI凭证也产生,但是对应RBKP,RSEG中无相应的发票. 原先这一问题SAP早给出过解释,参照note:1876234 Cause:在SD MM模块中 ...

  7. Docker 安装 Nacos 注册中心

    废话不多说直接上安装脚本: 在运行安装脚本之前,首先,我们查看一下 Nacos 的版本分别有哪些使用 docker search nacos: 然后在执行: docker pull nacos/nac ...

  8. TienChin 开篇-运行 RuoYiVue

    开篇 目的: 让大家随心所欲的 DIY 若依的脚手架 不会涉及到太多基础知识 踊跃提问(不懂得地方大家提问我会根据提问,后续一一解答疑惑) 下载 RuoYiVue Gitee: https://git ...

  9. C/C++ 实现Socket交互式服务端

    在 Windows 操作系统中,原生提供了强大的网络编程支持,允许开发者使用 Socket API 进行网络通信,通过 Socket API,开发者可以创建.连接.发送和接收数据,实现网络通信.本文将 ...

  10. 3.0 熟悉IDAPro静态反汇编器

    IDA Pro 是一种功能强大且灵活的反汇编工具,可以在许多领域中发挥作用,例如漏洞研究.逆向工程.安全审计和软件开发等,被许多安全专家和软件开发者用于逆向工程和分析二进制代码.它支持大量的二进制文件 ...