All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xceptance.xlt.api.engine.RequestFilter Maven / Gradle / Ivy

Go to download

XLT (Xceptance LoadTest) is an extensive load and performance test tool developed and maintained by Xceptance.

There is a newer version: 8.1.0
Show newest version
package com.xceptance.xlt.api.engine;

import java.net.URL;
import java.util.regex.Pattern;

import com.gargoylesoftware.htmlunit.WebRequest;

/**
 * Request filter.
* Used to get filtered data from {@link NetworkDataManager}. Currently, filtering is restricted to the request's URL. * * @author Matthias Ullrich (Xceptance Software Technologies GmbH) */ public class RequestFilter { private String protocol = null; private String hostPattern = null; private int port = -1; private String pathPattern = null; private String queryPattern = null; private String urlPattern; /** * Request protocol of the wanted request * * @return request protocol of the wanted request */ public String getProtocol() { return protocol; } /** * Request protocol (http, https, ...) * * @param protocol * the wanted request's protocol or null to disable protocol filtering */ public void setProtocol(final String protocol) { this.protocol = protocol; } /** * Regular expression to match the host of the wanted request * * @return regular expression to match the host or null if no host filter is set */ public String getHostPattern() { return hostPattern; } /** * Regular expression the matches the wanted request's host * * @param regex * regular expression the matches the wanted request's host or null to disable host * filtering */ public void setHostPattern(final String regex) { hostPattern = regex; } /** * Port number * * @return port number of the wanted request or -1 if no port filter is set */ public int getPort() { return port; } /** * Port number of the wanted request * * @param port * port number of the wanted request or -1 to disable port filtering */ public void setPort(final int port) { this.port = port; } /** * Path pattern * * @return regular expression that matches the wanted request's path or null if path filtering is * disabled */ public String getPathPattern() { return pathPattern; } /** * Path pattern * * @param regex * regular expression that matches the wanted request's path or null to disable path * filtering */ public void setPathPattern(final String regex) { pathPattern = regex; } /** * Query Pattern * * @return regular expression that matches the wanted request's query string or null if query filtering * is disabled */ public String getQueryPattern() { return queryPattern; } /** * Query pattern * * @param regex * regular expression that matches the wanted request's query string or null if query * filtering is disabled */ public void setQueryPattern(final String regex) { queryPattern = regex; } /** * URL Pattern If the URL pattern is set this overrides all other filters. * * @return regular expression that matches the wanted request's URL string or null if URL filtering is * disabled */ public String getUrlPattern() { return urlPattern; } /** * URL Pattern If the URL pattern is set this overrides all other filters. * * @param regex * regular expression that matches the wanted request's URL string or null to disable URL * filtering */ public void setUrlPattern(final String regex) { urlPattern = regex; } /** * Returns whether or not the this filter accepts the given request. * * @param request * the request to be checked * @return true if this filter accepts the given request, false otherwise */ public boolean accepts(final WebRequest request) { if (request == null) { return false; } /* * Check if request URL matches. */ final URL url = request.getUrl(); if (urlPattern != null) { return Pattern.matches(urlPattern, url.toString()); } // check protocol, host, port, path and query consecutively if (protocol != null && !url.getProtocol().equalsIgnoreCase(protocol)) { return false; } if (hostPattern != null && !Pattern.matches(hostPattern, url.getHost())) { return false; } if (port > 0 && port != url.getPort()) { return false; } if (pathPattern != null && !Pattern.matches(pathPattern, url.getPath())) { return false; } if (queryPattern != null && !Pattern.matches(queryPattern, url.getQuery())) { return false; } return true; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy