package com.docus.server;

import com.docus.server.collect.IWebServiceServer;
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;

//@ConditionalOnProperty(name = "docus.dispose.mode", havingValue = DisposeModeEnum.redis)
@Configuration
public class CxfConfig {
    @Resource
    private IWebServiceServer webserviceServer;

    /**
     * 注入Servlet，注意beanName不能为dispatcherServlet
     */
    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
    }

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

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