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 some static methods to create the HTTPRptServer, send message to client and change password etc.


Field Summary
 
Fields inherited from class jet.server.api.http.BaseHttpUtil
CONTENT_LOCATION, PROP_OUTPUT_ENCODING
 
Method Summary
static boolean checkAdminLogin(HttpServletRequest req, HttpServletResponse res)
          Check if the user is a admin user.
static boolean checkLogin(HttpServletRequest req, HttpServletResponse res)
          Do login if the HttpServletRequest has the login infomation.
static boolean checkPermission(HttpServletRequest req)
          Test if the user has the permission of the action for the resource in the server.
static void copyFilesByPrefix(java.lang.String srcDir, java.lang.String srcPrefix, java.lang.String destDir, java.lang.String destPrefix)
          Copy files from a directory to another directory, source files are begin with prefix specify by srcPrefix and "_" or "." follows prefix, and destination files are begin with prefix specify by destPrefix and "_" or "." follows prefix;
static java.lang.String filterXSS(java.lang.String oldVal)
           
static boolean getAdHoc()
          get if AdHoc feature is enabled.
static java.lang.String getAdhocJspPath()
          Get adhoc jsp path
static java.lang.String getAdhocServletPath()
          Get adhoc servlet path
static java.lang.String getAuthScheme()
          Get the scheme of authentication initialed by initEnv(..).
static long getAutoRecoverTaskInterval()
           
static int getAutoRecoverTaskMaxTimes()
           
static boolean getAutoRecoverTaskRedoAll()
           
static java.lang.String getBase(HttpServletRequest req, boolean convertEscapeForServletPath)
          Get the path of HttpServletRequest, including the servlet path.
static java.lang.String getBaseNoPath(HttpServletRequest req, boolean convertEscapeForServletPath)
          Get the servlet path.
static java.lang.String getDefaultDoc()
          Get the home page of JReport Enterprise Server initialed by initEnv(..).
static java.lang.String getHostAddress(java.lang.String hostName)
           
static HttpRptServer getHttpRptServer()
          Get the HttpRptServer object created by initEnv(...).
static java.lang.String getHttpURL()
          Gets the current Http prefix.
static java.lang.String getJRServletPath()
          Get jreport servlet path
static java.lang.String getJspUri(HttpServletRequest request, java.lang.String jspPath)
           
static java.lang.String getJSPWebAppName(java.lang.String propname)
          get jsp webapp name from (bin\server.properties)
static java.util.List getLanguageList()
          get the supported language list.
static java.lang.String getLogInfoAfterService(ServletRequest _req, ServletResponse _res)
          Get the debug info related to a ServletResponse object for the access.log.
static java.lang.String getLogInfoBeforeService(ServletRequest _req, ServletResponse _res)
          Get the debug info related to a ServletRequest object for the access.log.
static java.lang.String getOndemandJspUri(HttpServletRequest request)
           
static int getOndemandTaskInitPriority()
           
static java.lang.String getProductLicense()
          get license of server product
static java.lang.String getProductSystemInfo()
          get system information of server product
static java.lang.String getProductSystemProp()
          get system properties of server product
static java.lang.String getProductVersionInfo()
          get version information of server product
static java.lang.String getQueryBase(HttpServletRequest req, boolean convertEscapeForServletPath)
          Get the path of HttpServletRequest, including the servlet path for making HTTP query string.
static java.lang.String getQueryBaseNoPath(HttpServletRequest req, boolean convertEscapeForServletPath)
          Get the servlet path for making HTTP query string.
static java.lang.String getRealmDir()
          Get directory for realm files on server.
static RemoteFileService getRemoteFileService()
          get the RemoteFileService
static long getReportWaitTimeouts()
          Get the timeouts of waiting report in millisecond.
static int getScheduleTaskInitPriority()
           
static java.lang.String getServletPath(HttpServletRequest req)
          Get the servlet path.
static java.util.Properties getUploadFileProperties(HttpServletRequest req, java.lang.String tempDir)
          uploading and unzipping zipped files and get relevant properties of the files.
static java.util.Properties getUploadFileProperties(HttpServletRequest req, java.lang.String tempDir, boolean isZip)
          uploads and gets relevant properties of the files.
static java.lang.String getUser(HttpServletRequest req)
          Get the user ID related to a HttpServletRequest object.
static java.lang.String getValidMonitoringURL()
          Get the currently valid and active monitoring web url entry.
static java.lang.String getValidMonitoringURL(java.lang.String host, java.lang.String port)
           
static java.lang.String getWebAppUrl(HttpServletRequest req, java.lang.String appName)
          Get the url of given web app name, base on provided HttpServletRequest object.
static void initEnv(java.util.Properties props)
          Create and initialize the HttpRptServer object with the initial parameters.
static boolean isEnableDynamicResource()
          Tell whether resource from real path is enabled
static boolean isEnableMonitorLink()
           
static boolean isEnableTaskDuration()
          Tell whether enable task duration
static boolean isPipeline()
          if support pipeline for try-view reports
static boolean isPublishTempToVersion()
          Tell whether publish temp result to version system is enabled
static boolean isPublishTempToVersion(java.lang.String filename)
           
static boolean isRemoteServer()
          check whether a remote server
static boolean isSecure()
          Check if server needs checking security.
static boolean isShowNameWithPostfix()
          get a fag from (bin\server.properties) to show name with or without extension names
static boolean isShowVersionParamContents()
          if show contents of parameter files in version table
static boolean isStandaloneServer()
          check whether server is at integrated environment
static boolean isValidMonitoringURL(java.lang.String sURL)
           
static boolean isValidMonitoringURL(java.lang.String sURL, java.lang.String host, java.lang.String port)
           
static void logout(HttpServletRequest req)
           
static void processPartialRequest(HttpServletRequest req, HttpServletResponse res, java.io.File file, java.util.Hashtable ht)
           
static void restartServer()
          Restart the HttpRptServer.
static void sendFile(HttpServletRequest req, HttpServletResponse res, java.io.File file)
          Send a file to the client.
static void sendRemoteFile(HttpServletRequest req, HttpServletResponse res, java.lang.String filename)
          send a file to a remote end.
static void shutdownServer()
          Shutdown the HttpRptServer.
static void updateServletPaths(ServletContext context, HttpServletRequest request)
          Update servlet paths in server.properties automatically, these servlet paths are used to indicate exactly servlet path for every servlet in JReport Server, e.g.
static java.util.Properties uploadSkinFile(HttpServletRequest req, java.lang.String tempDir)
          uploading single unzipped file and specify the file name.
static boolean useRelativeWebAppUrl()
          Indicates use relative path or absolute path when get a web app url.
 
Methods inherited from class jet.server.api.http.BaseHttpUtil
changePassword, decodeEsc, dirIncludeCatalog, dirIncludeReport, encodeEsc, encodeEsc, getParameters, getResultType, getTempResultKey, hasPageSecurity, isClientAPI, isJRClient, makeQuery, 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)
Create and initialize the HttpRptServer object with the initial parameters. Use this method to avoid creating more than one HttpRptServer instance. If the HttpRptServer has already been started, this method will do nothing.

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:/JREntServer.
  • 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 Enterprise 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 Enterprise 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 charactors. 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 : Enable output of error messages of JRpeort Engine. Available values true/false.
  • vDebug : Enable output of debug messages of JRpeort Engine. Available values true/false.
  • logFile : Transfer output message of JRpeort engine to the file /logs/report.log or other file as specified.

isRemoteServer

public static boolean isRemoteServer()
check whether a remote server

Returns:

getRemoteFileService

public static RemoteFileService getRemoteFileService()
get the RemoteFileService

Returns:

getHttpRptServer

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

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

getAuthScheme

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

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

getDefaultDoc

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

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

getBase

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

For example:

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

getBaseNoPath

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

For example:

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

getQueryBase

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

For examples:

Parameters:
req - the HttpServletRequest.
convertEscapeForServletPath - indicates if to convert convert escape chars 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(HttpServletRequest req,
                                                  boolean convertEscapeForServletPath)
Get the servlet path for making HTTP query string.

For examples:

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

getUser

public static java.lang.String getUser(HttpServletRequest req)
Get the user ID related to a HttpServletRequest object.

Parameters:
req - the HttpServletRequest. return the user ID related to a HttpServletRequest object.

isSecure

public static boolean isSecure()
Check if server needs checking security. return if server needs checking security. deprecated since v6.1, replaced by jet.server.api.UserSessionManager.needSecurity().


restartServer

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

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

shutdownServer

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

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

getHttpURL

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


checkLogin

public static boolean checkLogin(HttpServletRequest req,
                                 HttpServletResponse res)
                          throws TooManyUsersException,
                                 java.io.IOException,
                                 TooManyTimesException,
                                 java.lang.RuntimeException,
                                 NoRemoteServerException
Do login if the HttpServletRequest has the login infomation. Also check the HTTP query fields APIConst.TAG_AUTH_UID, APIConst.TAG_AUTH_PWD or APIConst.TAG_AUTHORIZATION if the HttpServletRequest has not the login infomation. This method implicitly calls HttpUtil.initEnv(...). So one can get the HttpRptServer by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
Returns:
if the user attached to the HttpServletRequest login.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if a IOException occurs.
java.lang.RuntimeException
NoRemoteServerException

checkAdminLogin

public static boolean checkAdminLogin(HttpServletRequest req,
                                      HttpServletResponse res)
                               throws TooManyUsersException,
                                      java.io.IOException,
                                      TooManyTimesException,
                                      java.lang.RuntimeException,
                                      NoRemoteServerException
Check if the user is a admin user. Do login if the HttpServletRequest has the login infomation of a admin user. Also check the HTTP query fields APIConst.TAG_AUTH_UID, APIConst.TAG_AUTH_PWD or APIConst.TAG_AUTHORIZATION if the HttpServletRequest has not the login infomation. This method implicitly calls HttpUtil.initEnv(...). So one can get the HttpRptServer by HttpUtil.getHttpRptServer() after calling this method.

Parameters:
req - the HttpServletRequest.
res - the HttpServletResponse.
Returns:
if the user attached to the HttpServletRequest login.
Throws:
TooManyUsersException - if a TooManyUsersException occurs.
TooManyTimesException - if a TooManyTimesException occurs.
java.io.IOException - if a IOException occurs.
java.lang.RuntimeException
NoRemoteServerException

logout

public static void logout(HttpServletRequest req)

checkPermission

public static boolean checkPermission(HttpServletRequest req)
                               throws NoPrivilegeException
Test if the user has the permission of the action for the resource in the server. The action means the value of "jrs.cmd" of the query field in the HttpServletRequest or the HTTP method of the HttpServletRequest. The resource means the pathInfo of the HttpServletRequest.

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

sendFile

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

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

sendRemoteFile

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

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

getServletPath

public static java.lang.String getServletPath(HttpServletRequest req)
Get the servlet path.

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

getReportWaitTimeouts

public static long getReportWaitTimeouts()
Get the timeouts of waiting report in millisecond. This value is specified in sencond by the property "web.timeouts.report_wait" in the file /bin/server.properties.

Returns:
the timeouts in millisecond.

isPublishTempToVersion

public static boolean isPublishTempToVersion()
Tell whether publish temp result to version system is enabled

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

isPublishTempToVersion

public static boolean isPublishTempToVersion(java.lang.String filename)

isEnableDynamicResource

public static boolean isEnableDynamicResource()
Tell whether resource from real path is enabled

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

isEnableTaskDuration

public static boolean isEnableTaskDuration()
Tell whether enable task duration

Returns:
true if enable task duration, false disable it.

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
Copy files from a directory to another directory, source files are begin with prefix specify by srcPrefix and "_" or "." follows prefix, and destination files are begin with prefix specify by destPrefix and "_" or "." follows prefix;

Parameters:
srcDir - 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(HttpServletRequest req,
                                         HttpServletResponse res,
                                         java.io.File file,
                                         java.util.Hashtable ht)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

isShowNameWithPostfix

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


getJSPWebAppName

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

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

useRelativeWebAppUrl

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

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

getWebAppUrl

public static java.lang.String getWebAppUrl(HttpServletRequest req,
                                            java.lang.String appName)
Get the url of given web app name, base on provided HttpServletRequest object. Return value is various, depends on return value HttpUtil.useRelativeWebAppUrl(), if it is true, return a url relate 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() return 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 represent the appName base on provided request.
See Also:
useRelativeWebAppUrl()

getLanguageList

public static java.util.List getLanguageList()
get the supported language list.


isPipeline

public static boolean isPipeline()
if support pipeline for try-view reports


isShowVersionParamContents

public static boolean isShowVersionParamContents()
if show contents of parameter files in version table


getProductVersionInfo

public static java.lang.String getProductVersionInfo()
get version information of server product


getProductLicense

public static java.lang.String getProductLicense()
get license of server product


getProductSystemInfo

public static java.lang.String getProductSystemInfo()
get system information of server product


getAdhocServletPath

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

Returns:
the adhoc servlet path

getAdhocJspPath

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

Returns:
the adhoc jsp path

getJRServletPath

public static java.lang.String getJRServletPath()
Get jreport servlet path

Returns:
the jreport servlet path

isEnableMonitorLink

public static boolean isEnableMonitorLink()

getProductSystemProp

public static java.lang.String getProductSystemProp()
get system properties of server product


getAdHoc

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

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

getLogInfoBeforeService

public static java.lang.String getLogInfoBeforeService(ServletRequest _req,
                                                       ServletResponse _res)
Get the debug info related to a ServletRequest object for the access.log.

Parameters:
req - the ServletRequest.
_res - the ServletResponse. return the debug info related to a ServletRequest object for the access.log.

getLogInfoAfterService

public static java.lang.String getLogInfoAfterService(ServletRequest _req,
                                                      ServletResponse _res)
Get the debug info related to a ServletResponse object for the access.log.

Parameters:
req - the ServletRequest.
_res - the ServletResponse. return the debug info related to a ServletResponse object for the access.log.

uploadSkinFile

public static java.util.Properties uploadSkinFile(HttpServletRequest req,
                                                  java.lang.String tempDir)
                                           throws java.io.IOException
uploading single unzipped file and specify the file name.

Parameters:
req - the HttpServletRequest.
tempDir - the temp directory for uploading.
Throws:
java.io.IOException

getUploadFileProperties

public static java.util.Properties getUploadFileProperties(HttpServletRequest req,
                                                           java.lang.String tempDir)
                                                    throws java.io.IOException
uploading and unzipping zipped files and get relevant properties of the files.

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

getUploadFileProperties

public static java.util.Properties getUploadFileProperties(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 file is compressed. return relevant properties of the files
Throws:
java.io.IOException

isStandaloneServer

public static boolean isStandaloneServer()
check whether server is at integrated environment

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

updateServletPaths

public static void updateServletPaths(ServletContext context,
                                      HttpServletRequest request)
Update 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 as this format: context root + servlet mapped path, context root is gotten from parameter context, servlet mapped path must be a constant string which JReport Server has defined for each servlet. In server.properties, 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()
Get directory for realm files on server. As default, a realm directory name is %reporthome%/realm, but in cluster environment, a realm directory may be specified as a shared realm directory (indicated by resource.share.realm.dir in %reporthome%/bin/server.properties).


isValidMonitoringURL

public static boolean isValidMonitoringURL(java.lang.String sURL,
                                           java.lang.String host,
                                           java.lang.String port)

isValidMonitoringURL

public static boolean isValidMonitoringURL(java.lang.String sURL)

getValidMonitoringURL

public static java.lang.String getValidMonitoringURL()
Get 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)

getHostAddress

public static java.lang.String getHostAddress(java.lang.String hostName)

getAutoRecoverTaskMaxTimes

public static int getAutoRecoverTaskMaxTimes()

getAutoRecoverTaskInterval

public static long getAutoRecoverTaskInterval()

getAutoRecoverTaskRedoAll

public static boolean getAutoRecoverTaskRedoAll()

getJspUri

public static java.lang.String getJspUri(HttpServletRequest request,
                                         java.lang.String jspPath)

getOndemandJspUri

public static java.lang.String getOndemandJspUri(HttpServletRequest request)

filterXSS

public static java.lang.String filterXSS(java.lang.String oldVal)

getOndemandTaskInitPriority

public static int getOndemandTaskInitPriority()

getScheduleTaskInitPriority

public static int getScheduleTaskInitPriority()