添加WebService

oracle
wenfei 8 months ago
parent 3f6d189d81
commit 35849f4fbc

@ -5,7 +5,18 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="eacd3dd8-1e95-428c-a6af-1aadb9921989" name="Default Changelist" comment=""> <list default="true" id="eacd3dd8-1e95-428c-a6af-1aadb9921989" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/task/AgencyTask.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/utils/WebServiceUtils.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/AgencyServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/ApiCommonServiceImpl.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServiceConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServicePublishConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/rehome/mqttclienttemperature/AdminClientTemperatureApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/application.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.yml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -30,28 +41,32 @@
<component name="MavenRunner"> <component name="MavenRunner">
<option name="skipTests" value="true" /> <option name="skipTests" value="true" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 0
}]]></component>
<component name="ProjectId" id="2SgLAAD7fmKYxLWgfQc7MNYMQRi" /> <component name="ProjectId" id="2SgLAAD7fmKYxLWgfQc7MNYMQRi" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">
"keyToString": { <property name="RequestMappingsPanelOrder0" value="0" />
"RunOnceActivity.OpenProjectViewOnStart": "true", <property name="RequestMappingsPanelOrder1" value="1" />
"RunOnceActivity.ShowReadmeOnStart": "true", <property name="RequestMappingsPanelWidth0" value="75" />
"WebServerToolWindowFactoryState": "false", <property name="RequestMappingsPanelWidth1" value="75" />
"vue.rearranger.settings.migration": "true" <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
} <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
}]]></component> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.last.edited" value="SDKs" />
<property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/main/resources/ssl" /> <recent name="$PROJECT_DIR$/src/main/resources/ssl" />
</key> </key>
<key name="CopyClassDialog.RECENTS_KEY"> <key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.rehome.mqttclienttemperature.webservice" />
<recent name="com.rehome.mqttclienttemperature.utils" />
<recent name="com.rehome.mqttclienttemperature.task" />
<recent name="com.rehome.mqttclienttemperature.controller.api" /> <recent name="com.rehome.mqttclienttemperature.controller.api" />
</key> </key>
</component> </component>
@ -124,6 +139,11 @@
<workItem from="1737893859369" duration="553000" /> <workItem from="1737893859369" duration="553000" />
<workItem from="1739253198003" duration="10000" /> <workItem from="1739253198003" duration="10000" />
<workItem from="1740888797352" duration="83000" /> <workItem from="1740888797352" duration="83000" />
<workItem from="1744771655739" duration="2866000" />
<workItem from="1744774685514" duration="882000" />
<workItem from="1744792532086" duration="1668000" />
<workItem from="1744794454586" duration="20000" />
<workItem from="1744794979826" duration="1104000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -140,5 +160,6 @@
</entry> </entry>
</map> </map>
</option> </option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
</project> </project>

@ -151,6 +151,59 @@
<version>1.11</version> <version>1.11</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.37</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
<version>5.8.37</version>
</dependency>
<!--webservice + CXF .../start.......-->
<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.3.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--webservice + CXF .../end.......-->
<!-- <dependency>-->
<!-- <groupId>org.apache.axis2</groupId>-->
<!-- <artifactId>axis2-kernel</artifactId>-->
<!-- <version>2.0.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.axis2</groupId>-->
<!-- <artifactId>axis2-ant-plugin</artifactId>-->
<!-- <version>2.0.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-corba</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-spring</artifactId>
<version>1.8.2</version>
</dependency>
<!--webservice 第三方库axis2 maven引用 end-->
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

@ -11,6 +11,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -19,6 +20,7 @@ import java.util.Map;
@EnableJpaAuditing @EnableJpaAuditing
@EnableScheduling @EnableScheduling
@EnableAsync
@SpringBootApplication @SpringBootApplication
public class AdminClientTemperatureApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationContextAware { public class AdminClientTemperatureApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationContextAware {

@ -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<String, String> paramsMap = new HashMap();
// paramsMap.put("user_id", "4783748PL898878");
// paramsMap.put("token", "37483748YU23");
// paramsMap.put("user_name", "371522");
//
// Map<String, String> 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<String, String> paramsMap = new HashMap();
paramsMap.put("user_id", "4783748PL898878");
paramsMap.put("token", "37483748YU23");
paramsMap.put("user_name", "371522");
Map<String, String> 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<String, String> 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();
}
}
}

@ -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<String, String> 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<String, String> 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<String, String> 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<NamedValue> 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文件的命名空间名也就是<wsdl:definitions>元素的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<String, String> paramsMap, Object[] object) {
int index = 0;
for (Map.Entry<String, String> params : paramsMap.entrySet()) {
String value = params.getValue();
object[index] = value;
index++;
}
return object;
}
}

@ -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便 arg0arg1 ...
* 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);
}

@ -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();
}
}

@ -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);
}

@ -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 "成功";
}
}

@ -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
* 1bean dispatcherServletMVC dispatcherServlet
* 2 webservice 访
*
* @return
*/
@Bean(name = "cxfServlet")
public ServletRegistrationBean<CXFServlet> 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访
* 2publish
* 3stop
* @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;
}
}

@ -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<ApiCommonService> 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<Endpoint> 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]);
}
}

@ -8,10 +8,10 @@ spring:
# username: sa # username: sa
# password: Skyinno251, # password: Skyinno251,
#url: jdbc:mysql://192.168.1.21:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true #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.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.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.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://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 #url: jdbc:mysql://47.242.184.139:3306/appserver?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true

Loading…
Cancel
Save