Top Description Fields Constructors Methods
org.apache.derby.drda

public Class NetServlet

extends HttpServlet
Class Inheritance
Imports
java.io.IOException, .OutputStreamWriter, .PrintWriter, java.net.InetAddress, java.util.Locale, .Properties, .StringTokenizer, javax.servlet.ServletConfig, .ServletException, javax.servlet.http.HttpServlet, .HttpServletRequest, .HttpServletResponse, org.apache.derby.shared.common.reference.Property, org.apache.derby.iapi.tools.i18n.LocalizedResource

This servlet can be used to start Derby Network Server from a remote location.

These servlet configuration parameters are understood by this servlet.

Field Summary

Modifier and TypeField and Description
private String
private static final int
private static final String[]
private volatile boolean
private static final int
private static final int
private int
private NetworkServerControl
private static final String
private static final String
private volatile boolean
private volatile String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
displayCurrentStatus(LocalizedResource
LocalizedResource to use for localizing messages
localUtil
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Display the current Network server status

public synchronized void
doGet(HttpServletRequest
an HttpServletRequest object that contains the request the client has made of the servlet
request
,
HttpServletResponse
an HttpServletResponse object that contains the response the servlet sends to the client
response
)

Overrides javax.servlet.http.HttpServlet.doGet.

Get the form of NetServlet.
public void
doPost(HttpServletRequest
an HttpServletRequest object that contains the request the client has made of the servlet
request
,
HttpServletResponse
an HttpServletResponse object that contains the response the servlet sends to the client
response
)

Overrides javax.servlet.http.HttpServlet.doPost.

Get the form of NetServlet.
private String

Returns:

A sanitized string.
escapeHTML
(String
the string to escape
str
)

Escapes potentially dangerous characters in data written to the browser.

private String
escapeSingleQuotes(String
The string in which we want to escape single quotes.
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

Returns:

fixed version of the language, with _ separating parts and country in upper case
fixLanguageCode
(String
language to be fixed
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

Returns:

the appUI which fits the browsers preferences
getCurrentAppUI
(HttpServletRequest
HttpServetRequest for forms
request
,
String[]
Name of locale (return arg)
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

private String
private String
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(HttpServletRequest
HttpServetRequest for forms
request
,
String
parameter name
name
,
String
Key for the name of the field we're reading.
fieldKey
,
LocalizedResource
LocalizedResource to use in localizing messages
localUtil
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Get an integer parameter

private String

Returns:

stripped language string to use in matching
getLocStringFromLanguage
(String
language string to parse
lang
)

Get locale string from language which may have qvalue set

private String
private String

Returns:

decoded String
getParam
(HttpServletRequest
HttpServletRequest
request
,
String
Parameter name
paramName
)

get UTF8 parameter value and decode international characters

private boolean

Returns:

true if server is up and reachable; false; otherwise
getServerStatus
()

Get the currrent server status by using test connection

private String
public void
init(ServletConfig
the ServletConfig object that contains configutation information for this servlet
config
)

Overrides javax.servlet.GenericServlet.init.

Implements javax.servlet.Servlet.init.

Initialize the servlet.
private static boolean
private boolean

Returns:

true if succeeded; false; otherwise
logging
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
boolean val, String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Turn logging of connections on

private void
printAsContentHeader(String
The string to be printed as a header.
str
,
PrintWriter
Form PrintWriter
out
)

Print the received string as a header.

private void
printBanner(LocalizedResource localUtil, PrintWriter out)

Print Derby Network Server banner

private void
printErrorForm(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
Exception
Exception to be displayed
e
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Display an error form

private void
printErrorForm(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
String
String to be displayed
msg
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Display an error form

private void
runServer(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Start the network server and attempt to connect to it before returning

private void
setDefaults()

Set defaults for logging and tracing (both off)

private boolean

Returns:

true if succeeded; false; otherwise
setNetParam
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
int
maximum number of threads
max
,
int
time slice for each connection
slice
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Set Network server parameters

private boolean

Returns:

true if succeeded; false; otherwise
shutdownServer
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Shutdown the network server

private boolean

Returns:

true if succeeded; false; otherwise
traceAll
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
boolean
if true, turn tracing on, if false turn it off
val
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Change tracing for all sessions

private boolean

Returns:

true if succeeded; false; otherwise
traceDirectory
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
String
directory for trace files
traceDirectory
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Set trace directory

private boolean

Returns:

true if succeeded; false; otherwise
traceSession
(LocalizedResource
LocalizedResource to use to translate messages
localUtil
,
boolean
if true, turn tracing on, if false turn it off
val
,
int
session to trace
session
,
String
localized continue message for continue button on error form
returnMessage
,
PrintWriter
Form PrintWriter
out
)

Change tracing for a given session

private int

Returns:

index into language array if found, -1 otherwise;
translationAvailable
(String
language we are looking for
lang
)

Check if the required translation is available

Inherited from javax.servlet.http.HttpServlet:
doDeletedoHeaddoOptionsdoPutdoTracegetLastModifiedserviceservice

Field Detail

hostback to summary
private String host
INVALIDback to summary
private static final int INVALID
knownLangback to summary
private static final String[] knownLang
logStatusback to summary
private volatile boolean logStatus
MAX_CONNECT_TRYSback to summary
private static final int MAX_CONNECT_TRYS
NOT_GIVENback to summary
private static final int NOT_GIVEN
portNumberback to summary
private int portNumber
serverback to summary
private NetworkServerControl server
SERVLET_ADDRESSback to summary
private static final String SERVLET_ADDRESS
SERVLET_PROP_MESSAGESback to summary
private static final String SERVLET_PROP_MESSAGES
traceStatusback to summary
private volatile boolean traceStatus
tracingDirectoryback to summary
private volatile String tracingDirectory

Constructor Detail

NetServletback to summary
public NetServlet()

Method Detail

displayCurrentStatusback to summary
private void displayCurrentStatus(LocalizedResource localUtil, String returnMessage, PrintWriter out)

Display the current Network server status

Parameters
localUtil:LocalizedResource

LocalizedResource to use for localizing messages

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

doGetback to summary
public synchronized void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.doGet.

Get the form of NetServlet. Provides buttons and forms to control the Network server.

Parameters
request:HttpServletRequest

Doc from javax.servlet.http.HttpServlet.doGet.

an HttpServletRequest object that contains the request the client has made of the servlet

response:HttpServletResponse

Doc from javax.servlet.http.HttpServlet.doGet.

an HttpServletResponse object that contains the response the servlet sends to the client

Exceptions
ServletException:

Doc from javax.servlet.http.HttpServlet.doGet.

if the request for the GET could not be handled

IOException:

Doc from javax.servlet.http.HttpServlet.doGet.

if an input or output error is detected when the servlet handles the GET request

doPostback to summary
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.doPost.

Get the form of NetServlet. Provides a buttons and form to control the Network server

Parameters
request:HttpServletRequest

Doc from javax.servlet.http.HttpServlet.doPost.

an HttpServletRequest object that contains the request the client has made of the servlet

response:HttpServletResponse

Doc from javax.servlet.http.HttpServlet.doPost.

an HttpServletResponse object that contains the response the servlet sends to the client

Exceptions
ServletException:

Doc from javax.servlet.http.HttpServlet.doPost.

if the request for the POST could not be handled

IOException:

Doc from javax.servlet.http.HttpServlet.doPost.

if an input or output error is detected when the servlet handles the request

escapeHTMLback to summary
private String escapeHTML(String str)

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:String

the string to escape

Returns:String

A sanitized string.

escapeSingleQuotesback to summary
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.

Parameters
str:String

The string in which we want to escape single quotes.

fixLanguageCodeback to summary
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).

Parameters
lang:String

language to be fixed

Returns:String

fixed version of the language, with _ separating parts and country in upper case

fixLanguageCodeback to summary
private String fixLanguageCode(String lang, int index)
getCurrentAppUIback to summary
private LocalizedResource getCurrentAppUI(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:HttpServletRequest

HttpServetRequest for forms

locale:String[]

Name of locale (return arg)

Returns:LocalizedResource

the appUI which fits the browsers preferences

getDoActionback to summary
private String getDoAction(HttpServletRequest request) throws IOException
getFormback to summary
private String getForm(HttpServletRequest request) throws IOException
getHtmlLabelledMessageInstanceback to summary
private String getHtmlLabelledMessageInstance(LocalizedResource localUtil, String key, String id)

get an HTML labelled message from the resource bundle file, according to the given key.

getIntParameterback to summary
private int getIntParameter(HttpServletRequest request, String name, String fieldKey, LocalizedResource localUtil, String returnMessage, PrintWriter out)

Get an integer parameter

Parameters
request:HttpServletRequest

HttpServetRequest for forms

name:String

parameter name

fieldKey:String

Key for the name of the field we're reading.

localUtil:LocalizedResource

LocalizedResource to use in localizing messages

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

getLocStringFromLanguageback to summary
private String getLocStringFromLanguage(String lang)

Get locale string from language which may have qvalue set

Parameters
lang:String

language string to parse

Returns:String

stripped language string to use in matching

getLoggingback to summary
private String getLogging(HttpServletRequest request) throws IOException
getParamback to summary
private String getParam(HttpServletRequest request, String paramName) throws IOException

get UTF8 parameter value and decode international characters

Parameters
request:HttpServletRequest

HttpServletRequest

paramName:String

Parameter name

Returns:String

decoded String

getServerStatusback to summary
private boolean getServerStatus()

Get the currrent server status by using test connection

Returns:boolean

true if server is up and reachable; false; otherwise

getTraceback to summary
private String getTrace(HttpServletRequest request) throws IOException
initback to summary
public void init(ServletConfig config) throws ServletException

Overrides javax.servlet.GenericServlet.init.

Implements javax.servlet.Servlet.init.

Initialize the servlet. Configuration parameters:

  • portNumber
    - Port number
  • host
    - Host name
  • traceDirectory
    - location of trace directory
  • startNetworkServerOnInit
    - start the server on initialization
Parameters
config:ServletConfig

Doc from javax.servlet.GenericServlet.init.

the ServletConfig object that contains configutation information for this servlet

Exceptions
ServletException:

Doc from javax.servlet.GenericServlet.init.

if an exception occurs that interrupts the servlet's normal operation

isServerStartedback to summary
private static boolean isServerStarted(NetworkServerControl server, int ntries)
loggingback to summary
private boolean logging(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out)

Turn logging of connections on

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

printAsContentHeaderback to summary
private void printAsContentHeader(String str, PrintWriter out)

Print the received string as a header.

Parameters
str:String

The string to be printed as a header.

out:PrintWriter

Form PrintWriter

printBannerback to summary
private void printBanner(LocalizedResource localUtil, PrintWriter out)

Print Derby Network Server banner

printErrorFormback to summary
private void printErrorForm(LocalizedResource localUtil, Exception e, String returnMessage, PrintWriter out)

Display an error form

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

e:Exception

Exception to be displayed

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

printErrorFormback to summary
private void printErrorForm(LocalizedResource localUtil, String msg, String returnMessage, PrintWriter out)

Display an error form

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

msg:String

String to be displayed

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

runServerback to summary
private void runServer(LocalizedResource localUtil, String returnMessage, PrintWriter out) throws ServletException

Start the network server and attempt to connect to it before returning

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Exceptions
ServletException:
throws an exception if error in starting the Network Server during initialization
setDefaultsback to summary
private void setDefaults()

Set defaults for logging and tracing (both off)

setNetParamback to summary
private boolean setNetParam(LocalizedResource localUtil, int max, int slice, String returnMessage, PrintWriter out)

Set Network server parameters

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

max:int

maximum number of threads

slice:int

time slice for each connection

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

shutdownServerback to summary
private boolean shutdownServer(LocalizedResource localUtil, String returnMessage, PrintWriter out)

Shutdown the network server

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

traceAllback to summary
private boolean traceAll(LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out)

Change tracing for all sessions

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

val:boolean

if true, turn tracing on, if false turn it off

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

traceDirectoryback to summary
private boolean traceDirectory(LocalizedResource localUtil, String traceDirectory, String returnMessage, PrintWriter out)

Set trace directory

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

traceDirectory:String

directory for trace files

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

traceSessionback to summary
private boolean traceSession(LocalizedResource localUtil, boolean val, int session, String returnMessage, PrintWriter out)

Change tracing for a given session

Parameters
localUtil:LocalizedResource

LocalizedResource to use to translate messages

val:boolean

if true, turn tracing on, if false turn it off

session:int

session to trace

returnMessage:String

localized continue message for continue button on error form

out:PrintWriter

Form PrintWriter

Returns:boolean

true if succeeded; false; otherwise

translationAvailableback to summary
private int translationAvailable(String lang)

Check if the required translation is available

Parameters
lang:String

language we are looking for

Returns:int

index into language array if found, -1 otherwise;