diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c90f39c..ebaa9c3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,18 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index c17b7ca..f2e3d2e 100644 --- a/pom.xml +++ b/pom.xml @@ -151,6 +151,59 @@ 1.11 compile + + cn.hutool + hutool-all + 5.8.37 + + + cn.hutool + hutool-crypto + 5.8.37 + + + + org.springframework.boot + spring-boot-starter-web-services + + + org.apache.cxf + cxf-spring-boot-starter-jaxws + 3.3.0 + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + + + + + + + + + + org.apache.axis2 + axis2-corba + 1.8.2 + + + org.apache.axis2 + axis2-jaxws + 1.8.2 + + + org.apache.axis2 + axis2-spring + 1.8.2 + + diff --git a/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java b/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java index f82e46b..3ac2551 100644 --- a/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java +++ b/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java @@ -11,6 +11,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; @@ -19,6 +20,7 @@ import java.util.Map; @EnableJpaAuditing @EnableScheduling +@EnableAsync @SpringBootApplication public class AdminClientTemperatureApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationContextAware { diff --git a/src/main/java/com/rehome/mqttclienttemperature/task/AgencyTask.java b/src/main/java/com/rehome/mqttclienttemperature/task/AgencyTask.java new file mode 100644 index 0000000..1b3b200 --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/task/AgencyTask.java @@ -0,0 +1,87 @@ +package com.rehome.mqttclienttemperature.task; + + +import cn.hutool.http.webservice.SoapClient; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.rehome.mqttclienttemperature.utils.WebServiceUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.*; + +/*** + * 调用本地布署的Webservice + */ +@Component +public class AgencyTask { + private static final Logger log = LoggerFactory.getLogger(AgencyTask.class); + + + //每1分钟执行一次 + @Scheduled(cron="0 0/1 * * * ?") + protected void addRfqs(){ + log.info("调用本地布署的Webservice,时间:{}",new Date()); + + try { + Gson gson = new Gson(); + +// String url = "http://127.0.0.1:8873/webservice/AgencyService?wsdl"; +// String namespace = "http://webservice.mqttclienttemperature.rehome.com/"; +// String method = "queryAgencyStatInfo"; +// Map paramsMap = new HashMap(); +// paramsMap.put("user_id", "4783748PL898878"); +// paramsMap.put("token", "37483748YU23"); +// paramsMap.put("user_name", "371522"); +// +// Map paramBodyMap = new HashMap(); +// paramBodyMap.put("paramBody", gson.toJson(paramsMap)); +// String result = WebServiceUtils.invoke(url,namespace,method,paramBodyMap); +// log.info("结果:"+result); + + String url = "http://127.0.0.1:8873/webservice/AgencyService?wsdl"; + String namespace = "http://webservice.mqttclienttemperature.rehome.com/"; + String method = "syncAgencyStatInfo"; + Map paramsMap = new HashMap(); + paramsMap.put("user_id", "4783748PL898878"); + paramsMap.put("token", "37483748YU23"); + paramsMap.put("user_name", "371522"); + + Map paramBodyMap = new HashMap(); + paramBodyMap.put("paramBody", gson.toJson(paramsMap)); + String result = WebServiceUtils.invoke(url,namespace,method,paramBodyMap); + log.info("结果:"+result); + +// String url = "http://127.0.0.1:8873/ws/ApiCommonService?wsdl"; +// String namespace = "http://webservice.mqttclienttemperature.rehome.com/"; +// String method = "commonApi"; +// Map paramsMap = new HashMap(); +// paramsMap.put("param1", "12"); +// paramsMap.put("param2", "332"); +// +// String result = WebServiceUtils.invoke(url,namespace,method,paramsMap); +// log.info("结果:"+result); + + +// SoapClient soapClient = SoapClient.create("http://127.0.0.1:8873/ws/ApiCommonService?wsdl"); +// soapClient.setMethod("commonApi", "http://webservice.mqttclienttemperature.rehome.com/").setParam("param1", "1").setParam("param2","2"); +// String send = soapClient.send(true); +// System.out.println(send); + +// SoapClient soapClient = SoapClient.create(url); +// soapClient.setMethod(method, namespace).setParam("paramBody", gson.toJson(paramsMap)); +// String send = soapClient.send(true); +// System.out.println(send); + + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/rehome/mqttclienttemperature/utils/WebServiceUtils.java b/src/main/java/com/rehome/mqttclienttemperature/utils/WebServiceUtils.java new file mode 100644 index 0000000..1b90640 --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/utils/WebServiceUtils.java @@ -0,0 +1,128 @@ +package com.rehome.mqttclienttemperature.utils; + + +import cn.hutool.http.webservice.SoapClient; +import com.google.gson.Gson; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.NamedValue; +import org.apache.axis2.kernel.http.HTTPConstants; +import org.apache.axis2.rpc.client.RPCServiceClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ObjectUtils; + +import javax.xml.namespace.QName; +import javax.xml.soap.SOAPBody; +import javax.xml.soap.SOAPFault; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + + +/** + * @Author: HuangWenfei + * @Description: 动态调用WebService, 用开源 hutool 第三库 SoapClient 调用远程rpc + * @Date: 2025/04/15 + **/ +public class WebServiceUtils { + private static final Logger log = LoggerFactory.getLogger(WebServiceUtils.class); + + public static String invoke(String url, String namespace, String methodTemp, Map paramsMap) { + String result = ""; + try { + SoapClient soapClient = SoapClient.create(url); + soapClient.setMethod(methodTemp, namespace); + if (paramsMap.size() > 0) { + Gson gson = new Gson(); + log.info("paramsMap:{}",gson.toJson(paramsMap)); + for (Map.Entry params : paramsMap.entrySet()) { + String key = params.getKey(); + String value = params.getValue(); + soapClient.setParam(key, value); + } + } + soapClient.header("app-id", "DYW_ZHDC"); + SOAPBody soapBody = soapClient.sendForMessage().getSOAPBody(); + SOAPFault soapFault = soapBody.getFault(); + if(!ObjectUtils.isEmpty(soapFault)&&soapFault.hasDetail()){ + String faultCode = soapFault.getFaultCode(); + String faultStr = soapFault.getFaultString(); + log.info("WebService调用失败,调用方法:{}",methodTemp); + log.info("faultCode:{}",faultCode); + log.info("faultStr:{}",faultStr); + }else{ + result = soapBody.getTextContent(); + log.info("WebService调用成功,调用方法:{}",methodTemp); + log.info("WebService调用成功,返回结果数据:{}",result); + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public static String invokeAxis2(String url, String namespace, String method, Map paramsMap) { + String result = ""; + try { + // 使用RPC方式调用WebService + RPCServiceClient serviceClient = new RPCServiceClient(); + Options options = serviceClient.getOptions(); + // 指定调用WebService的URL + EndpointReference targetEPR = new EndpointReference(url); + options.setTo(targetEPR); + // 添加HTTP请求头 + List headerList = new ArrayList<>(); + // headerList.add(new NamedValue("userName", "xxx")); + // 修改时候 字段大小写必须与原始一致 + headerList.add(new NamedValue("app-id", "DYW_ZHDC")); + options.setProperty(HTTPConstants.HTTP_HEADERS, headerList); + // 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是元素的targetNamespace属性值 + // // 指定要调用的getWorld方法及WSDL文件的命名空间..... + QName opAddEntry = new QName(namespace, method); + + Object[] opAddEntryArgs = null; + if (paramsMap.size() > 0) { + Gson gson = new Gson(); + System.out.println(gson.toJson(paramsMap)); + opAddEntryArgs = new Object[paramsMap.size()]; + opAddEntryArgs = joinParams(paramsMap, opAddEntryArgs); + } + // + // 指定getGreeting方法的参数值,如果有多个,继续往后面增加即可,不用指定参数的名称 + //Object[] opAddEntryArgs = new Object[]{"lmycc"}; + // 返回参数类型,这个和axis1有点区别 + // invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名; + // 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; + // 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 + // 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{} + // 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法, + // 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同 + // 指定getGreeting方法返回值的数据类型的Class对象..... + Class[] classes = new Class[]{String.class}; + // 调用getGreeting方法并输出该方法的返回值....... + result = (String) serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]; + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + /** + * @Author: xinsihai + * @Description: //拼接参数数据 + * @Date: 2024/10/22 + * @Param: + * @Return: + **/ + private static Object[] joinParams(Map paramsMap, Object[] object) { + int index = 0; + for (Map.Entry params : paramsMap.entrySet()) { + String value = params.getValue(); + object[index] = value; + index++; + } + return object; + } + +} diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyService.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyService.java new file mode 100644 index 0000000..380404a --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyService.java @@ -0,0 +1,38 @@ +package com.rehome.mqttclienttemperature.webservice; + + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; + +/** + * 单位信息 webService 远程接口 + * 1、@javax.jws.WebService 定义接口为 webservice 服务。 + * @author HuangWenfei + * @version 1.0 + * @date 2025/04/15 13:44 + */ +@WebService(targetNamespace = "http://webservice.mqttclienttemperature.rehome.com/") +public interface AgencyService { + /** + * 查询单位信息 + * 1、@WebMethod 定义方法为 webservice 方法。写或不写,服务端都会将 @WebService 中的所有方法提供给客户端调用。建议全部写上。 + * * operationName:操作名称,默认为方法名称。 + * 2、@WebParam 定义方法参数,用于定义wsdl中的参数映射名称,方便查看与调用,否则会是 arg0、arg1 ...。建议写上。 + * 3、@WebResult 定义 wsdl 文件中,服务端方法返回值名称,默认为 result,方便查看与调用。建议写上。 + * @param paramJson :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 + * @return :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 或者自己需要的实体对象。 + */ + @WebMethod(operationName = "queryAgencyStatInfo") + @WebResult(name = "queryResult") + String queryAgencyStatInfo(@WebParam(name = "paramBody") String paramJson); + /** + * 更正单位信息 + * @param paramJson :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 + * @return :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 或者自己需要的实体对象。 + */ + @WebMethod(operationName = "syncAgencyStatInfo") + @WebResult(name = "syncResult") + String syncAgencyStatInfo(@WebParam(name = "paramBody") String paramJson); +} \ No newline at end of file diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyServiceImpl.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyServiceImpl.java new file mode 100644 index 0000000..09be2d3 --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyServiceImpl.java @@ -0,0 +1,64 @@ +package com.rehome.mqttclienttemperature.webservice; + + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import javax.jws.WebService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + + +/** + * 单位信息 webService 远程接口实现 + * 1、@WebService 定义接口为 webservice 服务。 + * * serviceName:对应生成的 WSDL 文件中的 definitions 元素中的 name 属性值,默认以服务类名称+"Service"为值。 + * * targetNamespace:目标名称空间,对应 WSDL 文档的根元素 definition 元素的 targetNameSpace 属性。默认为 "http://" 加 "包名的反写"。 + * * endpointInterface:终端接口,定义服务抽象 WebService 协定的服务端点接口的完整名称,通常设置为服务接口的全路径。 + * @author HuangWenfei + * @version 1.0 + * @date 2025/04/15 13:51 + */ +@Component +@WebService(serviceName = "agencyService", + targetNamespace = "http://webservice.mqttclienttemperature.rehome.com/", + endpointInterface = "com.rehome.mqttclienttemperature.webservice.AgencyService") +public class AgencyServiceImpl implements AgencyService { + private static final Logger log = LoggerFactory.getLogger(AgencyServiceImpl.class); + /** + * 查询单位信息 + * 1、@WebMethod 定义方法为 webservice 方法 + * 2、@WebParam 定义方法参数,用于定义wsdl中的参数映射 + * + * @param paramJson :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象。 + * 如 {"user_id":"4783748PL898878","token":"37483748YU23","user_name":"蚩尤后裔"} + * @return :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 或者自己需要的实体对象 + */ + @Override + public String queryAgencyStatInfo(String paramJson) { + String returnValue; + log.info("查询单位信息-开始-请求参数:\n{}", JSONUtil.toJsonPrettyStr(paramJson)); + System.out.println("根据参数查询数据..."); + returnValue = "{\"reason\":\"加载成功\",\"status_code\":\"1000\",\"data\":{\"msg\":\"查询成功\",\"subSystemName\":\"基础库管理\",\"subSystemCode\":\"bgt-basic-server\",\"tableList\":[{\"tableName\":\"BAS_AGENCY_EXT 单位扩展信息表\",\"tableSize\":560},{\"tableName\":\"BAS_AGENCY_INFO 单位基本信息表\",\"tableSize\":560}],\"sendStatus\":1,\"id\":\"5337a4bc06634e5491588c4fb9019787\"}}"; + JSONObject jsonObject = JSONUtil.parseObj(returnValue); + return jsonObject.toString(); + } + /** + * 更正单位信息 + * 1、@WebMethod 定义方法为 webservice 方法 + * 2、@WebParam 定义方法参数,用于定义wsdl中的参数映射 + * + * @param paramJson :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象。 + * {"user_id":"5543748KH988878","token":"25483748YU98","user_name":"蚩尤后裔"} + * @return :Json 对象字符串,复杂对象统一转成 json 对象字符串进行传输,双方接收后再转成 Json 对象 或者自己需要的实体对象 + */ + @Override + public String syncAgencyStatInfo(String paramJson) { + String returnValue; + log.info("更正单位信息-开始-请求参数:\n{}", JSONUtil.toJsonPrettyStr(paramJson)); + System.out.println("根据参数更正数据..."); + returnValue = "{\"reason\":\"操作成功\",\"status_code\":\"1000\",\"data\":{\"msg\":\"更正成功\",\"subSystemName\":\"基础库管理\",\"subSystemCode\":\"bgt-basic-server\",\"tableList\":[{\"tableName\":\"BAS_AGENCY_EXT 单位扩展信息表\",\"tableSize\":145},{\"tableName\":\"BAS_AGENCY_INFO 单位基本信息表\",\"tableSize\":146}],\"sendStatus\":1,\"id\":\"5337a4bc06634e5491588c4fb9019787\"}}"; + JSONObject jsonObject = JSONUtil.parseObj(returnValue); + return jsonObject.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonService.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonService.java new file mode 100644 index 0000000..17ca078 --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonService.java @@ -0,0 +1,22 @@ +package com.rehome.mqttclienttemperature.webservice; + + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; + + +/** + * ApiCommonService 提供WebService远程接口调用 + * @Description 定义 webservice 接口服务。 + * @author HuangWenfei + * @version 1.0 + * @date 2025/04/16 09:35 + */ +@WebService(targetNamespace = "http://webservice.mqttclienttemperature.rehome.com/") +public interface ApiCommonService { + @WebMethod(operationName = "commonApi") + @WebResult(name = "commonApiResult") + String commonApi(@WebParam(name="param1") String param1,@WebParam(name = "param2") String param2); +} \ No newline at end of file diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonServiceImpl.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonServiceImpl.java new file mode 100644 index 0000000..340ed39 --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonServiceImpl.java @@ -0,0 +1,26 @@ +package com.rehome.mqttclienttemperature.webservice; + + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import javax.jws.WebService; + +/** + * @ClassName ApiServiceImpl + * @Description 测试地址:http://127.0.0.1:8099/ws/ApiCommonService?wsdl + * @Date 2024/6/14 16:52 + * @Version 1.0 + */ +@Component +@WebService(serviceName = "ApiCommonService", + targetNamespace = "http://webservice.mqttclienttemperature.rehome.com/", + endpointInterface = "com.rehome.mqttclienttemperature.webservice.ApiCommonService") +@Slf4j +public class ApiCommonServiceImpl implements ApiCommonService { + + @Override + public String commonApi(String param1,String param2) { + log.info("调用的入参为:"+param1+","+param2); + return "成功"; + } +} \ No newline at end of file diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServiceConfig.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServiceConfig.java new file mode 100644 index 0000000..fd267ee --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServiceConfig.java @@ -0,0 +1,83 @@ +package com.rehome.mqttclienttemperature.webservice; + +import javax.annotation.Resource; +import javax.xml.ws.Endpoint; +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBus; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * WebService 配置类 + * @author HuangWenfei + * @version 1.0 + * @date 2025/04/15 14:21 + */ +@Configuration +public class WebServiceConfig { + private static final Logger log = LoggerFactory.getLogger(WebServiceConfig.class); + /** + * 注入 CXF servlet bean + * 1、bean 名称不能叫 dispatcherServlet,否则会覆盖MVC原本的 dispatcherServlet。 + * 2、指定 webservice 服务访问的路径。所有的服务接口都会在路径下。 + * + * @return + */ + @Bean(name = "cxfServlet") + public ServletRegistrationBean cxfServlet() { + // 注册servlet 拦截 /webservice 开头的请求,不设置时默认为 /services/* + return new ServletRegistrationBean<>(new CXFServlet(), "/webservice/*"); + } + + /** + * 业务处理类,也可以直接在实现类上标注 @Service 注解。 + * @return + */ +// @Bean +// public AgencyService agencyService() { +// return new AgencyServiceImpl(); +// } +// @Bean(name = Bus.DEFAULT_BUS_ID) +// public SpringBus springBus() { +// return new SpringBus(); +// } + + @Resource + private AgencyService agencyService; + @Resource + @Qualifier(Bus.DEFAULT_BUS_ID) + private SpringBus springBus; + + + + /** + * 发布 Web 服务访问端点 + * 1、本方法可以提供多个,用于发布多个访问断点。 + * 2、publish 方法用于开始发布端点,此时端点开始接受传入请求。 + * 3、stop 方法可以用于停止接受传入请求并关闭端点。一旦停止,就无法再次发布终结点。 + * @return http://127.0.0.1:8088/ws/ApiCommonService?wsdl + */ + @Bean + public Endpoint agencyServiceEndpoint() { + // 参数二是SEI实现类对象 + EndpointImpl endpoint = new EndpointImpl(this.springBus, agencyService); + // 发布服务 + //endpoint.publish("/agencyService"); + String simpleName = agencyService.getClass().getSimpleName(); + log.info("simpleName:{}",simpleName); + //如果有Impl结尾的类名,去掉Impl + if (simpleName.endsWith("Impl")) { + simpleName = simpleName.substring(0, simpleName.length() - 4); + } + log.info("simpleName:{}",simpleName); + endpoint.publish("/"+simpleName); + return endpoint; + } + +} \ No newline at end of file diff --git a/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServicePublishConfig.java b/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServicePublishConfig.java new file mode 100644 index 0000000..64d387f --- /dev/null +++ b/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServicePublishConfig.java @@ -0,0 +1,58 @@ +package com.rehome.mqttclienttemperature.webservice; + + + + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBus; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.Resource; +import javax.xml.ws.Endpoint; +import java.util.ArrayList; +import java.util.List; + + +/** + * @ClassName WebServicePublishConfig + * @Description + * @Date 2024/6/14 16:57 + * @Version 1.0 + */ +@Configuration +public class WebServicePublishConfig { + @Bean + public ServletRegistrationBean wsServlet(){ + return new ServletRegistrationBean(new CXFServlet(),"/ws/*"); + } + + @Resource + private ApiCommonService apiCommonService; + @Resource + private List apiServices; + @Resource + @Qualifier(Bus.DEFAULT_BUS_ID) + private SpringBus bus; + + //http://127.0.0.1:8873/ws/ApiCommonService?wsdl + //http://127.0.0.1:8873/ws/ + @Bean + public Endpoint[] endPoint(){ + List endpointList = new ArrayList<>(apiServices.size()); + EndpointImpl endpoint = new EndpointImpl(bus, apiCommonService); + String simpleName = apiCommonService.getClass().getSimpleName(); + //如果有Impl结尾的类名,去掉Impl + if (simpleName.endsWith("Impl")) { + simpleName = simpleName.substring(0, simpleName.length() - 4); + } + endpoint.publish("/"+simpleName); + endpointList.add(endpoint); + return endpointList.toArray(new Endpoint[0]); + } + +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 47cb64f..ae867be 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,10 +8,10 @@ spring: # username: sa # password: Skyinno251, #url: jdbc:mysql://192.168.1.21:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true - #url: jdbc:mysql://127.0.0.1:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true + url: jdbc:mysql://127.0.0.1:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #url: jdbc:mysql://192.168.2.18:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #url: jdbc:mysql://192.168.1.24:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true - url: jdbc:mysql://192.168.3.7:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true + #url: jdbc:mysql://192.168.3.7:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #url: jdbc:mysql://192.168.3.7:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #url: jdbc:mysql://192.168.1.24:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #url: jdbc:mysql://47.242.184.139:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true