You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
admin-client-temperature/src/main/java/com/rehome/mqttclienttemperature/webservice/WebServicePublishConfig.java

58 lines
1.7 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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