Package de.xima.fc.web.common.utils
Class ServletUtils
java.lang.Object
de.xima.fc.web.common.utils.ServletUtils
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddCspPolicy(javax.servlet.http.HttpServletResponse res, String policy) Amends theContent-Security-Policyheader with the given policy, preserving existing policies.static voidaddCspReportOnlyPolicy(javax.servlet.http.HttpServletResponse res, String policy) Amends theContent-Security-Policy-Report-Onlyheader with the given policy, preserving existing policies.static voidaddRobotsTagHeader(javax.servlet.http.HttpServletResponse resp, String botName, ERobotsTag... tags) Adds aX-Robots-Tagheader for all or one specific bot.static ObjectcheckForDate(Object value) Falls übergebener Wert kein Datums-String im erwarteten Format ist, wird der Original-Wert zurückgegeben, ansonsten das entsprechendejava.util.Date.static SimpleDateFormatstatic intgetIntParam(String param) static StringgetRequestTrace(javax.servlet.http.HttpServletRequest req) Schreibt Request-Header rausstatic intgetUrlIntParam(javax.servlet.http.HttpServletRequest req, int idx) Auslesen eines Int-Parameters aus einer ServletUrl.static StringgetUrlParam(javax.servlet.http.HttpServletRequest req, int idx) Auslesen eines Parameter aus einer ServletUrl.static voidlogRequestTrace(javax.servlet.http.HttpServletRequest req, org.slf4j.Logger logger) parseForMultipleParameters(javax.servlet.http.HttpServletRequest request, Long limit) Assumes there are no file uploads.parseForSingleParameters(javax.servlet.http.HttpServletRequest request, Long limit) Assumes there are no file uploads.static final Stringstatic final Stringstatic StringInputStream in einen String umwandeln.static final voidsetAccessControlHeader(javax.servlet.http.HttpServletResponse resp) Sets the headerAccess-Control-Allow-Origin: *.static final voidsetAccessControlHeader(javax.servlet.http.HttpServletResponse resp, int deltaSeconds, String origin, boolean allowCredentials, Iterable<String> allowMethods, Iterable<String> allowHeaders, Iterable<String> exposeHeaders) Sets the variousAccess-Control-*headers on the given response.static final voidsetAccessControlHeader(javax.servlet.http.HttpServletResponse resp, int deltaSeconds, javax.servlet.http.HttpServletRequest req, boolean allowCredentials, Iterable<String> allowMethods, Iterable<String> allowHeaders, Iterable<String> exposeHeaders) Sets the variousAccess-Control-*headers on the given response.static final voidsetDefaultEncodings(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) static final voidsetFormAccessControllHeaders(javax.servlet.http.HttpServletResponse resp) static final voidsetFormAccessControllHeaders(javax.servlet.http.HttpServletResponse resp, String allowOrigin) static voidsetFormRobotsTags(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Sets thenoindexandnofollowtags when a security related parameter is present in the request (process ID , form request ID, form session ID, verify ID, verify workflow node ID, username).static final voidsetNoCacheHeaders(javax.servlet.http.HttpServletResponse resp) static voidsetRobotsTagHeader(javax.servlet.http.HttpServletResponse resp, String botName, ERobotsTag... tags) Sets theX-Robots-Tagheader (overwriting all existing headers) for all or one specific bot.static final Stringstatic javax.servlet.http.HttpServletResponseunwrapResponse(javax.servlet.http.HttpServletResponse response) Unwraps the servlet response, removing CDI proxies and allServletResponseWrapper, returning the raw unwrapped HTTP servlet response.
- 
Field Details- 
LOGpublic static final org.slf4j.Logger LOG
- 
ERRpublic static final int ERR- See Also:
 
 
- 
- 
Method Details- 
getRequestTraceSchreibt Request-Header raus
- 
logRequestTracepublic static void logRequestTrace(javax.servlet.http.HttpServletRequest req, org.slf4j.Logger logger) 
- 
unwrapResponsepublic static javax.servlet.http.HttpServletResponse unwrapResponse(javax.servlet.http.HttpServletResponse response) Unwraps the servlet response, removing CDI proxies and allServletResponseWrapper, returning the raw unwrapped HTTP servlet response.- Parameters:
- response- Response to unwrap.
- Returns:
- The unwrapped response.
 
- 
getUrlParamAuslesen eines Parameter aus einer ServletUrl. Der Index gibt die Position an, begonnen wird bei 0. Aufbau der URL:web-app-url/servlet/param0/param1/... - Parameters:
- req- HttpServletRequest mit Parameter
- idx- Index des Parameters
- Returns:
- Parameter aus HttpRequest. Wird kein Parameter gefunden wird null zurückgegeben.
 
- 
getUrlIntParampublic static int getUrlIntParam(javax.servlet.http.HttpServletRequest req, int idx) Auslesen eines Int-Parameters aus einer ServletUrl. Weitere Informationen siehe ServletUtils#getParam(req, idx)
- 
getIntParam
- 
parseForSingleParameterspublic static Map<String,String> parseForSingleParameters(javax.servlet.http.HttpServletRequest request, Long limit) throws org.apache.commons.fileupload.FileUploadException, IOException Assumes there are no file uploads. Reads all parameters from the request, including parameters from a multipart request. In case there are multiple values for a parameter key (eg.http://example.com?foo=bar&foo=baz), only one value is returned. Also handles the case of form encoded requests with different methods such asDELETEorPUT.- Parameters:
- request- Request to be parsed
- limit- Limit in bytes for a multipart request. Set to- 0or- nullfor no limit.
- Returns:
- A map of all request parameters, including form parameters from a multipart request.
- Throws:
- org.apache.commons.fileupload.FileUploadException- When the request is a multipart request and could not be parsed.
- IOException- When the body of the HTTP request could not be read.
 
- 
parseForMultipleParameterspublic static Map<String,List<String>> parseForMultipleParameters(javax.servlet.http.HttpServletRequest request, Long limit) throws org.apache.commons.fileupload.FileUploadException, IOException Assumes there are no file uploads. Reads all parameters from the request, including parameters from a multipart request. Also handles the case of form encoded requests with different methods such asDELETEorPUT.- Parameters:
- request- Request to be parsed
- limit- Limit in bytes for a multipart request. Set to- 0or- nullfor no limit.
- Returns:
- A map of all request parameters, including form parameters from a multipart request.
- Throws:
- org.apache.commons.fileupload.FileUploadException- When the request is a multipart request and could not be parsed.
- IOException- When the body of the HTTP request could not be read.
 
- 
readJSONFromPayLoadInputStream in einen String umwandeln.- Parameters:
- is- InputStream
- Returns:
- JSON-String aus InputStream, im Fehlerfall wird null zurückgegeben.
 
- 
setDefaultEncodingspublic static final void setDefaultEncodings(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws UnsupportedEncodingException - Throws:
- UnsupportedEncodingException
 
- 
setNoCacheHeaderspublic static final void setNoCacheHeaders(javax.servlet.http.HttpServletResponse resp) 
- 
addRobotsTagHeaderpublic static void addRobotsTagHeader(javax.servlet.http.HttpServletResponse resp, String botName, ERobotsTag... tags) Adds aX-Robots-Tagheader for all or one specific bot. See e.g. https://developers.google.com/search/docs/advanced/robots/robots_meta_tag for reference.- Parameters:
- resp- Servlet response on which to set the header.
- botName- Name of the bot to which the robots tags should apply, such as- googlebot,- Bingbot, or- Baiduspider.- nullor empty if they should apply to all robots.
- tags- Robots tag to set.
 
- 
setRobotsTagHeaderpublic static void setRobotsTagHeader(javax.servlet.http.HttpServletResponse resp, String botName, ERobotsTag... tags) Sets theX-Robots-Tagheader (overwriting all existing headers) for all or one specific bot. See e.g. https://developers.google.com/search/docs/advanced/robots/robots_meta_tag for reference.- Parameters:
- resp- Servlet response on which to set the header.
- botName- Name of the bot to which the robots tags should apply, such as- googlebot,- Bingbot, or- Baiduspider.- nullor empty if they should apply to all robots.
- tags- Robots tag to set.
 
- 
setFormAccessControllHeaderspublic static final void setFormAccessControllHeaders(javax.servlet.http.HttpServletResponse resp) 
- 
setFormAccessControllHeaderspublic static final void setFormAccessControllHeaders(javax.servlet.http.HttpServletResponse resp, String allowOrigin) 
- 
setAccessControlHeaderpublic static final void setAccessControlHeader(javax.servlet.http.HttpServletResponse resp) Sets the headerAccess-Control-Allow-Origin: *.- Parameters:
- resp- Response to process.
 
- 
setAccessControlHeaderpublic static final void setAccessControlHeader(javax.servlet.http.HttpServletResponse resp, int deltaSeconds, javax.servlet.http.HttpServletRequest req, boolean allowCredentials, Iterable<String> allowMethods, Iterable<String> allowHeaders, Iterable<String> exposeHeaders) Sets the variousAccess-Control-*headers on the given response.- Parameters:
- resp- Response to process.
- deltaSeconds- The value for the- Access-Control-Max-Ageheader, which indicates how long the results of a preflight request (that is the information contained in the- Access-Control-Allow-Methodsand- Access-Control-Allow-Headersheaders) can be cached. Set to a value less than 0 to not set this header.
- req- Origin to allow for the- Access-Control-Allow-Originheader, uses the- Originheader of the request.
- allowCredentials- When true, sets- Access-Control-Allow-Credentials: true. It tells browsers whether to expose the response to the frontend JavaScript code when the request's credentials mode (- Request.credentials) is- include.
- allowMethods- HTTP methods for the- Access-Control-Allow-Methodsheader, which specifies one or more methods allowed when accessing a resource in response to a preflight request.
- allowHeaders- Headers for the- Access-Control-Allow-Headersheader, which indicates which HTTP headers can be used during the actual request.
- exposeHeaders- Headers for the- Access-Control-Expose-Headersheader, which indicates which response headers should be made available to scripts running in the browser, in response to a cross-origin request.
 
- 
setAccessControlHeaderpublic static final void setAccessControlHeader(javax.servlet.http.HttpServletResponse resp, int deltaSeconds, String origin, boolean allowCredentials, Iterable<String> allowMethods, Iterable<String> allowHeaders, Iterable<String> exposeHeaders) Sets the variousAccess-Control-*headers on the given response.- Parameters:
- resp- Response to process.
- deltaSeconds- The value for the- Access-Control-Max-Ageheader, which indicates how long the results of a preflight request (that is the information contained in the- Access-Control-Allow-Methodsand- Access-Control-Allow-Headersheaders) can be cached. Set to a value less than 0 to not set this header.
- origin- Origin to allow for the- Access-Control-Allow-Originheader. When empty or- null, uses- *.
- allowCredentials- When true, sets- Access-Control-Allow-Credentials: true. It tells browsers whether to expose the response to the frontend JavaScript code when the request's credentials mode (- Request.credentials) is- include.
- allowMethods- HTTP methods for the- Access-Control-Allow-Methodsheader, which specifies one or more methods allowed when accessing a resource in response to a preflight request.
- allowHeaders- Headers for the- Access-Control-Allow-Headersheader, which indicates which HTTP headers can be used during the actual request.
- exposeHeaders- Headers for the- Access-Control-Expose-Headersheader, which indicates which response headers should be made available to scripts running in the browser, in response to a cross-origin request.
 
- 
pn- Returns:
- Die übergebene Attributkette in Punktnotation, bspw "attribs0.attribs1.attribs2".
 
- 
pn2ul- Returns:
- Der übergebene String, wobei Punkte('.') mit Unterstrichen('_') erstetzt werden.
 
- 
ul2pn- Returns:
- Der übergebene String, wobei Unterstriche('_') mit Punkten('.') erstetzt werden.
 
- 
dateFormatter- Returns:
- SimpleDateFormatauf Basis des Standardformats für Datumsangaben
 
- 
checkForDateFalls übergebener Wert kein Datums-String im erwarteten Format ist, wird der Original-Wert zurückgegeben, ansonsten das entsprechendejava.util.Date.
- 
setFormRobotsTagspublic static void setFormRobotsTags(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) Sets thenoindexandnofollowtags when a security related parameter is present in the request (process ID , form request ID, form session ID, verify ID, verify workflow node ID, username).- Parameters:
- req- Request that was made.
- resp- Response that is to be sent.s
 
- 
addCspPolicyAmends theContent-Security-Policyheader with the given policy, preserving existing policies.- Parameters:
- res- HTTP response to which to add the policy.
- policy- Policy to add.
 
- 
addCspReportOnlyPolicypublic static void addCspReportOnlyPolicy(javax.servlet.http.HttpServletResponse res, String policy) Amends theContent-Security-Policy-Report-Onlyheader with the given policy, preserving existing policies.- Parameters:
- res- HTTP response to which to add the policy.
- policy- Policy to add.
 
 
-