public class ServerUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ServerUtils.GlassFishFilter
Filtering the set of directories with GlassFish server home subdirectory
shown to the user in file filter.
|
private static class |
ServerUtils.VersionFilter
Filtering the set of GlassFish servers using file name pattern.
|
Modifier and Type | Field and Description |
---|---|
static String |
AS_JAVA_ENV
GlassFish Java VM system environment
AS_JAVA variable name. |
private static String |
AUTH_BASIC_FIELD_SEPARATPR
GlassFish Basic Authorization user and password separator.
|
static String |
BUNDLE_VERSION
Manifest attribute Bundle-Version containing GlassFish
version
String . |
private static String |
FULL_VERSION_METHOD
GlassFish full version string getter method name.
|
private static String |
FULL_VERSION_PATTERN
Regex pattern to retrieve version string like 3.1.2.2 from
full version string.
|
static String |
GF_COMMON_UTIL_JAR
Common utilities JAR file name.
|
static String |
GF_DERBY_DIR_NAME
GlassFish server Derby subdirectory.
|
static String |
GF_DERBY_ROOT_PROPERTY
GlassFish server Derby root property name.
|
static String |
GF_DOMAIN_ARG
GlassFish server domain name command line argument.
|
static String |
GF_DOMAIN_CONFIG_DIR_NAME
GlassFish server domains subdirectory.
|
static String |
GF_DOMAIN_DIR_ARG
GlassFish server domain directory command line argument.
|
static String |
GF_DOMAIN_ROOT_PROPERTY
GlassFish server domain root property name.
|
static String |
GF_DOMAINS_DIR_NAME
GlassFish server domains subdirectory.
|
static String |
GF_EMBEDDED_DIR_NAME
GlassFish server embedded libraries subdirectory under libraries.
|
static String |
GF_EMBEDDED_STATIC_SHELL_JAR
Embedded static shell JAR file name.
|
static ServerUtils.GlassFishFilter |
GF_HOME_DIR_FILTER
GlassFish server home subdirectory filter instance.
|
static String |
GF_HOME_PROPERTY
GlassFish server home property name.
|
static String |
GF_JAVA_ROOT_PROPERTY
GlassFish server Java VM root property name.
|
static String |
GF_JAVAHELP_JAR
JavaHelp JAR file name.
|
static String |
GF_JERSEY_1_CORE_JAR
Jersey 1.x core JAR file name.
|
static String |
GF_JERSEY_2_COMMON_JAR
Jersey 2.x common JAR file name.
|
static String |
GF_LIB_DIR_NAME
GlassFish server libraries subdirectory.
|
static String |
GF_LOG_DIR_NAME
GlassFish server logs subdirectory.
|
static String |
GF_LOG_FILE_NAME
GlassFish server log file.
|
static String |
GF_MODULES_DIR_NAME
GlassFish server modules subdirectory.
|
static String |
GF_SERVICE_NOT_YET_READY_MSG
GlassFish server service response while server is not yet ready.
|
static String |
GF_VERIFIER_JAR
Verifier JAR file name.
|
static String |
GFV3_JAR_MATCHER |
static String |
GFV3_VERSION_MATCHER |
private static Logger |
LOGGER
Logger instance for this class.
|
private static Pattern |
MANIFEST_COMPONENT_COMP_PATTERN
REGEX pattern used to extract additional containers from containers
list of
Manifest attribute. |
private static String |
MANIFEST_COMPONENT_COMP_REGEX
REGEX expression used to extract additional containers from containers
list of
Manifest attribute. |
private static Pattern |
MANIFEST_COMPONENT_FULL_PATTERN
REGEX pattern used to extract component name and containers from
Manifest attribute. |
private static String |
MANIFEST_COMPONENT_FULL_REGEX
REGEX expression used to extract component name and containers from
Manifest attribute. |
static String |
MANIFEST_COMPONENTS_SEPARATOR
REGEX expression used to split components (applications) returned in
Manifest object from HTTP response. |
static String |
MANIFEST_EOL
End of line sequence in Manifest.
|
static String |
MANIFEST_RESOURCES_SEPARATOR
REGEX expression used to split resources returned in
Manifest object from HTTP response. |
static String |
VERIFIER_MAIN_CLASS
GlassFish VerifierMain class name (including package).
|
private static String |
VERSION_CLASS
GlassFish Version class name (including package).
|
Constructor and Description |
---|
ServerUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addComponentToMap(Map<String,List<String>> map,
String component)
Parse server component (application) record and add it into
Map containing container to components List
mapping. |
static void |
addPathElement(StringBuilder rootPath,
String next)
Append next path element to existing path in
StringBuilder . |
static String |
basicAuthCredentials(String user,
String password)
Build HTTP Basic authorization base64 encoded credentials argument
containing user name and password.
|
static String |
cmdLineArgument(String name,
String value)
Builds command line argument containing argument identifier, space
and argument value, e.g.
|
static File |
getCommonUtilJarInModules(String serverHome)
Build path to the
common-util.jar file in GlassFish modules
directory. |
static String |
getDerbyRoot(GlassFishServer server)
Get GlassFish server derby root full path.
|
static String |
getDomainConfigPath(String domainDir)
Get GlassFish server domain configuration directory full path from
domain root.
|
static String |
getDomainPath(GlassFishServer server)
Get GlassFish server domain root full path.
|
static String |
getEmbeddedStaticShellJar(String serverHome)
Build path to the
glassfish-embedded-static-shell.jar
library in embedded libraries directory. |
static File |
getFileFromPattern(String pattern,
File dir)
Search for file matching given
pattern in given
dir ectory tree. |
static File |
getJarInModules(String serverHome,
String jarName)
Build path to the supplied
.jar file in GlassFish
modules directory. |
static File |
getJarName(String serverHome,
String pattern)
Search for
.jar file matching given pattern
in <serverHome>/modules directory tree. |
static File |
getJarName(String serverHome,
String pattern,
String dir)
Search for
.jar file matching given pattern
in given directory tree. |
static String |
getJavaHelpJar(String serverHome)
Build path to the supplied
javahelp.jar library in GlassFish
modules directory. |
static File |
getJerseyCommonJarInModules(String serverHome)
Build path to the
jersey-common.jar or
jersey-core.jar file in GlassFish modules directory. |
static String |
getJerseyVersion(String serverHome)
Retrieve Jersey version string from GlassFish modules.
|
static File |
getServerLogFile(GlassFishServer server)
Get GlassFish server log
File object. |
static GlassFishVersion |
getServerVersion(String serverHome)
Retrieve GlassFish version from local installation using file access.
|
static String |
getVerifierJar(String serverHome)
Build path to the supplied
verifier.jar library in GlassFish
modules directory. |
static String |
getVersionString(String fullVersionString)
Retrieve version numbers substring from full version string.
|
static boolean |
isDASRunning(GlassFishServer server)
Tests if the server administrator's port is occupied.
|
static boolean |
isRunning(GlassFishServer server)
Tests if the server listener port is occupied.
|
static boolean |
isRunningLocal(String host,
int port)
Finds out if server is running on local host by binding to local port.
|
static boolean |
isRunningRemote(String host,
int port)
Finds out if server is running on remote host by connecting to remote
host and port.
|
static String |
javaRootProperty(String javaHome)
Get GlassFish server Java VM root property.
|
static String |
manifestDecode(String str)
Decode
Manifest string to remove EOL sequences. |
static boolean |
notYetReadyMsg(String msg)
Check if given message is the one returned by GlassFish server service
response while server is not yet ready.
|
static String |
serverLogFileRelativePath()
Build GlassFish server log file sub path under domains root directory.
|
private static final Logger LOGGER
public static final String AS_JAVA_ENV
AS_JAVA
variable name.
This value should be equal to system environment JAVA_HOME
value.public static final String GF_JAVA_ROOT_PROPERTY
public static final String GF_HOME_PROPERTY
glassfish
subdirectory under server installation root which
we usually call server home.public static final String GF_DOMAIN_ROOT_PROPERTY
public static final String GF_DERBY_ROOT_PROPERTY
public static final ServerUtils.GlassFishFilter GF_HOME_DIR_FILTER
public static final String GF_DOMAINS_DIR_NAME
public static final String GF_DOMAIN_CONFIG_DIR_NAME
public static final String GF_MODULES_DIR_NAME
public static final String GF_DERBY_DIR_NAME
public static final String GF_LIB_DIR_NAME
public static final String GF_EMBEDDED_DIR_NAME
public static String GF_LOG_DIR_NAME
public static String GF_LOG_FILE_NAME
public static final String GFV3_VERSION_MATCHER
public static final String GFV3_JAR_MATCHER
public static final String BUNDLE_VERSION
String
.public static final String GF_COMMON_UTIL_JAR
public static final String GF_JERSEY_2_COMMON_JAR
public static final String GF_JERSEY_1_CORE_JAR
public static final String GF_EMBEDDED_STATIC_SHELL_JAR
public static final String GF_VERIFIER_JAR
public static final String GF_JAVAHELP_JAR
private static String VERSION_CLASS
public static String VERIFIER_MAIN_CLASS
private static String FULL_VERSION_PATTERN
private static String FULL_VERSION_METHOD
private static String AUTH_BASIC_FIELD_SEPARATPR
public static String GF_DOMAIN_ARG
public static String GF_DOMAIN_DIR_ARG
public static final String GF_SERVICE_NOT_YET_READY_MSG
com.sun.enterprise.v3.admin.AdminAdapter
.public static final String MANIFEST_EOL
public static final String MANIFEST_RESOURCES_SEPARATOR
Manifest
object from HTTP response.public static final String MANIFEST_COMPONENTS_SEPARATOR
Manifest
object from HTTP response.private static final String MANIFEST_COMPONENT_FULL_REGEX
Manifest
attribute.private static final String MANIFEST_COMPONENT_COMP_REGEX
Manifest
attribute.private static final Pattern MANIFEST_COMPONENT_FULL_PATTERN
Manifest
attribute.private static final Pattern MANIFEST_COMPONENT_COMP_PATTERN
Manifest
attribute.public static File getJarName(String serverHome, String pattern)
.jar
file matching given pattern
in <serverHome>/modules
directory tree.
serverHome
- GlassFish server home.pattern
- File name pattern.File
object containing full .jar file
path or null
if no file was found.
public static File getJarName(String serverHome, String pattern, String dir)
.jar
file matching given pattern
in given directory tree.
serverHome
- GlassFish server home.pattern
- File name pattern.dir
- Directory tree root to be searched for
.jar file.
File
object containing full .jar file
path or null
if no file was found.
public static File getFileFromPattern(String pattern, File dir)
pattern
in given
dir
ectory tree.
pattern
- Name pattern to search for.dir
- Directory tree root to be searched for pattern.File
object that matches given pattern
or null
otherwise.public static void addPathElement(StringBuilder rootPath, String next)
StringBuilder
.
Path separator is added only when there is no one at the end of existing
path.
rootPath
- Already existing path in StringBuilder
.next
- Path to be appended at the end of already existing path.public static File getCommonUtilJarInModules(String serverHome)
common-util.jar
file in GlassFish modules
directory.
serverHome
- GlassFish server home directory.common-util.jar
file in GlassFish
modules directory.public static File getJarInModules(String serverHome, String jarName)
.jar
file in GlassFish
modules directory.
serverHome
- GlassFish server home directory. This argument
should not be null
.jarName
- Supplied JAR file name. This argument should not
be null
..jar
file in GlassFish
modules directory.public static File getJerseyCommonJarInModules(String serverHome)
jersey-common.jar
or
jersey-core.jar
file in GlassFish modules directory.
Searches for Jersey 1.x or 2.x common (core) jersey JAR file name
in GlassFish modules directory and returns File
that was
found or null
when no such a file exists and is readable.
serverHome
- GlassFish server home directory. This argument
should not be null
.public static String getVerifierJar(String serverHome)
verifier.jar
library in GlassFish
modules directory.
serverHome
- GlassFish server home directory. This argument
should not be null
.verifier.ja
file in GlassFish
modules directory.public static String getJavaHelpJar(String serverHome)
javahelp.jar
library in GlassFish
modules directory.
serverHome
- GlassFish server home directory. This argument
should not be null
.javahelp.jar
file in GlassFish
libraries directory.public static String getEmbeddedStaticShellJar(String serverHome)
glassfish-embedded-static-shell.jar
library in embedded libraries directory.
serverHome
- GlassFish server home directory. This argument
should not be null
.glassfish-embedded-static-shell.jar
file in GlassFish embedded libraries directory.public static String getJerseyVersion(String serverHome)
serverHome
- GlassFish server home directory. This argument
should not be null
.public static String getVersionString(String fullVersionString)
fullVersionString
- GlassFish server full version string, e.g.
GlassFish Server Open Source Edition
3.1.2.2 (build 5)
3.1.2.2
public static GlassFishVersion getServerVersion(String serverHome)
common-util.jar
archive and com.sun.appserv.server.util.Version
class.
It's not public GlassFish API so there is no guaranty for this to work
forever. However GlassFish development team promised to keep this
API working the same way in GlassFish 3 and 4.
serverHome
- GlassFish server home directory.public static String manifestDecode(String str)
Manifest
string to remove EOL sequences.
str
- String to be decoded.public static String basicAuthCredentials(String user, String password)
user
- Username to be stored into encoded argument.password
- Password to be stored into encoded argument.public static boolean isRunning(GlassFishServer server)
server
- GlassFish server entitytrue
when server listener port
is occupied or false
otherwise.public static boolean isDASRunning(GlassFishServer server)
server
- GlassFish server entitytrue
when server administrator port
is occupied or false
otherwise.public static boolean isRunningRemote(String host, int port)
host
- Server host.port
- Server port.true
when server port is accepting
connections or false
otherwise.public static boolean isRunningLocal(String host, int port)
host
- Server host or null
value for address of the
loopback interface.port
- Server port.true
when server port is accepting
connections or false
otherwise.public static String cmdLineArgument(String name, String value)
--name value
.
name
- Command line argument name including dashes at
the beginning.value
- Value to be appended prefixed with single space.public static void addComponentToMap(Map<String,List<String>> map, String component)
Map
containing container to components List
mapping.
Component records: <name> '<' <container>
[',' <container>] '>'
map
- Map where new component is stored under it's container key.component
- Component record retrieved from server.NullPointerException
- when provided map argument
is null
.public static String serverLogFileRelativePath()
public static String getDomainPath(GlassFishServer server)
server
- GlassFish server entitynull
when server domains root folder or domain name is not set.public static String getDomainConfigPath(String domainDir)
domainDir
- GlassFish server domain root full path.public static File getServerLogFile(GlassFishServer server)
File
object.
server
- GlassFish server entity.File
object.public static String getDerbyRoot(GlassFishServer server)
server
- GlassFish server entitynull
when server server installation directory is not set.public static String javaRootProperty(String javaHome)
javaHome
- Java VM root (home) directory to be set as property
value.public static boolean notYetReadyMsg(String msg)
msg
- Message to be checked.true
if given message is server service
response while server is not yet ready or false
otherwise.Copyright © 2013. All Rights Reserved.