Commit 8cb4ddc4 authored by Matija Obreza's avatar Matija Obreza

Track last HTTP GET request

parent 22c986cc
......@@ -19,6 +19,7 @@ package org.genesys2.spring;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
......@@ -27,6 +28,9 @@ import org.springframework.web.servlet.ModelAndView;
@Component
public class AddStuffInterceptor implements HandlerInterceptor {
@Autowired
private RequestTracker requestTracker;
@Value("${build.name}")
private String buildName;
......@@ -44,6 +48,7 @@ public class AddStuffInterceptor implements HandlerInterceptor {
final long endTime = System.currentTimeMillis();
final long executeTime = endTime - startTime;
arg0.setAttribute("springExecuteTime", executeTime);
arg0.setAttribute("lastGet", requestTracker.getLastGet());
}
@Override
......
package org.genesys2.spring;
import java.io.Serializable;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "session")
public class RequestTracker implements Serializable {
private String lastGet;
public String getLastGet() {
return lastGet;
}
public void setLastGet(String lastGet) {
this.lastGet = lastGet;
}
}
/**
* 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.genesys2.spring;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class RequestTrackingInterceptor implements HandlerInterceptor {
private static final Log LOG = LogFactory.getLog(RequestTrackingInterceptor.class);
@Autowired
private RequestTracker requestTracker;
@Override
public void afterCompletion(HttpServletRequest req, HttpServletResponse res, Object x, Exception e) throws Exception {
if (e == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Examining last request " + req.getMethod() + " " + req.getServletPath() + " req=" + req.getContentType() + " respo="
+ res.getHeader(HttpHeaders.CONTENT_TYPE));
}
String ct = res.getHeader(HttpHeaders.CONTENT_TYPE);
if ("GET".equals(req.getMethod()) && ct != null && ct.toLowerCase().startsWith("text/html")) {
if (LOG.isInfoEnabled()) {
LOG.info("Recording last GET request " + req.getServletPath() + "?" + req.getQueryString());
}
requestTracker.setLastGet(req.getServletPath() + (req.getQueryString() == null ? "" : "?" + req.getQueryString()));
}
}
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView modelAndView) throws Exception {
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
return true;
}
}
......@@ -16,25 +16,35 @@
package org.genesys2.spring.config;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import org.genesys2.spring.AddStuffInterceptor;
import org.genesys2.spring.RequestAttributeLocaleResolver;
import org.genesys2.spring.RequestTrackingInterceptor;
import org.genesys2.spring.validation.oval.spring.SpringOvalValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.Validator;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
import org.springframework.web.servlet.theme.CookieThemeResolver;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
@Import({ SpringProperties.class })
@EnableWebMvc
@EnableAspectJAutoProxy
......@@ -47,6 +57,9 @@ public class SpringServletConfig extends WebMvcConfigurerAdapter {
@Autowired
private AddStuffInterceptor addStuffInterceptor;
@Autowired
private RequestTrackingInterceptor requestTrackingInterceptor;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
......@@ -77,6 +90,7 @@ public class SpringServletConfig extends WebMvcConfigurerAdapter {
themeChangeInterceptor.setParamName("theme");
registry.addInterceptor(themeChangeInterceptor);
registry.addInterceptor(requestTrackingInterceptor);
registry.addInterceptor(addStuffInterceptor);
}
......
......@@ -27,7 +27,9 @@
</div>
<div class="pull-right">
<div class="pull-left" style="text-align: right; color: #808080; font-family: monospace; font-size: 8px;"><spring:message code="page.rendertime" arguments="${springExecuteTime}" />
<br /><a target="_blank" href="https://bitbucket.org/genesys2/genesys2-server/commits/${buildRevision}">${buildName}</a></div>
<br /><a target="_blank" href="https://bitbucket.org/genesys2/genesys2-server/commits/${buildRevision}">${buildName}</a>
<%-- <br />${lastGet} --%>
</div>
</div>
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment