Search in sources :

Example 1 with ApiWebService

use of com.netsteadfast.greenstep.bsc.webservice.ApiWebService in project bamboobsc by billchen198318.

the class ApiRouteBuilder method configure.

@Override
public void configure() throws Exception {
    this.from("servlet:///api").process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            String format = StringUtils.defaultString(exchange.getIn().getHeader("format", String.class)).trim().toLowerCase();
            String visionOid = StringUtils.defaultString(exchange.getIn().getHeader("visionOid", String.class)).trim().toLowerCase();
            String startDate = StringUtils.defaultString(exchange.getIn().getHeader("startDate", String.class)).trim().toLowerCase();
            String endDate = StringUtils.defaultString(exchange.getIn().getHeader("endDate", String.class)).trim().toLowerCase();
            String startYearDate = StringUtils.defaultString(exchange.getIn().getHeader("startYearDate", String.class)).trim().toLowerCase();
            String endYearDate = StringUtils.defaultString(exchange.getIn().getHeader("endYearDate", String.class)).trim().toLowerCase();
            String frequency = StringUtils.defaultString(exchange.getIn().getHeader("frequency", String.class)).trim().toLowerCase();
            String dataFor = StringUtils.defaultString(exchange.getIn().getHeader("dataFor", String.class)).trim().toLowerCase();
            String measureDataOrganizationOid = StringUtils.defaultString(exchange.getIn().getHeader("measureDataOrganizationOid", String.class)).trim().toLowerCase();
            String measureDataEmployeeOid = StringUtils.defaultString(exchange.getIn().getHeader("measureDataEmployeeOid", String.class)).trim().toLowerCase();
            String contentFlag = StringUtils.defaultString(exchange.getIn().getHeader("contentFlag", String.class)).trim().toUpperCase();
            String responseContent = "";
            // 請參考 gsbsc-web applicationContext-STANDARD-CXF.xml
            ApiWebService apiWebService = (ApiWebService) AppContext.getBean("bsc.webservice.ApiWebService");
            BscApiServiceResponse responseObj = apiWebService.getScorecard1(visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid, contentFlag);
            if ("xml".equals(format)) {
                // xml
                XStream xstream = new XStream();
                xstream.setMode(XStream.NO_REFERENCES);
                xstream.alias("response", BscApiServiceResponse.class);
                responseContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xstream.toXML(responseObj);
            } else {
                // json
                ObjectMapper mapper = new ObjectMapper();
                responseContent = mapper.writeValueAsString(responseObj);
            }
            exchange.getOut().setBody(responseContent);
        }
    }).to("stream:out");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ApiWebService(com.netsteadfast.greenstep.bsc.webservice.ApiWebService) BscApiServiceResponse(com.netsteadfast.greenstep.bsc.vo.BscApiServiceResponse) XStream(com.thoughtworks.xstream.XStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BscApiServiceResponse (com.netsteadfast.greenstep.bsc.vo.BscApiServiceResponse)1 ApiWebService (com.netsteadfast.greenstep.bsc.webservice.ApiWebService)1 XStream (com.thoughtworks.xstream.XStream)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1