springboot集成cxf

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.syx</groupId><artifactId>cxf-learn</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><cxf.version>3.2.4</cxf.version></properties><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.4</version><relativePath/> <!-- lookup parent from repository --></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- webService--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web-services</artifactId></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxws</artifactId><version>3.2.4</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>5.4.1.Final</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.12.0</version></dependency></dependencies></project>
package com.cxf.config;import com.cxf.endpoint.Service;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.util.Collections;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;/*** Author whh* Date 2023/12/07/ 22:39* <p></p>*/
@Configuration
public class WebServiceConfig {@Autowiredprivate SpringBus bus;@Autowiredprivate Service service;@Beanpublic Endpoint endpoint() {EndpointImpl endpoint = new EndpointImpl(bus,service);endpoint.setInInterceptors(Collections.singletonList(new LoggingInInterceptor()));endpoint.setOutInterceptors(Collections.singletonList(new LoggingOutInterceptor()));//将serviceName作为线程池前缀WebService annotation = service.getClass().getAnnotation(WebService.class);String prefix = annotation.serviceName();ThreadPoolExecutor executor = new ThreadPoolExecutor(10,50,2L,TimeUnit.SECONDS,new LinkedBlockingQueue<>(),new BasicThreadFactory.Builder().namingPattern(prefix+"-thread-pool-%d").daemon(true).build(),new ThreadPoolExecutor.CallerRunsPolicy());//设置线程池endpoint.setExecutor(executor);endpoint.publish("/api");return endpoint;}
}
package com.cxf.endpoint;import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;/*** Author whh* Date 2023/12/07/ 22:22* <p></p>*/
@WebService(targetNamespace = "http://com.cxf.endpoint.Service")
public interface Service {@WebMethodString sayHello(@WebParam(name = "name")String name);
}
package com.cxf.endpoint;import org.springframework.stereotype.Component;import javax.jws.WebService;/*** Author whh* Date 2023/12/07/ 22:35* <p></p>*/@WebService(serviceName = "Service",targetNamespace = "http://com.cxf.endpoint.Service",//指定你想要的名称空间,通常使用使用包名反转endpointInterface = "com.cxf.endpoint.Service")
@Component
public class ServiceImpl implements Service {@Overridepublic String sayHello(String name) {System.out.println(Thread.currentThread().getName());return "Hello,"+name;}
}
import com.cxf.endpoint.Service;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;/*** Author whh* Date 2023/12/07/ 22:58* <p></p>*/
public class MainTest {public static void main(String[] args) {String address = "http://127.0.0.1:8080/primal/cxf/api/Service";// 代理工厂JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();// 设置代理地址jaxWsProxyFactoryBean.setAddress(address);// 设置接口类型jaxWsProxyFactoryBean.setServiceClass(Service.class);// 创建一个代理接口实现Service xmlEndPoint = (Service) jaxWsProxyFactoryBean.create();Client proxy = ClientProxy.getClient(xmlEndPoint);HTTPConduit conduit = (HTTPConduit) proxy.getConduit();HTTPClientPolicy policy = new HTTPClientPolicy();policy.setConnectionTimeout(5000);policy.setReceiveTimeout(5000);conduit.setClient(policy);String service = xmlEndPoint.sayHello("123");System.out.println(service);}
}
server:servlet:context-path: /primalport: 8080cxf:path: /cxf
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHello xmlns:ns2="http://com.cxf.endpoint.Service"><name>123</name></ns2:sayHello></soap:Body>
</soap:Envelope>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/205648.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Dockerfile介绍

1. DockerFile介绍 dockerfile是用来构建docker镜像的文件&#xff01;命令参数脚本&#xff01; 构建步骤&#xff1a; 1、编写一个dockerfile文件 2、docker build 构建成为一个镜像 3、docker run运行镜像 4、docker push发布镜像&#xff08;DockerHub、阿里云镜像仓库…

Django模板,Django中间件,ORM操作(pymysql + SQL语句),连接池,session和cookie, 缓存

day04 django进阶-知识点 今日概要&#xff1a; 模板中间件ORM操作&#xff08;pymysql SQL语句&#xff09;session和cookie缓存&#xff08;很多种方式&#xff09; 内容回顾 请求周期 路由系统 最基本路由关系动态路由&#xff08;含正则&#xff09;路由分发不同的app中…

《论文阅读》用于情绪回复生成的情绪正则化条件变分自动编码器 Affective Computing 2021

《论文阅读》用于情绪回复生成的情绪正则化条件变分自动编码器 前言简介模型结构实验结果总结前言 今天为大家带来的是《Emotion-Regularized Conditional Variational Autoencoder for Emotional Response Generation》 出版:IEEE Transactions on Affective Computing 时间…

ZKP Understanding Nova (2) Relaxed R1CS

Understanding Nova Kothapalli, Abhiram, Srinath Setty, and Ioanna Tzialla. “Nova: Recursive zero-knowledge arguments from folding schemes.” Annual International Cryptology Conference. Cham: Springer Nature Switzerland, 2022. Nova: Paper Code 2. Unders…

安装TensorFlow2.12.0

文章目录 一、安装Anaconda步骤 1: 下载Anaconda步骤 2: 运行安装程序步骤 3: 选择安装路径步骤 4: 完成安装步骤 5: 启动Anaconda Navigator步骤 6: 创建和管理环境二、安装TensorFlow​(一)Anaconda修改国内镜像源(二)安装CPU版TensorFlow2.12.0(三)查看TensorFlow版本…

openGauss学习笔记-147 openGauss 数据库运维-备份与恢复-逻辑备份与恢复之gs_dump

文章目录 openGauss学习笔记-147 openGauss 数据库运维-备份与恢复-逻辑备份与恢复之gs_dump147.1 背景信息147.2 注意事项147.3 语法147.4 参数说明147.4.1 通用参数&#xff1a;147.4.2 转储参数&#xff1a;147.4.3 连接参数&#xff1a; 147.5 说明147.6 示例 openGauss学习…

HTTP、HTTPS、SSL协议以及报文讲解

目录 HTTP/HTTPS介绍 HTTP/HTTPS基本信息 HTTP请求与应答报文 HTTP请求报文 HTTP响应报文 SSL协议 SSL单向认证 SSL双向认证 HTTP连接建立与传输步骤 HTTP访问全过程相关报文&#xff08;以访问www.download.cucdccom为例子&#xff09; DNS报文解析 TCP三次握手连…

【Flink系列六】Flink里面的状态一致性

状态一致性 有状态的流处理&#xff0c;内部每个算子任务都可以有自己的状态&#xff0c;对于流处理器内部来说&#xff0c;所谓的状态一致性&#xff0c;其实就是我们所说的计算结果要保证准确。一条数据不应该丢失&#xff0c;也不应该重复计算。再遇到有故障时可以恢复状态…

RabbitMQ 常见面试题

目录 1.前置知识1.1.什么是 MQ&#xff1f;它有什么作用&#xff1f;1.2.什么是消费者生产者模型&#xff1f;1.3.AMQP 是什么&#xff1f; 2.RabbitMQ 入门2.1.什么是 RabbitMQ&#xff1f;有什么特点&#xff1f;2.2.RabbitMQ 的核心概念有哪些&#xff1f;2.2.1.生产者 (Pro…

css 元素前后添加图标(::before 和 ::after 的妙用)

<template><div class"container"><div class"label">猜你喜欢</div></div> </template><style lang"scss" scoped> .label {display: flex;&::before,&::after {content: "";widt…

《实战:如何使用Vue2.0开发一个npm组件库》- 6、Vue2.x 组件 webpack3 升 webpack5

升级 package.json 删除冗余依赖 "extract-text-webpack-plugin": "^3.0.2","vue-loader": "^13.0.5", "vue-template-compiler": "^2.4.4", "webpack": "^3.6.0", "webpack-dev-serv…

LLM之RAG实战(二):使用LlamaIndex + Metaphor实现知识工作自动化

最先进的大型语言模型&#xff08;LLM&#xff09;&#xff0c;如ChatGPT、GPT-4、Claude 2&#xff0c;具有令人难以置信的推理能力&#xff0c;可以解锁各种用例——从洞察力提取到问答&#xff0c;再到通用工作流自动化。然而&#xff0c;他们检索上下文相关信息的能力有限。…

[论文阅读]BEVFusion

BEVFusion BEVFusion: A Simple and Robust LiDAR-Camera Fusion Framework BEVFusion&#xff1a;简单而强大的激光雷达相机融合框架 论文网址&#xff1a;BEVFusion 论文代码&#xff1a;BEVFusion 简读论文 论文背景&#xff1a;激光雷达和摄像头是自动驾驶系统中常用的两…

UE Http笔记

c参考链接 UE4 开发如何使用 Http 请求_wx61ae2f5191643的技术博客_51CTO博客 虚幻引擎:UEC如何对JSON文件进行读写?-CSDN博客 UE4 HTTP使用 官方免费插件 VaRest 在代码插件创建的VaRest - 虚幻引擎商城 UE5在蓝图中使用Varest插件Get&#xff0c;Post两种常见请求方式…

webpack学习-3.管理输出

webpack学习-3.管理输出 1.简单练手2.设置 HtmlWebpackPlugin3.清理 /dist 文件夹4.manifest5.总结 1.简单练手 官网的第一个预先准备&#xff0c;是多入口的。 const path require(path);module.exports {entry: {index: ./src/index.js,print: ./src/print.js,},output: …

axios调接口传参特殊字符丢失的问题(encodeURI 和 encodeURIComponent)

1、axios调接口特殊字符丢失的问题 项目开发过程中遇到一个接口传参&#xff0c;参数带特殊字符&#xff0c;axios调接口特殊字符丢失的问题 例如接口&#xff1a; get/user/detail/{name} name是个参数直接调接口的时候拼到接口上&#xff0c;get/user/detail/test123#$%&am…

计算机网络中的通信子网:架构、协议与技术简介

在计算机网络中&#xff0c;通信子网是负责实现主机之间以及主机与终端之间数据传输的核心部分。它由一系列硬件设备和通信协议组成&#xff0c;为上层应用提供可靠、高效和透明的数据传输服务。本文将详细介绍通信子网的架构、协议与技术。 一、通信子网的架构 星型拓扑 星…

华为配置Smart Link负载分担示例

Smart Link基本概念 Smart Link通过两个端口相互配合工作来实现功能。这样的一对端口组成了一个Smart Link组。为了区别一个Smart Link组中的两个端口&#xff0c;我们将其中的一个叫做主端口&#xff0c;另一个叫做从端口。同时我们利用Flush报文、Smart Link实例和控制VLAN等…

Matlab 点云曲线探测(算法不稳定,仅用于学习)

文章目录 一、简介二、实现代码三、实现效果参考文献一、简介 这是一个很有趣的曲线探测的方法,不过我没有复现出论文中那样的效果,可能是理解有误,但这个算法仍然是很有意思,故这里也对其进行记录。 按照论文中的思路,首先我们需要通过一种线性强度图来计算确定每个点的法…

js事件流模型

js 事件流模型js 事件循环 js 事件流模型 JavaScript的事件流模型可以被概括为三个阶段&#xff1a;捕获阶段&#xff0c;目标阶段和冒泡阶段。这个模型是在DOM&#xff08;文档对象模型&#xff09;中定义的&#xff0c;用于描述事件如何在DOM元素中传播。 捕获阶段&#xf…