Java tutorial
/** * Copyright (c) 2016, Stupid Bird and/or its affiliates. All rights reserved. * STUPID BIRD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * @Project : parent * @Package : com.easarrive.image.thumbor.executer.controller * @author <a href="http://www.lizhaoweb.net">??(John.Lee)</a> * @EMAIL 404644381@qq.com * @Time : 23:18 */ package com.easarrive.image.thumbor.executer.controller; import com.easarrive.datasource.redis.etago.model.ThumborConfigure; import com.easarrive.image.thumbor.ConfigureFactory; import com.easarrive.image.thumbor.bean.ThumborConfigureMap; import com.easarrive.image.thumbor.executer.service.IThumborConfigureService; import lombok.Setter; import net.lizhaoweb.common.util.base.Constant; import net.lizhaoweb.common.util.base.StringUtil; import net.lizhaoweb.spring.mvc.core.bean.DataDeliveryWrapper; import net.lizhaoweb.spring.mvc.core.controller.AbstractController; import org.apache.commons.codec.digest.DigestUtils; import org.apache.http.HttpStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; /** * @author <a href="http://www.lizhaoweb.cn">??(John.Lee)</a> * @version 1.0.0.0.1 * @notes Created on 20160816<br> * Revision of last commit:$Revision$<br> * Author of last commit:$Author$<br> * Date of last commit:$Date$<br> * */ @RequestMapping("/thumbor/configure") public class ThumborConfigureController extends AbstractController { protected Logger logger = LoggerFactory.getLogger(this.getClass()); private final static String MODEL = "thumbor/configure"; @Setter private IThumborConfigureService service; /** * ? * * @param forward ? * @return */ @RequestMapping("/show/{forward}") public ModelAndView show(@PathVariable("forward") String forward) { String forwardS = String.format("/%s/%s", MODEL, forward); ModelAndView view = new ModelAndView(forwardS, "bean", new ThumborConfigure()); return view; } /** * @param request * @param response ? * @param model ? * @param bean * @param result ? * @return */ @RequestMapping(value = "/save", method = { RequestMethod.POST }) public String save(HttpServletRequest request, HttpServletResponse response, ModelMap model, @ModelAttribute("bean") @Valid ThumborConfigure bean, BindingResult result) { System.out.println(bean); // if (!result.hasErrors()) { // service.save(bean); // } return String.format("/%s/save", MODEL); } /** * ?? * * @param request * @param response ? * @return ?? */ @RequestMapping(value = "/reload", method = { RequestMethod.POST }) @ResponseBody public DataDeliveryWrapper<Boolean> reloadConfig(HttpServletRequest request, HttpServletResponse response) { //?? String acceptEncoding = this.getAcceptEncoding(request); try { String version = request.getHeader("VERSION"); String sign = request.getHeader("DATA_SIGN"); String charset = request.getHeader("CHARSET"); //?? String dataJson = this.getRequestBody(request); //? if (StringUtil.isEmpty(charset)) { charset = request.getCharacterEncoding(); } if (StringUtil.isEmpty(charset)) { charset = Constant.Charset.UTF8; } // if (StringUtil.isEmpty(version)) { return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_NOT_FOUND, this.encode("", acceptEncoding), false); } else if (!"1.0.0.0.1".equals(version)) { return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_NOT_FOUND, this.encode("??", acceptEncoding), false); } else if (StringUtil.isEmpty(sign)) { return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_NOT_FOUND, this.encode("??", acceptEncoding), false); } else if (StringUtil.isEmpty(dataJson)) { return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_NOT_FOUND, this.encode("?", acceptEncoding), false); } String signTemp = DigestUtils.md5Hex(dataJson); if (!sign.equals(signTemp)) { return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_FORBIDDEN, this.encode("??", acceptEncoding), false); } ConfigureFactory.clear(); // ThumborConfigure configure = ConfigureFactory.getConfigure(); // if (logger.isInfoEnabled()) { // logger.info("?? {}", configure); // } ThumborConfigureMap configureMap = ConfigureFactory.getConfigureMap(); if (logger.isInfoEnabled()) { logger.info("?? {}", configureMap); } return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_OK, this.encode("Thumbor ???", acceptEncoding), true); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("Thumbor ?", e); } return new DataDeliveryWrapper<Boolean>(HttpStatus.SC_INTERNAL_SERVER_ERROR, this.encode("Thumbor ??", acceptEncoding), false); } } }