|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjetbrains.buildServer.web.util.WebUtil
public class WebUtil
Utility class containing various useful methods for web controllers
| Nested Class Summary | |
|---|---|
static interface |
WebUtil.ParameterFilter
Query string parameters filter |
| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_WEB_DATE_FORMAT
|
static java.lang.String |
GUEST_AUTH_PREFIX
|
static java.lang.String |
HTTP_AUTH_PREFIX
|
| Method Summary | |
|---|---|
static void |
addCacheHeadersForIE(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Fixes IE problem when it cannot download files over https (see TW-9821). |
static java.lang.String |
combineContextPath(java.lang.String prefixPath,
java.lang.String path)
Combines two path with prefix with regard to starting and trailing slashes. |
static javax.servlet.http.Cookie |
createCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String value,
int age)
Creates a cookie with specified age |
static java.lang.String |
createPathWithParameters(javax.servlet.http.HttpServletRequest request)
Same as createPathWithParameters(javax.servlet.http.HttpServletRequest, jetbrains.buildServer.web.util.WebUtil.ParameterFilter)
with default filter which accepts all parameters. |
static java.lang.String |
createPathWithParameters(javax.servlet.http.HttpServletRequest request,
WebUtil.ParameterFilter filter)
From specified request creates part of the URL which contains path and query string. |
static javax.servlet.http.Cookie |
createSessionCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String value)
Creates session cookie (such cookie will be removed when browser exits). |
static java.lang.String |
decode(java.lang.String string)
Decodes specified string using URL encoding. |
static void |
dumpRequest(javax.servlet.http.HttpServletRequest request,
java.io.PrintStream out)
Dumps request information to the specified print stream |
static java.lang.String |
encode(java.lang.String string)
Encodes specified string using URL encoding. |
static java.lang.String |
escapeForJavaScript(java.lang.String text,
boolean removeLineFeeds,
boolean forHTMLAttribute)
Escapes text so that it can be used in JavaScript string. |
static java.lang.String |
escapeForJavaScriptIdentifier(java.lang.String text)
Escapes string to be a javascrip identifier |
static java.lang.String |
escapeUrlForQuotes(java.lang.String url)
Fixes security issues related to passing the URLs (or URL parts) to the quoted context as is. |
static java.lang.String |
escapeXml(java.lang.String text)
Replaces some characters like < > and others in the text with corresponding XML entities. |
static java.lang.String |
firstLine(java.lang.String text)
Return first line of a multiline text. |
static java.lang.String |
getFilename(SBuild build)
Create filename candidate from build information, including project name and build type name and build number |
static java.lang.String |
getMimeType(javax.servlet.http.HttpServletRequest request,
java.lang.String relativePath)
|
static java.lang.String |
getOriginalPathWithoutAuthenticationType(javax.servlet.http.HttpServletRequest request)
Returns original path without authntication types. |
static java.lang.String |
getOriginalPathWithoutContext(javax.servlet.http.HttpServletRequest request)
Returns path part of the request URL without context path. |
static java.lang.String |
getPathFromUrl(java.lang.String url)
Return path without session id and parameters |
static java.lang.String |
getPathWithoutAuthenticationType(javax.servlet.http.HttpServletRequest request)
Returns path without context and TeamCity specific authentication types, like httpAuth or guestAuth prefixes. |
static java.lang.String |
getPathWithoutAuthenticationType(java.lang.String path)
Returns path without context and TeamCity specific authentication types, like httpAuth or guestAuth prefixes. |
static java.lang.String |
getPathWithoutContext(javax.servlet.http.HttpServletRequest request)
Returns path part of the request URL without context path. |
static java.lang.String |
getPathWithoutContext(javax.servlet.http.HttpServletRequest request,
java.lang.String reqURI)
Returns path part of the request URL without context path. |
static java.lang.String |
getRequestDump(javax.servlet.http.HttpServletRequest request)
Returns dump of a request as string. |
static java.lang.String |
getRootUrl(javax.servlet.http.HttpServletRequest request)
Reconstructs root URL from the specified request. |
static java.lang.String |
getUserAgent(javax.servlet.http.HttpServletRequest request)
|
static boolean |
isAbsolute(java.lang.String url)
Returns true if url is not relative, i.e. |
static boolean |
isIE(javax.servlet.http.HttpServletRequest request)
Returns true if the request's client is MSIE. |
static boolean |
isJspPath(java.lang.String path)
Returns true if the specified path taken from the HTTP request points to JSP |
static boolean |
isProbablyBrowser(javax.servlet.http.HttpServletRequest request)
Returns true if user agent header specified in the request indicates that request was sent from a commonly known browser |
static void |
logRequestWarn(java.lang.String message,
java.lang.Exception e,
javax.servlet.http.HttpServletRequest request,
com.intellij.openapi.diagnostic.Logger log)
Logs warning that occurred during request processing. |
static java.lang.String |
makeBreakable(java.lang.String source,
java.lang.String regexp)
Makes the text breakable in HTML by replacing some places of the string with <wbr/> tags . |
static void |
notFound(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String errorString,
com.intellij.openapi.diagnostic.Logger log)
Generates 404 Not Found response and logs specified message into the specified logger |
static void |
setContentDisposition(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String fileName)
Sets the proper "Content-Disposition" response header. |
static void |
setContentDisposition(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String fileName,
boolean canBeInline)
Sets the proper "Content-Disposition" response header. |
static void |
setMimeType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String relativePath)
Computes MIME type for the file located by the specified relative path and sets it into the response. |
static java.lang.String |
truncateStringValueWithDotsInTheMiddle(java.lang.String str,
int maxLength)
Truncates string by cutting the middle part if string length exceeds specified max length. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String HTTP_AUTH_PREFIX
public static final java.lang.String GUEST_AUTH_PREFIX
public static final java.lang.String DEFAULT_WEB_DATE_FORMAT
| Method Detail |
|---|
@NotNull
public static java.lang.String getPathWithoutContext(@NotNull
javax.servlet.http.HttpServletRequest request)
request - request
getOriginalPathWithoutContext(javax.servlet.http.HttpServletRequest)
public static java.lang.String getOriginalPathWithoutContext(@NotNull
javax.servlet.http.HttpServletRequest request)
request - request
getPathWithoutContext(javax.servlet.http.HttpServletRequest)
@NotNull
public static java.lang.String getPathWithoutContext(@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
java.lang.String reqURI)
request - requestreqURI - request uri to process
@NotNull
public static java.lang.String getPathFromUrl(@NotNull
java.lang.String url)
url - url
public static java.lang.String getPathWithoutAuthenticationType(@NotNull
javax.servlet.http.HttpServletRequest request)
request - request
getOriginalPathWithoutContext(javax.servlet.http.HttpServletRequest),
getPathWithoutAuthenticationType(String)
public static java.lang.String getOriginalPathWithoutAuthenticationType(@NotNull
javax.servlet.http.HttpServletRequest request)
request - request
getOriginalPathWithoutContext(javax.servlet.http.HttpServletRequest),
getPathWithoutAuthenticationType(javax.servlet.http.HttpServletRequest),
getPathWithoutAuthenticationType(String)
public static java.lang.String getPathWithoutAuthenticationType(@NotNull
java.lang.String path)
request - path
public static java.lang.String combineContextPath(@NotNull
java.lang.String prefixPath,
@NotNull
java.lang.String path)
prefixPath - prefix pathpath - path
@NotNull
public static java.lang.String getRootUrl(@NotNull
javax.servlet.http.HttpServletRequest request)
request - request
public static boolean isAbsolute(@NotNull
java.lang.String url)
url - url
@NotNull
public static java.lang.String getMimeType(javax.servlet.http.HttpServletRequest request,
java.lang.String relativePath)
public static void setMimeType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String relativePath)
request - requestresponse - responserelativePath - path to a file which MIME type is to be set
public static void notFound(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String errorString,
@Nullable
com.intellij.openapi.diagnostic.Logger log)
throws java.io.IOException
response - responseerrorString - message to loglog - logger to log message to
java.io.IOException - IO exception if failed to write 404 response
@NotNull
public static java.lang.String encode(@Nullable
java.lang.String string)
string - string to encode
@NotNull
public static java.lang.String decode(@Nullable
java.lang.String string)
string - string to decode
public static java.lang.String escapeXml(java.lang.String text)
text - test
@NotNull
public static java.lang.String createPathWithParameters(@NotNull
javax.servlet.http.HttpServletRequest request)
createPathWithParameters(javax.servlet.http.HttpServletRequest, jetbrains.buildServer.web.util.WebUtil.ParameterFilter)
with default filter which accepts all parameters.
request - current http request.
@NotNull
public static java.lang.String createPathWithParameters(@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
WebUtil.ParameterFilter filter)
this method will return: /context/path/to/some/file.html?param1=value
request - requestfilter - to strip unneded parameters from query string
public static java.lang.String getFilename(@NotNull
SBuild build)
build - build for which filename should be returned
@NotNull
public static java.lang.String escapeForJavaScriptIdentifier(@Nullable
java.lang.String text)
text - id to escape
public static java.lang.String escapeForJavaScript(@NotNull
java.lang.String text,
boolean removeLineFeeds,
boolean forHTMLAttribute)
text - text to escaperemoveLineFeeds - whether to remove line feeds from the textforHTMLAttribute - specify true if text is supposed to be used in HTML attribute, in this case some characters will be replaced with HTML entities.
@NotNull
public static java.lang.String escapeUrlForQuotes(@Nullable
java.lang.String url)
Suppose you use the ${url} like this in your JSP:
SomeJsFunction("foo", '${url}', 0);
Passing the url equal to http://server/page.html?','');alert(1)//
will lead to
SomeJsFunction("foo", 'http://server/page.html?','');alert(1)//', 0);
Which executes not only SomeJsFunction function, but also user provided code (alert(1)).
A similar issue can arise in pure HTML like this:
<form action="${url}">...</form>
If the url is http://server/page.html?"><script>alert(1)</script>
In order to resolve the issue, but still support URLs containing special characters, this function urlencodes
dangerous characters with %-entities.
url - the url to process.
public static void dumpRequest(javax.servlet.http.HttpServletRequest request,
java.io.PrintStream out)
request - requestout - print streampublic static java.lang.String getRequestDump(javax.servlet.http.HttpServletRequest request)
request - request
public static void logRequestWarn(@NotNull
java.lang.String message,
@Nullable
java.lang.Exception e,
@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
com.intellij.openapi.diagnostic.Logger log)
message - warning messagee - exception that occurred, if anyrequest - request during which the error occurredlog - the log to add message to
public static java.lang.String makeBreakable(java.lang.String source,
java.lang.String regexp)
source - source textregexp - a regular expression identifying a place where replacement should be done
public static java.lang.String firstLine(java.lang.String text)
text - source text
public static javax.servlet.http.Cookie createSessionCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String value)
request - HTTP requestname - cookie namevalue - cookie value
public static javax.servlet.http.Cookie createCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String value,
int age)
request - HTTP requestname - cookie namevalue - cookie valueage - age in seconds
public static boolean isProbablyBrowser(javax.servlet.http.HttpServletRequest request)
request - HTTP request
public static java.lang.String getUserAgent(javax.servlet.http.HttpServletRequest request)
public static java.lang.String truncateStringValueWithDotsInTheMiddle(java.lang.String str,
int maxLength)
str - string to trimmaxLength - max length
public static boolean isJspPath(java.lang.String path)
path - path
public static boolean isIE(@NotNull
javax.servlet.http.HttpServletRequest request)
request - http request
public static void addCacheHeadersForIE(@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
javax.servlet.http.HttpServletResponse response)
request - an http requestresponse - the response to make
public static void setContentDisposition(@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
javax.servlet.http.HttpServletResponse response,
@NotNull
java.lang.String fileName)
fileName specified.
request - http requestresponse - http responsefileName - file name
public static void setContentDisposition(@NotNull
javax.servlet.http.HttpServletRequest request,
@NotNull
javax.servlet.http.HttpServletResponse response,
@NotNull
java.lang.String fileName,
boolean canBeInline)
fileName specified (if canBeInline is true).
response - http responsefileName - file namecanBeInline - use "inline" type or not (note: "inline" may cause problems in IE)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||