package com.docus.server;


import com.docus.server.reportmanager.webservice.ReportManagerService;
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.Autowired;
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.xml.ws.Endpoint;

@Configuration
public class CxfConfig {
    @Autowired
    @Qualifier("YdZyyReportManagerService")
    private ReportManagerService reportManagerService;

    /**
     * 注入Servlet，注意beanName不能为dispatcherServlet
     *
     * @author Fang Ruichuan
     * @date 2022/11/14 19:16
     */
    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/wzhws/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    @Qualifier("reportEndPoint")
    public Endpoint reportEndPoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), reportManagerService);
        endpoint.publish("/report");
        return endpoint;
    }

}
