✨SpringBoot Apache CXF 配置
399 字
2 分钟
✨SpringBoot Apache CXF 配置
SpringBoot Apache CXF 配置
docker-compose.yml 文件配置
public String sendWebServiceApi(String method, String xml, String message) { StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); // 获取接口密钥 String ztbKey = ConstantContextHolder.getSysConfig("ZTB_KEY", String.class, true); // 获取接口地址 String ztbWebServiceUrl = ConstantContextHolder.getSysConfigWithDefault("ZTB_WEB_SERVICE_URL", String.class, "<http://127.0.0.1/WebService.asmx?wsdl>"); // 获取是否开启请求超时 String ztbWebHttpTimeOut = ConstantContextHolder.getSysConfigWithDefault("ZTB_WEB_REQUEST_TIME_OUT", String.class, "N"); // 获取请求超时时间 Integer ztbWebRequestTimeOutTime = ConstantContextHolder.getSysConfigWithDefault("ZTB_WEB_REQUEST_TIME_OUT_TIME", Integer.class, 3); // 获取请求超时时间 Integer ztbWebConnectionTimeOutTime = ConstantContextHolder.getSysConfigWithDefault("ZTB_WEB_CONNECTION_TIME_OUT_TIME", Integer.class, 3);
// 创建根元素 Element root = new Element("Request_Packet");
// 创建并添加Header元素 Element header = new Element("Header"); header.addContent(new Element("Key").setText(ztbKey)); header.addContent(new Element("from").setText("请求者")); header.addContent(new Element("instruct").setText(method));
// 添加Header到根元素 root.addContent(header);
// 创建Content元素并添加CDATA内容 Element content = new Element("Content"); content.addContent(new CDATA(xml));
// 添加Content到根元素 root.addContent(content);
// 将根元素转换为XML文档 Document document = new Document(root);
// 使用XMLOutputter输出XML字符串 XMLOutputter xmlOutput = new XMLOutputter(); // 格式化输出 xmlOutput.setFormat(Format.getPrettyFormat()); String xmlString = xmlOutput.outputString(document);
JaxWsDynamicClientFactory dynamicClient = JaxWsDynamicClientFactory.newInstance(); Object[] objectArray; try (Client client = dynamicClient.createClient(ztbWebServiceUrl)) { // 设置超时单位为毫秒 HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout((1000 * 60) * ztbWebConnectionTimeOutTime); policy.setAllowChunking(false); policy.setReceiveTimeout((1000 * 60) * ztbWebRequestTimeOutTime); conduit.setClient(policy); // 强制设置URL,确保端口号没有丢失 // conduit.getTarget().getAddress().setValue("<http://127.0.0.1/WebService.asmx>"); objectArray = client.invoke("ProcessData", xmlString); } stopWatch.stop(); log.error("sendWebServiceApi - 执行请求耗时: {} 秒", stopWatch.getTotalTimeSeconds()); log.info("请求返回结果: {}", objectArray[0].toString()); return formatXml(objectArray[0].toString()); } catch (Exception e) { stopWatch.stop(); log.error("WebService接口异常 - 执行请求耗时: {} 秒", stopWatch.getTotalTimeSeconds()); log.error("WebService接口异常, {}, {},", message, e.getMessage(), e); return null; } }以下重点,遇到的坑
// 1.在使用代理的情况下可能导致请求地址无端口号// 强制设置URL,确保端口号没有丢失conduit.getTarget().getAddress().setValue("<http://127.0.0.1/WebService.asmx>");
// 2.ProcessData 必须和公布的WebService 一致,大小写不一样都不行objectArray = client.invoke("ProcessData", xmlString);文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
✨SpringBoot Apache CXF 配置
https://dear7575.cn/posts/springboot-apache-cxf/ 相关文章 智能推荐
1
✨SpringBoot 网卡获取忽略代理配置
技术分享 记录 Spring Boot 通过配置忽略虚拟网卡、代理网卡等网络接口,避免服务注册或网络识别异常。
2
✨IDEA 常用快捷键
技术分享 整理 IntelliJ IDEA 日常开发常用快捷键,覆盖搜索、编辑、导航、重构、运行调试、Git 与窗口操作。
3
✨IDEA 方法注释配置
技术分享 记录 IntelliJ IDEA 方法注释 Live Templates 模板配置,包含参数、返回值、日期和自定义注释样式。
4
✨使用EasyExcel实现导出Excel写入图片
技术分享 记录使用 EasyExcel 导出 Excel 并写入图片的实现示例,包含自定义写入处理逻辑。
5
✨基于Redis + WebSocket的批量文件处理系统
技术分享 记录基于 Redis 缓存、WebSocket 实时通信和多线程处理的批量文件处理系统设计与实现思路。
随机文章 随机推荐