package com.jianshui.api.config;

// import com.jianshui.api.controller.webservice.income.v1.InvoiceCheckWebService;

import com.jianshui.api.controller.webservice.income.v1.impl.InvoiceCheckWebServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.apache.cxf.jaxws.EndpointImpl;

import javax.xml.ws.Endpoint;
import javax.xml.ws.handler.soap.SOAPHandler;

@Configuration
public class WebServiceConfig {

    // @Autowired
    // private InvoiceCheckWebService invoiceCheckWebService;

    @Autowired
    private InvoiceCheckWebServiceImpl invoiceCheckWebService;

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

    @Bean
    public WebserviceResponseHandler webserviceResponseHandler() {
        return new WebserviceResponseHandler();
    }

    @Bean
    public Endpoint endpoint() {
        // EndpointImpl endpoint = new EndpointImpl(springBus(), invoiceCheckWebService);
        EndpointImpl endpoint = new EndpointImpl(springBus(), invoiceCheckWebService);
        WebserviceResponseHandler webserviceResponseHandler = webserviceResponseHandler();
        endpoint.getHandlers().add(webserviceResponseHandler);
        endpoint.publish("/income/v1/check");
        return endpoint;
    }

}
