AddStuffInterceptor.java
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.gringlobal.spring;
import java.time.LocalDate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class AddStuffInterceptor implements HandlerInterceptor, InitializingBean {
// @Autowired
// private RequestTracker requestTracker;
@Value("${build.name}")
private String buildName;
@Value("${build.revision}")
private String buildRevision;
@Value("${build.version}")
private String buildVersion;
@Value("${base.url}")
private String baseUrl;
@Override
public void afterPropertiesSet() throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception {
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView modelAndView) throws Exception {
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
request.setAttribute("buildName", buildName);
request.setAttribute("buildRevision", buildRevision);
request.setAttribute("buildVersion", buildVersion);
request.setAttribute("baseUrl", baseUrl);
request.setAttribute("currentYear", LocalDate.now().getYear());
return true;
}
}