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 voiddisplayCurrentStatus(LocalizedResource localUtil, String returnMessage, PrintWriter out) Display the current Network server statusvoiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Get the form of NetServlet.voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Get the form of NetServlet.private StringescapeHTML(String str) Escapes potentially dangerous characters in data written to the browser.private StringescapeSingleQuotes(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 StringfixLanguageCode(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 StringfixLanguageCode(String lang, int index) private LocalizedResourcegetCurrentAppUI(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 StringgetDoAction(javax.servlet.http.HttpServletRequest request) private StringgetForm(javax.servlet.http.HttpServletRequest request) private StringgetHtmlLabelledMessageInstance(LocalizedResource localUtil, String key, String id) get an HTML labelled message from the resource bundle file, according to the given key.private intgetIntParameter(javax.servlet.http.HttpServletRequest request, String name, String fieldKey, LocalizedResource localUtil, String returnMessage, PrintWriter out) Get an integer parameterprivate StringGet locale string from language which may have qvalue setprivate StringgetLogging(javax.servlet.http.HttpServletRequest request) private Stringget UTF8 parameter value and decode international charactersprivate booleanGet the currrent server status by using test connectionprivate StringgetTrace(javax.servlet.http.HttpServletRequest request) voidinit(javax.servlet.ServletConfig config) Initialize the servlet.private static booleanisServerStarted(NetworkServerControl server, int ntries) private booleanlogging(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Turn logging of connections onprivate voidprintAsContentHeader(String str, PrintWriter out) Print the received string as a header.private voidprintBanner(LocalizedResource localUtil, PrintWriter out) Print Derby Network Server bannerprivate voidprintErrorForm(LocalizedResource localUtil, Exception e, String returnMessage, PrintWriter out) Display an error formprivate voidprintErrorForm(LocalizedResource localUtil, String msg, String returnMessage, PrintWriter out) Display an error formprivate voidrunServer(LocalizedResource localUtil, String returnMessage, PrintWriter out) Start the network server and attempt to connect to it before returningprivate voidSet defaults for logging and tracing (both off)private booleansetNetParam(LocalizedResource localUtil, int max, int slice, String returnMessage, PrintWriter out) Set Network server parametersprivate booleanshutdownServer(LocalizedResource localUtil, String returnMessage, PrintWriter out) Shutdown the network serverprivate booleantraceAll(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out) Change tracing for all sessionsprivate booleantraceDirectory(LocalizedResource localUtil, String traceDirectory, String returnMessage, PrintWriter out) Set trace directoryprivate booleantraceSession(LocalizedResource localUtil, boolean val, int session, String returnMessage, PrintWriter out) Change tracing for a given sessionprivate inttranslationAvailable(String lang) Check if the required translation is availableMethods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods 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:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Parameters:
config- theServletConfigobject that contains configuration 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:
doGetin classjavax.servlet.http.HttpServlet- Parameters:
request- anHttpServletRequestobject that contains the request the client has made of the servletresponse- anHttpServletResponseobject 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:
doPostin classjavax.servlet.http.HttpServlet- Parameters:
request- anHttpServletRequestobject that contains the request the client has made of the servletresponse- anHttpServletResponseobject 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
-
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
-
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
-