CXFConfig.java 5.38 KB
package com.bsth;

import com.bsth.server_rs.AuthorizeInterceptor_IN;
import com.bsth.server_rs.base_info.car.CarRestService;
import com.bsth.server_rs.base_info.line.LineRestService;
import com.bsth.server_rs.base_info.person.PersonRestService;
import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;
import com.bsth.server_rs.base_info.section.LD_SectionRestService;
import com.bsth.server_rs.base_info.station.StationRestService;
import com.bsth.server_rs.bigdata.BigdateService;
import com.bsth.server_rs.directive.DirectiveRestService;
import com.bsth.server_rs.electric.ElectricService;
import com.bsth.server_rs.exception.AesExceptionMapper;
import com.bsth.server_rs.gps.GpsRestService;
import com.bsth.server_rs.logs.RealLogRestService;
import com.bsth.server_rs.schedule.plan.SchedulePlanService;
import com.bsth.server_rs.schedule.real.ScheduleRealService;
import com.bsth.server_rs.schedule.real.StaffViewRealService;
import com.bsth.server_ws.attendance.AttendanceServiceSoap;
import com.bsth.server_ws.electric_oil.OilServiceSoap;
import com.bsth.server_ws.park_station.CompanyServiceSoap;
import com.bsth.server_ws.waybill.LD_ServiceSoap;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import javax.xml.ws.Endpoint;
import java.util.Arrays;

/**
 * Created by panzhao on 2017/3/9.
 */
@Configuration
public class CXFConfig {

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

    @Autowired
    CompanyServiceSoap companyServiceSoap;
    @Autowired
    LD_ServiceSoap ld_serviceSoap;
    @Autowired
    AttendanceServiceSoap attendanceServiceSoap;
    @Autowired
    OilServiceSoap oilServiceSoap;

    @Bean
    public Endpoint companyEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);
        endpoint.publish("/CompanyService");
        //endpoint.getInInterceptors().add(new AuthInterceptor());
        return endpoint;
    }

    @Bean
    public Endpoint ldServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);
        endpoint.publish("/LD_Service");
        //endpoint.getInInterceptors().add(new AuthInterceptor());
        return endpoint;
    }

    @Bean
    public Endpoint attendanceServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);
        endpoint.publish("/attendanceService");
        //endpoint.getInInterceptors().add(new AuthInterceptor());
        return endpoint;
    }

    @Bean
    public Endpoint electricServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);
        endpoint.publish("/oilServiceSoap");
        //endpoint.getInInterceptors().add(new AuthInterceptor());
        return endpoint;
    }

    @Autowired
    ScheduleRealService scheduleRealService;
    @Autowired
    StationRestService stationRestService;
    @Autowired
    LD_SectionRestService ldSectionRestService;
    @Autowired
    SchedulePlanService schedulePlanService;
    @Autowired
    RealLogRestService realLogRestService;
    @Autowired
    GpsRestService gpsRestService;
    @Autowired
    DirectiveRestService directiveRestService;
    @Autowired
    LD_RoadSpeedRestService ld_roadSpeedRestService;
    @Autowired
    ElectricService electricService;
    @Autowired
    BigdateService bigdateService;
    @Autowired
    StaffViewRealService staffViewRealService;

    @Bean
    public Server rsServer() {
        JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setBus(springBus());
        endpoint.setAddress("/rest");
        endpoint.setServiceBeans(Arrays.<Object>asList(
                new LineRestService(),
                new CarRestService(),
                new PersonRestService(),
                gpsRestService,
                scheduleRealService,
                stationRestService,
                ldSectionRestService,
                schedulePlanService,
                realLogRestService,
                directiveRestService,
                ld_roadSpeedRestService,
                electricService,
                staffViewRealService,
                bigdateService));
        
        endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
        //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
        endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
        return endpoint.create();
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
        bean.setLoadOnStartup(0);
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return bean;
    }
}