Package org.apache.derby.drda
Class NetServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.derby.drda.NetServlet
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class NetServlet
extends javax.servlet.http.HttpServlet
This servlet can be used to start Derby Network Server from a remote location.
These servlet configuration parameters are understood by this servlet.
portNumber
- Port number to use. The default is 1527.startNetworkServerOnInit
- Starts the Derby Network Server at servlet initialization if 'true'.tracingDirectory
- Directory for trace files
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
displayCurrentStatus
(LocalizedResource localUtil, String returnMessage, PrintWriter out) Display the current Network server statusvoid
doGet
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Get the form of NetServlet.void
doPost
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Get the form of NetServlet.private String
escapeHTML
(String str) Escapes potentially dangerous characters in data written to the browser.private String
escapeSingleQuotes
(String str) If the received string has one or more single quotes in it, replace each one with the HTML escape-code for a single quote (apostrophe) so that the string can be properly displayed on a submit button.private String
fixLanguageCode
(String lang) Fix the language code, as some browsers send then in a bad format (for instance, Firefox sends en-us instead of en_US).private String
fixLanguageCode
(String lang, int index) private LocalizedResource
getCurrentAppUI
(javax.servlet.http.HttpServletRequest request, String[] locale) Determine the locale file needed for this browsers preferences Defaults to the settings for derby.locale and derby.codeset if set English otherwise if browsers preferences can't be foundprivate String
getDoAction
(javax.servlet.http.HttpServletRequest request) private String
getForm
(javax.servlet.http.HttpServletRequest request) private String
getHtmlLabelledMessageInstance
(LocalizedResource localUtil, String key, String id) get an HTML labelled message from the resource bundle file, according to the given key.private int
getIntParameter
(javax.servlet.http.HttpServletRequest request, String name, String fieldKey, LocalizedResource localUtil, String returnMessage, PrintWriter out) Get an integer parameterprivate String
Get locale string from language which may have qvalue setprivate String
getLogging
(javax.servlet.http.HttpServletRequest request) private String
get UTF8 parameter value and decode international charactersprivate boolean
Get the currrent server status by using test connectionprivate String
getTrace
(javax.servlet.http.HttpServletRequest request) void
init
(javax.servlet.ServletConfig config) Initialize the servlet.private static boolean
isServerStarted
(NetworkServerControl server, int ntries) private boolean
logging
(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Turn logging of connections onprivate void
printAsContentHeader
(String str, PrintWriter out) Print the received string as a header.private void
printBanner
(LocalizedResource localUtil, PrintWriter out) Print Derby Network Server bannerprivate void
printErrorForm
(LocalizedResource localUtil, Exception e, String returnMessage, PrintWriter out) Display an error formprivate void
printErrorForm
(LocalizedResource localUtil, String msg, String returnMessage, PrintWriter out) Display an error formprivate void
runServer
(LocalizedResource localUtil, String returnMessage, PrintWriter out) Start the network server and attempt to connect to it before returningprivate void
Set defaults for logging and tracing (both off)private boolean
setNetParam
(LocalizedResource localUtil, int max, int slice, String returnMessage, PrintWriter out) Set Network server parametersprivate boolean
shutdownServer
(LocalizedResource localUtil, String returnMessage, PrintWriter out) Shutdown the network serverprivate boolean
traceAll
(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Change tracing for all sessionsprivate boolean
traceDirectory
(LocalizedResource localUtil, String traceDirectory, String returnMessage, PrintWriter out) Set trace directoryprivate boolean
traceSession
(LocalizedResource localUtil, boolean val, int session, String returnMessage, PrintWriter out) Change tracing for a given sessionprivate int
translationAvailable
(String lang) Check if the required translation is availableMethods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
MAX_CONNECT_TRYS
private static final int MAX_CONNECT_TRYS- See Also:
-
SERVLET_PROP_MESSAGES
- See Also:
-
SERVLET_ADDRESS
- See Also:
-
knownLang
-
host
-
portNumber
private int portNumber -
tracingDirectory
-
logStatus
private volatile boolean logStatus -
traceStatus
private volatile boolean traceStatus -
NOT_GIVEN
private static final int NOT_GIVEN- See Also:
-
INVALID
private static final int INVALID- See Also:
-
server
-
-
Constructor Details
-
NetServlet
public NetServlet()
-
-
Method Details
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException Initialize the servlet. Configuration parameters:portNumber
- Port numberhost
- Host nametraceDirectory
- location of trace directorystartNetworkServerOnInit
- start the server on initialization
- Specified by:
init
in interfacejavax.servlet.Servlet
- Overrides:
init
in classjavax.servlet.GenericServlet
- Parameters:
config
- theServletConfig
object that contains configutation information for this servlet- Throws:
javax.servlet.ServletException
- if an exception occurs that interrupts the servlet's normal operation- See Also:
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException Get the form of NetServlet. Provides buttons and forms to control the Network server.- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- anHttpServletRequest
object that contains the request the client has made of the servletresponse
- anHttpServletResponse
object that contains the response the servlet sends to the client- Throws:
javax.servlet.ServletException
- if the request for the GET could not be handledIOException
- if an input or output error is detected when the servlet handles the GET request- See Also:
-
doPost
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException Get the form of NetServlet. Provides a buttons and form to control the Network server- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- anHttpServletRequest
object that contains the request the client has made of the servletresponse
- anHttpServletResponse
object that contains the response the servlet sends to the client- Throws:
javax.servlet.ServletException
- if the request for the POST could not be handledIOException
- if an input or output error is detected when the servlet handles the request- See Also:
-
getForm
- Throws:
IOException
-
getDoAction
- Throws:
IOException
-
getLogging
- Throws:
IOException
-
getTrace
- Throws:
IOException
-
getParam
private String getParam(javax.servlet.http.HttpServletRequest request, String paramName) throws IOException get UTF8 parameter value and decode international characters- Parameters:
request
- HttpServletRequestparamName
- Parameter name- Returns:
- decoded String
- Throws:
IOException
-
runServer
private void runServer(LocalizedResource localUtil, String returnMessage, PrintWriter out) throws javax.servlet.ServletException Start the network server and attempt to connect to it before returning- Parameters:
localUtil
- LocalizedResource to use to translate messagesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Throws:
javax.servlet.ServletException
- throws an exception if error in starting the Network Server during initialization
-
printErrorForm
private void printErrorForm(LocalizedResource localUtil, Exception e, String returnMessage, PrintWriter out) Display an error form- Parameters:
localUtil
- LocalizedResource to use to translate messagese
- Exception to be displayedreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter
-
printErrorForm
private void printErrorForm(LocalizedResource localUtil, String msg, String returnMessage, PrintWriter out) Display an error form- Parameters:
localUtil
- LocalizedResource to use to translate messagesmsg
- String to be displayedreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter
-
displayCurrentStatus
private void displayCurrentStatus(LocalizedResource localUtil, String returnMessage, PrintWriter out) Display the current Network server status- Parameters:
localUtil
- LocalizedResource to use for localizing messagesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter
-
getServerStatus
private boolean getServerStatus()Get the currrent server status by using test connection- Returns:
- true if server is up and reachable; false; otherwise
-
shutdownServer
Shutdown the network server- Parameters:
localUtil
- LocalizedResource to use to translate messagesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
logging
private boolean logging(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Turn logging of connections on- Parameters:
localUtil
- LocalizedResource to use to translate messagesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
traceAll
private boolean traceAll(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Change tracing for all sessions- Parameters:
localUtil
- LocalizedResource to use to translate messagesval
- if true, turn tracing on, if false turn it offreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
traceSession
private boolean traceSession(LocalizedResource localUtil, boolean val, int session, String returnMessage, PrintWriter out) Change tracing for a given session- Parameters:
localUtil
- LocalizedResource to use to translate messagesval
- if true, turn tracing on, if false turn it offsession
- session to tracereturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
traceDirectory
private boolean traceDirectory(LocalizedResource localUtil, String traceDirectory, String returnMessage, PrintWriter out) Set trace directory- Parameters:
localUtil
- LocalizedResource to use to translate messagestraceDirectory
- directory for trace filesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
setNetParam
private boolean setNetParam(LocalizedResource localUtil, int max, int slice, String returnMessage, PrintWriter out) Set Network server parameters- Parameters:
localUtil
- LocalizedResource to use to translate messagesmax
- maximum number of threadsslice
- time slice for each connectionreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter- Returns:
- true if succeeded; false; otherwise
-
setDefaults
private void setDefaults()Set defaults for logging and tracing (both off) -
getIntParameter
private int getIntParameter(javax.servlet.http.HttpServletRequest request, String name, String fieldKey, LocalizedResource localUtil, String returnMessage, PrintWriter out) Get an integer parameter- Parameters:
request
- HttpServetRequest for formsname
- parameter namefieldKey
- Key for the name of the field we're reading.localUtil
- LocalizedResource to use in localizing messagesreturnMessage
- localized continue message for continue button on error formout
- Form PrintWriter
-
printBanner
Print Derby Network Server banner -
getCurrentAppUI
private LocalizedResource getCurrentAppUI(javax.servlet.http.HttpServletRequest request, String[] locale) Determine the locale file needed for this browsers preferences Defaults to the settings for derby.locale and derby.codeset if set English otherwise if browsers preferences can't be found- Parameters:
request
- HttpServetRequest for formslocale
- Name of locale (return arg)- Returns:
- the appUI which fits the browsers preferences
-
getLocStringFromLanguage
Get locale string from language which may have qvalue set- Parameters:
lang
- language string to parse- Returns:
- stripped language string to use in matching
-
translationAvailable
Check if the required translation is available- Parameters:
lang
- language we are looking for- Returns:
- index into language array if found, -1 otherwise;
-
fixLanguageCode
Fix the language code, as some browsers send then in a bad format (for instance, Firefox sends en-us instead of en_US).- Parameters:
lang
- language to be fixed- Returns:
- fixed version of the language, with _ separating parts and country in upper case
-
fixLanguageCode
-
getHtmlLabelledMessageInstance
get an HTML labelled message from the resource bundle file, according to the given key. -
printAsContentHeader
Print the received string as a header.- Parameters:
str
- The string to be printed as a header.out
- Form PrintWriter
-
escapeSingleQuotes
If the received string has one or more single quotes in it, replace each one with the HTML escape-code for a single quote (apostrophe) so that the string can be properly displayed on a submit button.- Parameters:
str
- The string in which we want to escape single quotes.
-
escapeHTML
Escapes potentially dangerous characters in data written to the browser.NOTE: This is a poor mans implementation - it doesn't protect against all kinds of attacks, and it cannot be used in all contexts.
- Parameters:
str
- the string to escape- Returns:
- A sanitized string.
-
isServerStarted
-