jet.server.api.http
Class HttpUtil

java.lang.Object
  extended by jet.server.api.http.BaseHttpUtil
      extended by jet.server.api.http.HttpUtil

public class HttpUtil
extends BaseHttpUtil

Class HttpUtil provides a set of useful static methods.

Many of the methods are for use by JSP pages or servlets that run in a servlet container to perform operations related to HTTP Requests. These are easy to distinguish because they require an HTTPServletRequest parameter.

Other methods can be used in any environment.
In particular, the initEnv() and getHttpRptServer() are important and useful methods that can be used by code running in any environment.


Field Summary
 
Fields inherited from class jet.server.api.http.BaseHttpUtil
CONTENT_LOCATION, PROP_OUTPUT_ENCODING
 
Method Summary
static void bindHttpRptServer(HttpRptServer server, java.lang.String dispatchId)
          Bind the HttpRptServer to the specified dispatchId.
static boolean checkAdminLogin(javax.servlet.http.HttpServletRequest req)
          Performs an authentication check for the current HTTP Request looking for an admin user.
static boolean checkAdminLogin(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Performs an authentication check for the current HTTP Request looking for an admin user.
static boolean checkAdminLoginEx(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
static boolean checkLogin(javax.servlet.http.HttpServletRequest req)
          Performs an authentication check for the current HTTP Request.
static boolean checkLogin(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Performs an authentication check for the current HTTP Request.
static boolean checkLoginEx(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
static boolean checkPermission(javax.servlet.http.HttpServletRequest req)
          Tests whether the JReport user logged into the current session is authorized to perform the requested action against the target resource which is indicated in the HTTP Request.
static void copyFilesByPrefix(java.lang.String srcDir, java.lang.String srcPrefix, java.lang.String destDir, java.lang.String destPrefix)
          Copies files from a directory to another directory.
static HttpRptServer dispatchHttpRptServer(javax.servlet.http.HttpServletRequest request)
          Dispatch and return a HttpRptServer object by HttpRequest according dispatch implement algorithm(round-Robin).
static java.lang.String filterXSS(java.lang.String oldVal)
          Filters html content to prevent Cross Site Scripting (XSS) vulnerability.
static boolean getAdHoc()
          Gets if AdHoc feature is enabled.
static java.lang.String getAdhocJspPath()
          Gets adhoc jsp path.
static java.lang.String getAdhocServletPath()
          Gets adhoc servlet path.
static java.lang.String getAuthScheme()
          Gets the scheme of authentication initialed by initEnv(..).
static long getAutoRecoverTaskInterval()
          Gets retry interval for auto recovering failed scheduled tasks.
static int getAutoRecoverTaskMaxTimes()
          Gets maximum retry times for auto recovering failed scheduled tasks.
static boolean getAutoRecoverTaskRedoAll()
          Checks whether to recreate all results for auto recovering failed scheduled tasks.
static java.lang.String getBase(javax.servlet.http.HttpServletRequest req, boolean convertEscapeForServletPath)
          Gets the path of HttpServletRequest, including the servlet path.
static java.lang.String getBaseNoPath(javax.servlet.http.HttpServletRequest req, boolean convertEscapeForServletPath)
          Gets the servlet path.
static HttpRptServer getBindedHttpRptServer(java.lang.String dispatchId)
          Gets the HttpRptServer which binded to the specified dispatchId.
static java.lang.String getDefaultDoc()
          Gets the home page of JReport Server initialed by initEnv(..).
static java.lang.String getHostAddress(java.lang.String hostName)
          Gets the host address by host name.
static HttpRptServer getHttpRptServer()
          Gets the HttpRptServer object created by initEnv(...).
static HttpRptServer getHttpRptServer(javax.servlet.http.HttpServletRequest request)
          Gets the HttpRptServer object by HTTP Request according RemoteDispatch implement (session-level dispatch).
static HttpRptServer getHttpRptServer(javax.servlet.http.HttpServletRequest request, int clusterMemberId)
          If system is cluster-enabled and clusterMemberId is exist in the active cluster nodes, return the node of specified by clusterMemberId, otherwise return getHttpRptServer(HttpServletRequest)
static java.lang.String getHttpURL()
          Gets the current Http prefix.
static java.lang.String getInternalBuildLable()
          Gets internal build lable of the server.
static java.lang.String getJRServletPath()
          Gets the JReport servlet path.
static java.lang.String getJspUri(javax.servlet.http.HttpServletRequest request, java.lang.String jspPath)
          Gets the url of the jsp by jsp path.
static java.lang.String getJSPWebAppName(java.lang.String propname)
          Gets jsp webapp name from bin\server.properties.
static java.util.List getLanguageList()
          Gets the supported languages list.
static java.lang.String getLogInfoAfterService(javax.servlet.ServletRequest _req, javax.servlet.ServletResponse _res)
          Gets the debug information related to a ServletResponse object for the access.log.
static java.lang.String getLogInfoBeforeService(javax.servlet.ServletRequest _req, javax.servlet.ServletResponse _res)
          Gets the debug information related to a ServletRequest object for the access.log.
static java.lang.String getOndemandJspUri(javax.servlet.http.HttpServletRequest request)
          Gets the url of the on demand page by the path of specified request.
static int getOndemandTaskInitPriority()
          Gets the initial priority of on demand tasks.
static java.lang.String getProductLicense(java.text.SimpleDateFormat df)
          Gets license of the server.
static java.lang.String getProductSystemInfo()
          Gets system information of the server.
static java.lang.String getProductSystemProp()
          Gets system properties of the server.
static java.lang.String getProductVersionInfo()
          Gets version information of the server.
static java.lang.String getQueryBase(javax.servlet.http.HttpServletRequest req, boolean convertEscapeForServletPath)
          Gets the path of HttpServletRequest, including the servlet path for making HTTP query string.
static java.lang.String getQueryBaseNoPath(javax.servlet.http.HttpServletRequest req, boolean convertEscapeForServletPath)
          Gets the servlet path for making HTTP query string.
static java.lang.String getRealmDir()
          Gets the directory for realm files on the server.
static java.lang.String getReferer(javax.servlet.http.HttpServletRequest request)
          auto get jsp referer, used to relative jsp prosess business logic and return to the previous page.
static RemoteFileService getRemoteFileService()
          Gets the RemoteFileService which connect to the HttpRptServer object created by initEnv(...)
static RemoteFileService getRemoteFileService(javax.servlet.http.HttpServletRequest request)
          Deprecated. As of v12.1 replaced by RptServer.getRemoteFileService()
static long getReportWaitTimeouts()
          Gets the timeouts of waiting reports in milliseconds.
static int getScheduleTaskInitPriority()
          Gets the initial priority of scheduled tasks.
static java.lang.String getServletPath(javax.servlet.http.HttpServletRequest req)
          Gets the servlet path.
static java.util.Properties getUploadFileProperties(javax.servlet.http.HttpServletRequest req, java.lang.String tempDir)
          Uploads and unzips zipped files and gets relevant properties of the files.
static java.util.Properties getUploadFileProperties(javax.servlet.http.HttpServletRequest req, java.lang.String tempDir, boolean isZip)
          Uploads and gets relevant properties of the files.
static java.lang.String getUser(javax.servlet.http.HttpServletRequest req)
          Gets the JReport user ID (user name) logged into the session associated with the HttpServletRequest.
static java.lang.String getValidMonitoringURL()
          Gets the currently valid and active monitoring web url entry.
static java.lang.String getValidMonitoringURL(java.lang.String host, java.lang.String port)
          Gets the currently valid and active monitoring web url entry.
static java.lang.String getWebAppUrl(javax.servlet.http.HttpServletRequest req, java.lang.String appName)
          Gets the url of the given web app name, based on provided HttpServletRequest object.
static void handleFileNameByBrowserTypeForDownload(java.lang.String fileName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Encoding download file name by browser type, if browser type can not be identified, will set download file name by original file name.
static void initEnv(java.util.Properties props)
          Creates and initializes the HttpRptServer object using the given set of properties.
static boolean isEnableDynamicResource()
          Checks if resources from real path is enabled.
static boolean isEnableMonitorLink()
          Checks if the monitor link is enabled.
static boolean isEnableTaskDuration()
          Checks whether task duration is enabled.
static boolean isPipeline()
          Checks whether to support pipeline for try-view reports
static boolean isPublishTempToVersion()
          Checks if temp result can be published to version system.
static boolean isPublishTempToVersion(java.lang.String filename)
          Checks if the specified file of temp result can publish to version system.
static boolean isRemoteServer()
          Checks whether it is a remote server.
static boolean isSecure()
          Deprecated. since v6.1, replaced by jet.server.api.UserSessionManager.needSecurity().
static boolean isShowNameWithPostfix()
          Gets a boolean value from bin\server.properties to show names with or without extension.
static boolean isShowVersionParamContents()
          Checks whether to show the contents of parameter files in the version table
static boolean isStandaloneServer()
          Checks whether the server is in an integrated environment.
static boolean isValidMonitoringURL(java.lang.String sURL)
          Checks if the specific monitor URL is valid.
static boolean isValidMonitoringURL(java.lang.String sURL, java.lang.String host, java.lang.String port)
          Checks if the specific monitor URL is valid.
static void logout(javax.servlet.http.HttpServletRequest req)
          Logs out the JReport user currently logged in to the UserSession associated with the Http Request.
static java.lang.String printURL(javax.servlet.http.HttpServletRequest request)
           
static void processPartialRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.io.File file, java.util.Hashtable ht)
          Processes an http request for partial contents.
static void restartServer()
          Restarts the HttpRptServer.
static void sendBytes(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, byte[] bytes, java.lang.String name)
           
static void sendFile(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.io.File file)
          Sends a file to the client.
static void sendRemoteFile(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String filename)
          Sends a file to a remote end.
static void shutdownServer()
          Shuts down the HttpRptServer.
static void unbindHttpRptServer(java.lang.String dispatchId)
          Unbind the dispatchId with the HttpRptServer which binded by bindHttpRptServer(HttpRptServer, String).
static void updateServletPaths(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request)
          Updates servlet paths in server.properties automatically.
static java.util.Properties uploadSkinFile(javax.servlet.http.HttpServletRequest req, java.lang.String tempDir)
          Uploads a single unzipped file and specifies the file name.
static boolean useRelativeWebAppUrl()
          Indicates use relative path or absolute path when getting a web app url.
 
Methods inherited from class jet.server.api.http.BaseHttpUtil
changePassword, decodeEsc, decodeEscapeEx, dirIncludeCatalog, dirIncludeReport, encodeEsc, encodeEsc, getParameters, getResultType, getTempResultKey, hasPageSecurity, isClientAPI, isJRClient, makeQuery, makeQueryWithout, outputHtmlTableHeader, parseQuery, redirect, sendMessage, sendMessage
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initEnv

public static void initEnv(java.util.Properties props)
Creates and initializes the HttpRptServer object using the given set of properties.

Use this method to avoid creating more than one HttpRptServer instance.

If the HttpRptServer is not started, this will start it, so that it can be used by all later requests.

If the HttpRptServer has already been started, this method will do nothing.

The "props" parameter should contain the properties to be used by the HttpRptServer which is initialized. A common convention is to call this method with the property values that are registered in the external property files, using System.getProperties() to obtain them.

Example: HttpUtil.initEnv(System.getProperties());

Parameters:
props - properties of the server. The property "reporthome" must be set. Other properties are optional.

The properties are:

  • reporthome or install.root: Must be set, for example, c:/jrserver.
  • jrs.isMyServer: Indicates if the HTTP server is JReport standalone server. The default value is "false".
  • temp_dir or jrs.dir.temp: The path of temp directory. The default value is "/temp".
  • history_dir or jrs.dir.history: The directory where all the versions of report results will be maintained. The default value is "/history".
  • auth_scheme: It specifies the scheme of authentication. Its value must be Basic or Digest. The default value is Basic.
  • default_doc: The home page of JReport Server. It is an HTML file. If it is not set or the file set to it cannot be loaded, the default home page of JReport Server will be used. The path is relative to , for example, docs/index.html.
  • isConvertedServletPath: This property specifies whether your web server decodes the path if it contains special characters. This information is used for JRServlet to determine whether it needs to convert that path. If you don't specify this property, your web server is supposed not to decode path.
  • vError: Enables the output of error messages of JRpeort Engine. Available values are true/false.
  • vDebug: Enables the output of debug messages of JRpeort Engine. Available values are true/false.
  • logFile: Transfers the output messages of JRpeort engine to the file /logs/report.log or other file as specified.

isRemoteServer

public static boolean isRemoteServer()
Checks whether it is a remote server.

Returns:
whether it is a remote server.

getRemoteFileService

public static RemoteFileService getRemoteFileService()
Gets the RemoteFileService which connect to the HttpRptServer object created by initEnv(...)

Returns:
The RemoteFileService object.
See Also:
getHttpRptServer()

getRemoteFileService

public static RemoteFileService getRemoteFileService(javax.servlet.http.HttpServletRequest request)
Deprecated. As of v12.1 replaced by RptServer.getRemoteFileService()

Gets the RemoteFileService object associated with the HTTP Request.

Parameters:
request - the HttpServletRequest object.
Returns:
the RemoteFileService object.
See Also:
RptServer.getRemoteFileService()

getHttpRptServer

public static HttpRptServer getHttpRptServer()
Gets the HttpRptServer object created by initEnv(...).

Returns:
the HttpRptServer object created by initEnv(...).

getHttpRptServer

public static HttpRptServer getHttpRptServer(javax.servlet.http.HttpServletRequest request)
Gets the HttpRptServer object by HTTP Request according RemoteDispatch implement (session-level dispatch).

Parameters:
request - the HttpServletRequest object.
Returns:
the HttpRptServer object.

getHttpRptServer

public static HttpRptServer getHttpRptServer(javax.servlet.http.HttpServletRequest request,
                                             int clusterMemberId)
If system is cluster-enabled and clusterMemberId is exist in the active cluster nodes, return the node of specified by clusterMemberId, otherwise return getHttpRptServer(HttpServletRequest)

Parameters:
request -
clusterMemberId -
Returns:

dispatchHttpRptServer

public static HttpRptServer dispatchHttpRptServer(javax.servlet.http.HttpServletRequest request)
Dispatch and return a HttpRptServer object by HttpRequest according dispatch implement algorithm(round-Robin). The result server is not limited to the same session-level.

Generally, to make subsequence request connect to same HttpRptServer, client need to bind the result HttpRptServer to a specified dispathId.

Client should not call this method before the first time initEnv(Properties) successful.

Parameters:
request -
Returns:
Since:
13.0
See Also:
bindHttpRptServer(HttpRptServer, String), #getHttpRptServerByDispatchId(String)

bindHttpRptServer

public static void bindHttpRptServer(HttpRptServer server,
                                     java.lang.String dispatchId)
Bind the HttpRptServer to the specified dispatchId.

The dispatchId required be unique in the cluster scope, and has pattern: XXXX@serverMemberId.

Client should not call this method before the first time initEnv(Properties) successful.

Parameters:
server -
dispatchId - must be unique in the cluster scope
Since:
13.0

getBindedHttpRptServer

public static HttpRptServer getBindedHttpRptServer(java.lang.String dispatchId)
Gets the HttpRptServer which binded to the specified dispatchId.

client should not call this method before the first time initEnv(Properties) successful.

Parameters:
dispatchId -
Returns:
the binded HttpRptServer, null if there is not a binded HttpRptServer for the dispatchId.
Since:
13.0

unbindHttpRptServer

public static void unbindHttpRptServer(java.lang.String dispatchId)
Unbind the dispatchId with the HttpRptServer which binded by bindHttpRptServer(HttpRptServer, String).

If has not HttpRptServer bind with the specified dispatchId, no effect.

Client should not call this method before the first time initEnv(Properties) successful.

Parameters:
dispatchId -
Since:
13.0

getAuthScheme

public static java.lang.String getAuthScheme()
Gets the scheme of authentication initialed by initEnv(..).

Returns:
the scheme of authentication.
See Also:
initEnv(Properties props).

getDefaultDoc

public static java.lang.String getDefaultDoc()
Gets the home page of JReport Server initialed by initEnv(..).

Returns:
the home page of JReport Server.
See Also:
initEnv(Properties props).

getBase

public static java.lang.String getBase(javax.servlet.http.HttpServletRequest req,
                                       boolean convertEscapeForServletPath)
Gets the path of HttpServletRequest, including the servlet path.

For example:

Parameters:
req - the HttpServletRequest.
convertEscapeForServletPath - indicates whether to convert escape characters for the servlet path.
Returns:
the path of HttpServletRequest, including the servlet path.

getBaseNoPath

public static java.lang.String getBaseNoPath(javax.servlet.http.HttpServletRequest req,
                                             boolean convertEscapeForServletPath)
Gets the servlet path.

For example:

Parameters:
req - the HttpServletRequest.
convertEscapeForServletPath - indicates whether to convert escape characters for the servlet path.
Returns:
the servlet path.

getQueryBase

public static java.lang.String getQueryBase(javax.servlet.http.HttpServletRequest req,
                                            boolean convertEscapeForServletPath)
Gets the path of HttpServletRequest, including the servlet path for making HTTP query string.

For examples:

Parameters:
req - the HttpServletRequest.
convertEscapeForServletPath - indicates whether to convert escape characters for the servlet path.
Returns:
the path of HttpServletRequest, including the servlet path for making HTTP query string.

getQueryBaseNoPath

public static java.lang.String getQueryBaseNoPath(javax.servlet.http.HttpServletRequest req,
                                                  boolean convertEscapeForServletPath)
Gets the servlet path for making HTTP query string.

For examples:

Parameters:
req - the HttpServletRequest.
convertEscapeForServletPath - indicates whether to convert escape characters for the servlet path.
Returns:
the servlet path for making HTTP query string.

getUser

public static java.lang.String getUser(javax.servlet.http.HttpServletRequest req)
Gets the JReport user ID (user name) logged into the session associated with the HttpServletRequest.

Parameters:
req - the HttpServletRequest. Return the user ID (suer name) logged into the session associated with the HttpServletRequest object.
Returns:
the user ID. Returns an empty string when no user is logged into the session.

isSecure

public static boolean isSecure()
Deprecated. since v6.1, replaced by jet.server.api.UserSessionManager.needSecurity().

Checks whether the server needs checking security.

Returns:
whether the server needs checking security.

restartServer

public static void restartServer()
                          throws java.lang.Throwable
Restarts the HttpRptServer.

Throws:
java.lang.Throwable - if a Throwable occurs.

shutdownServer

public static void shutdownServer()
                           throws java.lang.Throwable
Shuts down the HttpRptServer.

Throws:
java.lang.Throwable - if a Throwable occurs.

getHttpURL

public static java.lang.String getHttpURL()
Gets the current Http prefix.

Returns:
the current Http prefix.

checkLogin

public static boolean checkLogin(javax.servlet.http.HttpServletRequest req,
                                 javax.servlet.http.HttpServletResponse res)
                          throws TooManyUsersException,
                                 java.io.IOException,
                                 TooManyTimesException,
                                 java.lang.RuntimeException,
                                 NoRemoteServerException
Performs an authentication check for the current HTTP Request.

Returns true if an authenticated JReport Server user is logged-in to the web session.

There is no false return. For the non-true case, it sends a response to the browser and stops processing.

This is a facade pattern for calling HttpUserSessionManager.checkLogin(), followed by a potential call to HttpUserSessionManager.sendUnauthorizedResponse() to initiate an HTTP Authentication dialog with the browser. It initiates the dialog with the browser when a logged-in user can not be found. This method does not return when a logged-in user is not found. (This is when HttpUserSessionManager.checkLogin() returns false.)

If a logged-in user is not found, it attempts to log in a user based on the HttpExternalAuthorized login framework, and the current HTTP Request parameters passed in to it.

First, it calls the HttpExternalAuthorized class method getExternalAuthorizedUser().
If this returns a valid JReport user id, it logs this user into the JReport session.
If this does not return a valid user id, it looks in the HTTP Request header for the Authorization field (following the current HTTP Authentication protocal settings, either Basic or Digest), and uses what it finds as the name/password credentials to validate as a known JReport user.
If the header has credentials and they validate, it logs this user into the JReport session.
If the HTTP Request header does not contain credentials that validate, it looks in the HttpServletRequest parameters for either the pair of parameters APIConst.TAG_AUTH_UID and APIConst.TAG_AUTH_PWD or the single parameter APIConst.TAG_AUTHORIZATION, and uses the parameter values or value to get the name/password credentials to validate.
If these exist and the values validate, it logs this user into the JReport session.

When a user is logged into the JReport session based on credentials that checkLogin validates during this call, a new UserSession is established within the servlet session so that subsequent calls to checkLogin can return true immediately based on a user being logged-in.

If checkLogin is able to log in a user during this call it returns true.
If checkLogin does not find a user already logged-in and can not log in a user following this process, it calls HttpUserSessionManager.sendUnauthorizedResponse() which sends an HTTP Response to the client and stops processing on the server. There is no return from the call in this case.

This method implicitly calls HttpUtil.initEnv(...). So one may get the HttpRptServer handle by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
Returns:
true when the session is for a currently logged-in user.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if an IOException occurs.
java.lang.RuntimeException
NoRemoteServerException
See Also:
HttpExternalAuthorized, HttpUserSessionManager.checkLogin(), HttpUserSessionManager.sendUnauthorizedResponse()

checkLoginEx

public static boolean checkLoginEx(javax.servlet.http.HttpServletRequest req,
                                   javax.servlet.http.HttpServletResponse res)
                            throws TooManyUsersException,
                                   java.io.IOException,
                                   TooManyTimesException,
                                   java.lang.RuntimeException,
                                   NoRemoteServerException,
                                   InvalidUserException
Throws:
TooManyUsersException
java.io.IOException
TooManyTimesException
java.lang.RuntimeException
NoRemoteServerException
InvalidUserException

checkLogin

public static boolean checkLogin(javax.servlet.http.HttpServletRequest req)
                          throws TooManyUsersException,
                                 java.io.IOException,
                                 TooManyTimesException,
                                 java.lang.RuntimeException,
                                 NoRemoteServerException
Performs an authentication check for the current HTTP Request.

Returns true if an authenticated JReport Server user is logged-in to the web session.

There is no false return. For the non-true case, it dont sends a response to the browser and stops processing.

This is a facade pattern for calling HttpUserSessionManager.checkLogin(), followed by a potential call to HttpUserSessionManager.sendUnauthorizedResponse() to initiate an HTTP Authentication dialog with the browser. It initiates the dialog with the browser when a logged-in user can not be found. This method does not return when a logged-in user is not found. (This is when HttpUserSessionManager.checkLogin() returns false.)

If a logged-in user is not found, it attempts to log in a user based on the HttpExternalAuthorized login framework, and the current HTTP Request parameters passed in to it.

First, it calls the HttpExternalAuthorized class method getExternalAuthorizedUser().
If this returns a valid JReport user id, it logs this user into the JReport session.
If this does not return a valid user id, it looks in the HTTP Request header for the Authorization field (following the current HTTP Authentication protocal settings, either Basic or Digest), and uses what it finds as the name/password credentials to validate as a known JReport user.
If the header has credentials and they validate, it logs this user into the JReport session.
If the HTTP Request header does not contain credentials that validate, it looks in the HttpServletRequest parameters for either the pair of parameters APIConst.TAG_AUTH_UID and APIConst.TAG_AUTH_PWD or the single parameter APIConst.TAG_AUTHORIZATION, and uses the parameter values or value to get the name/password credentials to validate.
If these exist and the values validate, it logs this user into the JReport session.

When a user is logged into the JReport session based on credentials that checkLogin validates during this call, a new UserSession is established within the servlet session so that subsequent calls to checkLogin can return true immediately based on a user being logged-in.

If checkLogin is able to log in a user during this call it returns true.
If checkLogin does not find a user already logged-in and can not log in a user following this process, it calls HttpUserSessionManager.sendUnauthorizedResponse() which sends an HTTP Response to the client and stops processing on the server. There is no return from the call in this case.

This method implicitly calls HttpUtil.initEnv(...). So one may get the HttpRptServer handle by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
Returns:
true when the session is for a currently logged-in user.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if an IOException occurs.
java.lang.RuntimeException
NoRemoteServerException
See Also:
HttpExternalAuthorized, HttpUserSessionManager.checkLogin(), HttpUserSessionManager.sendUnauthorizedResponse()

checkAdminLogin

public static boolean checkAdminLogin(javax.servlet.http.HttpServletRequest req,
                                      javax.servlet.http.HttpServletResponse res)
                               throws TooManyUsersException,
                                      java.io.IOException,
                                      TooManyTimesException,
                                      java.lang.RuntimeException,
                                      NoRemoteServerException
Performs an authentication check for the current HTTP Request looking for an admin user. Returns true if an authenticated JReport Server admin user is logged-in to the web session.

There is no false return. For the non-true case, it sends a response to the browser and stops processing.

This is a facade pattern for calling HttpUserSessionManager.checkAdminLogin(), followed by a potential call to HttpUserSessionManager.sendUnauthorizedResponse() to initiate an HTTP Authentication dialog with the browser. It initiates the dialog with the browser when a logged-in admin user can not be found. This method does not return when a logged-in user is not found. (This is when HttpUserSessionManager.checkAdminLogin() returns false.)

If a logged-in admin user is not found, it attempts to log in a user based on the HttpExternalAuthorized login framework, and the current HTTP Request parameters passed in to it.

First, it calls the HttpExternalAuthorized class method getExternalAuthorizedUser().
If this returns a valid JReport admin user id, it logs this user into the JReport session.
If this does not return a valid admin user id, it looks in the HTTP Request header for the Authorization field (following the current HTTP Authentication protocal settings, either Basic or Digest), and uses what it finds as the name/password credentials to validate as a known JReport admin user.
If the header has credentials and they validate an admin user, it logs this user into the JReport session.
If the HTTP Request header does not contain credentials that validate, it looks in the HttpServletRequest parameters for either the pair of parameters APIConst.TAG_AUTH_UID and APIConst.TAG_AUTH_PWD or the single parameter APIConst.TAG_AUTHORIZATION, and uses the parameter values or value to get the name/password credentials to validate.
If these exist and the values validate an admin user, it logs this user into the JReport session.

When a admin user is logged into the JReport session based on credentials that checkLogin validates during this call, a new UserSession is established within the servlet session so that subsequent calls to checkAdminLogin can return true immediately based on an admin user being logged-in.

If checkAdminLogin() is able to log in an admin user during this call it returns true.
If checkAdminLogin does not find an admin user already logged-in and can not log in an admin user following this process, it calls HttpUserSessionManager.sendUnauthorizedResponse() which sends an HTTP Response to the client and stops processing on the server. There is no return from the call in this case.

This method implicitly calls HttpUtil.initEnv(...). So one may get the HttpRptServer handle by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
Returns:
true when the session is for a currently logged-in admin user.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if an IOException occurs.
java.lang.RuntimeException
NoRemoteServerException
See Also:
HttpExternalAuthorized, HttpUserSessionManager.checkAdminLogin(), HttpUserSessionManager.sendUnauthorizedResponse()

checkAdminLoginEx

public static boolean checkAdminLoginEx(javax.servlet.http.HttpServletRequest req,
                                        javax.servlet.http.HttpServletResponse res)
                                 throws TooManyUsersException,
                                        java.io.IOException,
                                        TooManyTimesException,
                                        java.lang.RuntimeException,
                                        NoRemoteServerException,
                                        InvalidUserException
Throws:
TooManyUsersException
java.io.IOException
TooManyTimesException
java.lang.RuntimeException
NoRemoteServerException
InvalidUserException

checkAdminLogin

public static boolean checkAdminLogin(javax.servlet.http.HttpServletRequest req)
                               throws TooManyUsersException,
                                      java.io.IOException,
                                      TooManyTimesException,
                                      java.lang.RuntimeException,
                                      NoRemoteServerException
Performs an authentication check for the current HTTP Request looking for an admin user. Returns true if an authenticated JReport Server admin user is logged-in to the web session.

There is no false return. For the non-true case, it dont sends a response to the browser and stops processing.

This is a facade pattern for calling HttpUserSessionManager.checkAdminLogin(), followed by a potential call to HttpUserSessionManager.sendUnauthorizedResponse() to initiate an HTTP Authentication dialog with the browser. It initiates the dialog with the browser when a logged-in admin user can not be found. This method does not return when a logged-in user is not found. (This is when HttpUserSessionManager.checkAdminLogin() returns false.)

If a logged-in admin user is not found, it attempts to log in a user based on the HttpExternalAuthorized login framework, and the current HTTP Request parameters passed in to it.

First, it calls the HttpExternalAuthorized class method getExternalAuthorizedUser().
If this returns a valid JReport admin user id, it logs this user into the JReport session.
If this does not return a valid admin user id, it looks in the HTTP Request header for the Authorization field (following the current HTTP Authentication protocal settings, either Basic or Digest), and uses what it finds as the name/password credentials to validate as a known JReport admin user.
If the header has credentials and they validate an admin user, it logs this user into the JReport session.
If the HTTP Request header does not contain credentials that validate, it looks in the HttpServletRequest parameters for either the pair of parameters APIConst.TAG_AUTH_UID and APIConst.TAG_AUTH_PWD or the single parameter APIConst.TAG_AUTHORIZATION, and uses the parameter values or value to get the name/password credentials to validate.
If these exist and the values validate an admin user, it logs this user into the JReport session.

When a admin user is logged into the JReport session based on credentials that checkLogin validates during this call, a new UserSession is established within the servlet session so that subsequent calls to checkAdminLogin can return true immediately based on an admin user being logged-in.

If checkAdminLogin() is able to log in an admin user during this call it returns true.
If checkAdminLogin does not find an admin user already logged-in and can not log in an admin user following this process, it calls HttpUserSessionManager.sendUnauthorizedResponse() which sends an HTTP Response to the client and stops processing on the server. There is no return from the call in this case.

This method implicitly calls HttpUtil.initEnv(...). So one may get the HttpRptServer handle by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
Returns:
true when the session is for a currently logged-in admin user.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if an IOException occurs.
java.lang.RuntimeException
NoRemoteServerException
See Also:
HttpExternalAuthorized, HttpUserSessionManager.checkAdminLogin(), HttpUserSessionManager.sendUnauthorizedResponse()

logout

public static void logout(javax.servlet.http.HttpServletRequest req)
Logs out the JReport user currently logged in to the UserSession associated with the Http Request.

Parameters:
req - http servlet request.

checkPermission

public static boolean checkPermission(javax.servlet.http.HttpServletRequest req)
                               throws NoPrivilegeException
Tests whether the JReport user logged into the current session is authorized to perform the requested action against the target resource which is indicated in the HTTP Request.

The requested action is the value of "jrs.cmd" query paramter in the HttpServletRequest or is the HTTP method of the HttpServletRequest.

The target resource is the report resource identified by the path information query parameters in the HttpServletRequest.

The path information is indicated by query parameters:

Parameters:
req - the HttpServletRequest.
Returns:
whether the user has the permission of the action for the resource in the server.
Throws:
NoPrivilegeException

sendFile

public static void sendFile(javax.servlet.http.HttpServletRequest req,
                            javax.servlet.http.HttpServletResponse res,
                            java.io.File file)
                     throws java.io.IOException
Sends a file to the client.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
file - the file.
Throws:
java.io.IOException - if an IOException occurs.

sendBytes

public static void sendBytes(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res,
                             byte[] bytes,
                             java.lang.String name)
                      throws java.io.IOException
Throws:
java.io.IOException

sendRemoteFile

public static void sendRemoteFile(javax.servlet.http.HttpServletRequest req,
                                  javax.servlet.http.HttpServletResponse res,
                                  java.lang.String filename)
                           throws java.io.IOException
Sends a file to a remote end.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
file - the file.
Throws:
java.io.IOException - if an IOException occurs.

getServletPath

public static java.lang.String getServletPath(javax.servlet.http.HttpServletRequest req)
Gets the servlet path.

Parameters:
req - the HttpServletRequest.
Returns:
the servlet path.

getReportWaitTimeouts

public static long getReportWaitTimeouts()
Gets the timeouts of waiting reports in milliseconds. This value is specified in seconds by the property "web.timeouts.report_wait" in the file /bin/server.properties.

Returns:
the timeouts in milliseconds.

isPublishTempToVersion

public static boolean isPublishTempToVersion()
Checks if temp result can be published to version system.

Returns:
true if it is enabled, false if it is disabled.

isPublishTempToVersion

public static boolean isPublishTempToVersion(java.lang.String filename)
Checks if the specified file of temp result can publish to version system.

Returns:
true if it is enabled, false if it is disabled.

isEnableDynamicResource

public static boolean isEnableDynamicResource()
Checks if resources from real path is enabled.

Returns:
true if it is enabled, false if it is disabled.

isEnableTaskDuration

public static boolean isEnableTaskDuration()
Checks whether task duration is enabled.

Returns:
true if enabled, or else false.

copyFilesByPrefix

public static void copyFilesByPrefix(java.lang.String srcDir,
                                     java.lang.String srcPrefix,
                                     java.lang.String destDir,
                                     java.lang.String destPrefix)
                              throws java.lang.Exception
Copies files from a directory to another directory. The source files begin with prefix specified by srcPrefix and "_" or "." following prefix, and destination files begin with prefix specified by destPrefix and "_" or "." following prefix;

Parameters:
srcDir - the source directory.
srcPrefix - source file's prefix.
destDir - destination file's directory.
destPrefix - destination file's prefix.
Throws:
java.lang.Exception

processPartialRequest

public static void processPartialRequest(javax.servlet.http.HttpServletRequest req,
                                         javax.servlet.http.HttpServletResponse res,
                                         java.io.File file,
                                         java.util.Hashtable ht)
                                  throws java.lang.Exception
Processes an http request for partial contents.

Parameters:
req - the http request.
res - the http response.
file - the file that is required.
ht - additional properties of the request.
Throws:
java.lang.Exception - when exception is thrown during processing.

isShowNameWithPostfix

public static boolean isShowNameWithPostfix()
Gets a boolean value from bin\server.properties to show names with or without extension.

Returns:
whether to show names with extension.

getJSPWebAppName

public static java.lang.String getJSPWebAppName(java.lang.String propname)
Gets jsp webapp name from bin\server.properties.

Parameters:
propname - the property name that records this webapp eg. propname "jsp.webapp.sendfile" sendfile's webapp name "\servlet\sendfile"
Returns:
jsp webapp name

useRelativeWebAppUrl

public static boolean useRelativeWebAppUrl()
Indicates use relative path or absolute path when getting a web app url.

Returns:
true if relative web app url is used, otherwise absolute web app url is used.
See Also:
getWebAppUrl()

getWebAppUrl

public static java.lang.String getWebAppUrl(javax.servlet.http.HttpServletRequest req,
                                            java.lang.String appName)
Gets the url of the given web app name, based on provided HttpServletRequest object. Returned value varies, depending on the returned value HttpUtil.useRelativeWebAppUrl(), if it is true, return a url related with provided req, otherwise return absolute path of appName. For example, appName is "/dhtml", the servlet path of req is "/jinfonet/runReport.jsp", if WebPageOptions.useRelativeWebAppUrl() returns true, this method return "../dhtml", otherwise return "/dhtml".

Parameters:
req - the HttpServletRequest object.
appName - a web app name, for example, "/dhtml".
Returns:
a web app url, which represents the appName based on the provided request.
See Also:
useRelativeWebAppUrl()

getLanguageList

public static java.util.List getLanguageList()
Gets the supported languages list.

Returns:
the supported languages list.

isPipeline

public static boolean isPipeline()
Checks whether to support pipeline for try-view reports

Returns:
whether to support pipeline for try-view reports

isShowVersionParamContents

public static boolean isShowVersionParamContents()
Checks whether to show the contents of parameter files in the version table

Returns:
whether to show the contents of parameter files in the version table

getProductVersionInfo

public static java.lang.String getProductVersionInfo()
Gets version information of the server.

Returns:
version information.

getInternalBuildLable

public static java.lang.String getInternalBuildLable()
Gets internal build lable of the server.

Returns:
version information.

getProductLicense

public static java.lang.String getProductLicense(java.text.SimpleDateFormat df)
Gets license of the server.

Returns:
license of the server.

getProductSystemInfo

public static java.lang.String getProductSystemInfo()
Gets system information of the server.

Returns:
system information.

getAdhocServletPath

public static java.lang.String getAdhocServletPath()
Gets adhoc servlet path.

Returns:
the adhoc servlet path.

getAdhocJspPath

public static java.lang.String getAdhocJspPath()
Gets adhoc jsp path.

Returns:
the adhoc jsp path.

getJRServletPath

public static java.lang.String getJRServletPath()
Gets the JReport servlet path.

Returns:
the JReport servlet path.

isEnableMonitorLink

public static boolean isEnableMonitorLink()
Checks if the monitor link is enabled.

Returns:
whether the monitor link is enabled.

getProductSystemProp

public static java.lang.String getProductSystemProp()
Gets system properties of the server.

Returns:
system properties.

getAdHoc

public static boolean getAdHoc()
Gets if AdHoc feature is enabled.

Returns:
true if this key is AdHoc enabled, otherwise false.

getLogInfoBeforeService

public static java.lang.String getLogInfoBeforeService(javax.servlet.ServletRequest _req,
                                                       javax.servlet.ServletResponse _res)
Gets the debug information related to a ServletRequest object for the access.log.

Parameters:
req - the ServletRequest.
_res - the ServletResponse. Return the debug information related to a ServletRequest object for the access.log.
Returns:
the debug information related to a ServletRequest object for the access.log.

getLogInfoAfterService

public static java.lang.String getLogInfoAfterService(javax.servlet.ServletRequest _req,
                                                      javax.servlet.ServletResponse _res)
Gets the debug information related to a ServletResponse object for the access.log.

Parameters:
req - the ServletRequest.
_res - the ServletResponse. Return the debug information related to a ServletResponse object for the access.log.
Returns:
the debug information related to a ServletResponse object for the access.log.

uploadSkinFile

public static java.util.Properties uploadSkinFile(javax.servlet.http.HttpServletRequest req,
                                                  java.lang.String tempDir)
                                           throws java.io.IOException
Uploads a single unzipped file and specifies the file name.

Parameters:
req - the HttpServletRequest.
tempDir - the temp directory for uploading.
Returns:
relevant properties of the files
Throws:
java.io.IOException

getUploadFileProperties

public static java.util.Properties getUploadFileProperties(javax.servlet.http.HttpServletRequest req,
                                                           java.lang.String tempDir)
                                                    throws java.io.IOException
Uploads and unzips zipped files and gets relevant properties of the files.

Parameters:
req - the HttpServletRequest.
tempDir - the temp directory for returning relevant properties of the files
Returns:
relevant properties of the files.
Throws:
java.io.IOException

getUploadFileProperties

public static java.util.Properties getUploadFileProperties(javax.servlet.http.HttpServletRequest req,
                                                           java.lang.String tempDir,
                                                           boolean isZip)
                                                    throws java.io.IOException
Uploads and gets relevant properties of the files.

Parameters:
req - the HttpServletRequest.
tempDir - the temp directory for uploading files.
isZip - if the uploaded files is compressed.
Returns:
relevant properties of the files.
Throws:
java.io.IOException

isStandaloneServer

public static boolean isStandaloneServer()
Checks whether the server is in an integrated environment.

Returns:
value true when it is standalone server, otherwise return false.

updateServletPaths

public static void updateServletPaths(javax.servlet.ServletContext context,
                                      javax.servlet.http.HttpServletRequest request)
Updates servlet paths in server.properties automatically. These servlet paths are used to indicate exactly servlet path for every servlet in JReport Server, e.g. "/servlet/sendfile".
A servlet path will be updated using this format: context root + servlet mapped path. context root is gotten from the parameter context, and servlet mapped path must be a constant string which JReport Server has defined for each servlet. In server.properties, the values of below properties will be updated
Property Name Servlet Mapped Path
jsp.webapp.sendfile sendfile
web.jreport_servlet_path jrserver
web.dhtml_jsp_path dhtmljsp
web.dhtml_servlet_entry_path jrdhtml
web.dhtml_servlet_path dhtml
web.help_servlet_path help

Parameters:
context - the ServletContext which the current servlet belongs to.
request - the HttpServletRequest received in current servlet.

getRealmDir

public static java.lang.String getRealmDir()
Gets the directory for realm files on the server. As default, a realm directory name is %reporthome%/realm, but in a cluster environment, a realm directory may be specified as a shared realm directory (indicated by resource.share.realm.dir in %reporthome%/bin/server.properties).

Returns:
the directory for realm files on the server.

isValidMonitoringURL

public static boolean isValidMonitoringURL(java.lang.String sURL,
                                           java.lang.String host,
                                           java.lang.String port)
Checks if the specific monitor URL is valid.

Parameters:
sURL - the monitor URL.
host - the monitor host.
port - the monitor port.
Returns:
Whether the specific monitor URL is valid.

isValidMonitoringURL

public static boolean isValidMonitoringURL(java.lang.String sURL)
Checks if the specific monitor URL is valid.

Parameters:
sURL - the monitor URL.
Returns:
Whether the specific monitor URL is valid.

getValidMonitoringURL

public static java.lang.String getValidMonitoringURL()
Gets the currently valid and active monitoring web url entry.

Returns:
the valid and active monitoring web url entry. If there is not one existed, return null.

getValidMonitoringURL

public static java.lang.String getValidMonitoringURL(java.lang.String host,
                                                     java.lang.String port)
Gets the currently valid and active monitoring web url entry.

Parameters:
host - the monitor host.
port - the monitor port.
Returns:
the valid and active monitoring web url entry. If there is not one existed, return null.

getHostAddress

public static java.lang.String getHostAddress(java.lang.String hostName)
Gets the host address by host name.

Parameters:
hostName - the host name.
Returns:
the host address.

getAutoRecoverTaskMaxTimes

public static int getAutoRecoverTaskMaxTimes()
Gets maximum retry times for auto recovering failed scheduled tasks.

Returns:
the maximum retry times.

getAutoRecoverTaskInterval

public static long getAutoRecoverTaskInterval()
Gets retry interval for auto recovering failed scheduled tasks.

Returns:
a long value to represent retry interval.

getAutoRecoverTaskRedoAll

public static boolean getAutoRecoverTaskRedoAll()
Checks whether to recreate all results for auto recovering failed scheduled tasks.

Returns:
true if all results will be recreated, otherwise return false.

getJspUri

public static java.lang.String getJspUri(javax.servlet.http.HttpServletRequest request,
                                         java.lang.String jspPath)
Gets the url of the jsp by jsp path.

Parameters:
request - the http servlet request.
jspPath - the path of the jsp.
Returns:
the jsp url.

getOndemandJspUri

public static java.lang.String getOndemandJspUri(javax.servlet.http.HttpServletRequest request)
Gets the url of the on demand page by the path of specified request.

Parameters:
the - based http request.

filterXSS

public static java.lang.String filterXSS(java.lang.String oldVal)
Filters html content to prevent Cross Site Scripting (XSS) vulnerability.

Parameters:
oldVal - the original html content
Returns:
the filtered html content with no XSS vulnerability.

getOndemandTaskInitPriority

public static int getOndemandTaskInitPriority()
Gets the initial priority of on demand tasks.

Returns:
the initial priority.

getScheduleTaskInitPriority

public static int getScheduleTaskInitPriority()
Gets the initial priority of scheduled tasks.

Returns:
the initial priority of scheduled tasks.

getReferer

public static java.lang.String getReferer(javax.servlet.http.HttpServletRequest request)
auto get jsp referer, used to relative jsp prosess business logic and return to the previous page. the jsp page would refresh by self, so referer will be save to hidden field named "http_header_referer".


printURL

public static java.lang.String printURL(javax.servlet.http.HttpServletRequest request)

handleFileNameByBrowserTypeForDownload

public static void handleFileNameByBrowserTypeForDownload(java.lang.String fileName,
                                                          javax.servlet.http.HttpServletRequest request,
                                                          javax.servlet.http.HttpServletResponse response)
                                                   throws java.lang.Exception
Encoding download file name by browser type, if browser type can not be identified, will set download file name by original file name. At the same time, it will use standard format for download file. Example : Content-Disposition: attachment;filename="encoded_file_name";filename*=UTF-8''utf8_encoded_file_name

Parameters:
fileName - Original file name
request - HttpServletRequest
response - HttpServletResponse
Throws:
java.lang.Exception