001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.metrics.aspects.request;
018
019import javax.servlet.http.HttpServletRequest;
020
021import org.apache.wicket.metrics.WicketMetrics;
022import org.aspectj.lang.ProceedingJoinPoint;
023import org.aspectj.lang.annotation.Around;
024import org.aspectj.lang.annotation.Aspect;
025
026/**
027 * Aspect to measure request url time
028 * 
029 * @author Tobias Soloschenko
030 */
031@Aspect
032public class WicketFilterRequestCycleUrlAspect extends WicketMetrics
033{
034        /**
035         * Collects data how often a request has been made against the webapp and counts the time how
036         * long the request took. Measures the information with the request url
037         * 
038         * @param joinPoint
039         *            the joinPoint to be proceed
040         * @return returns the boolean of the processRequest method
041         * 
042         * @throws Throwable
043         *             might occur while invoking process request
044         */
045        @Around("execution(* org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(..))")
046        public Object aroundRequestProcessedWithURL(ProceedingJoinPoint joinPoint) throws Throwable
047        {
048                Object[] args = joinPoint.getArgs();
049                if (args.length >= 3)
050                {
051                        Object requestAsObject = args[2];
052                        if (requestAsObject != null && requestAsObject instanceof HttpServletRequest)
053                        {
054                                HttpServletRequest httpServletRequest = (HttpServletRequest)requestAsObject;
055                                String requestUrl = httpServletRequest.getRequestURL().toString();
056                                String replacedUrl = requestUrl.replace('/', '_');
057                                replacedUrl = replacedUrl.replace('.', '_');
058                                replacedUrl = replacedUrl.replaceAll(";jsessionid=.*?(?=\\?|$)", "");
059                                return measureTime("core/application/request/" + replacedUrl, joinPoint, false);
060                        }
061                }
062                return joinPoint.proceed();
063        }
064}