com.github.dennisit.vplus.data.interceptor.AppletInterceptor Maven / Gradle / Ivy
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.data.interceptor;
import com.github.dennisit.vplus.data.utils.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by Elon.su on 17/10/6.
*/
public class AppletInterceptor extends HandlerInterceptorAdapter {
private static final Logger LOG = LoggerFactory.getLogger(AppletInterceptor.class);
public static final String APP_KEY = DigestUtils.md5Hex("APP_KEY");
public static final String VERSION_KEY = DigestUtils.md5Hex("APP_VERSION");
/**
* 应用标识
*/
private String appKey;
/**
* 应用版本
*/
private String version;
/**
* 应用拦截器
*/
public AppletInterceptor() {
}
public AppletInterceptor(String appKey, String version) {
this.appKey = appKey;
this.version = version;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
request.setAttribute(AppletInterceptor.APP_KEY, appKey);
request.setAttribute(AppletInterceptor.VERSION_KEY, version);
LOG.debug("[Applet] [AppKey:{}] [Version:{}]", this.appKey, this.version);
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public void setVersion(String version) {
this.version = version;
}
}