Package com.webmethods.caf.wsclient.util
Class WSClientUtil
java.lang.Object
com.webmethods.caf.wsclient.util.WSClientUtil
A collection of simple utility methods similar to PathUtil and StringTools provided
by IBM My webMethods Server
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
Protocol prefix for a URL that describes a resource on the classpathstatic final char
static final String
Protocol prefix for a URL that describes a resource on the filesystemstatic final String
static final char
Map of ClassLoaders and their temp directories NOTE: not intended for external use, please use the {@link WsClientUtil.getClassloadTempDir()}static String
Map of extracted resources and their filenames NOTE: not intended for external usestatic final String
Prefix for temp directories created by WSClientstatic final String
Prefix for temp filenames created by WSClient -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendPath
(String dirName, String filePath) Append an file/directory to an existing directory path, ensuring that a single path separator character is placed between directory elements.static String
Concatenate two stringsstatic Map
constructClientAPI
(Class clazz, String packageName, String operationName) static boolean
copyResource
(Class<?> portTypeClass, String targetFile, String resource) Copy a resource from the classpath to a temp file.static int
copyStream
(InputStream inputStream, OutputStream outputStream) Copy the contents from anInputStream
to aOutputStream
static String
createTempDir
(String baseTempDir, String prefix) Create a unique temp subdirectory in the given base subdirectorystatic String
ensureForwardSlashes
(String path) Ensure that a path (as string) uses slash as a path separator.static String
ensureTrailingSlash
(String path) Ensure that a path has a trailing path separator character.static String
extractHostURL
(String endpointURL) Extract the host portion of a web service endpoint url.static String
getBaseName
(String filePath) Extract the base filename (no path info) from a file/path stringstatic String
getClassloaderTempDir
(ClassLoader classLoader) Create a temp subdirectory for a specific classloader NOTE: this is to ensure different components have different temp subdirectoriesstatic String
Get the temp directory specified by the OSstatic String
Get or create a temp directory unique to this process NOTE: necessary for generated a unique temp directory where multiple processes are using the WSClient libraryprotected static String
getResourceMapKey
(String url, Class<?> portType) static String
processURL
(String url, Class<?> portTypeClass) Process a resource URL.static String[]
processURLs
(String[] mapURLs, Class<?> portTypeClass) Process an array of resource URLs.static void
reloadResource
(Class<?> portTypeClass) static String
removeStartingSlash
(String path) Remove the trailing forward slash path separator character from a path stringstatic boolean
removeWsdlFromCache
(String wsdlURL, Class<?> portTypeClass) Remove a WSDL from the Glue cache and extracted resource cachestatic String
Strip the 'classpath:' protocol prefix from a URL stringstatic String
stripLastSegment
(String path) Extract the last segments of a path string (using the forward slash as a path separator) For example, the path c:/folder1/folder2 will return the value 'folder2'.static String
For a given path as string, convert any slash path separators into dot characters.
-
Field Details
-
FORWARD_SLASH
- See Also:
-
FORWARD_SLASH_CHAR
public static final char FORWARD_SLASH_CHAR- See Also:
-
DOT_CHAR
public static final char DOT_CHAR- See Also:
-
BACKWARD_SLASH
- See Also:
-
TEMP_DIR_PREFIX
Prefix for temp directories created by WSClient- See Also:
-
TEMP_FILENAME_PREFIX
Prefix for temp filenames created by WSClient- See Also:
-
CLASSPATH_PROTOCOL
Protocol prefix for a URL that describes a resource on the classpath- See Also:
-
FILE_PROTOCOL
Protocol prefix for a URL that describes a resource on the filesystem- See Also:
-
s_resourceMap
Map of extracted resources and their filenames NOTE: not intended for external use -
s_processTempDir
-
s_classloaderTempMap
Map of ClassLoaders and their temp directories NOTE: not intended for external use, please use the {@link WsClientUtil.getClassloadTempDir()}
-
-
Constructor Details
-
WSClientUtil
public WSClientUtil()
-
-
Method Details
-
getBaseName
Extract the base filename (no path info) from a file/path string- Parameters:
filePath
- the file/path URL to extract from as a string- Returns:
- the extracted base filename
-
appendPath
Append an file/directory to an existing directory path, ensuring that a single path separator character is placed between directory elements.- Parameters:
dirName
- the directory path to append to (as string)filePath
- the file or directory name to append to the directory path- Returns:
- the aggregated directory path
-
ensureTrailingSlash
Ensure that a path has a trailing path separator character. If the path already has a trailing separator, the path is return unmodified, otherwise the path separator is appended- Parameters:
path
- the path to ensure has a trailing path separator- Returns:
- the path as string
-
ensureForwardSlashes
Ensure that a path (as string) uses slash as a path separator. Any backslashes will be convereted to slashes.- Parameters:
path
- the path to ensure contains only slashes as the path separator, a null path will be ignored- Returns:
- the modified path, may be null if the initial path is null.
-
translateSlashToDot
For a given path as string, convert any slash path separators into dot characters. NOTE: this is useful when loading resources from classpath rather than from the filesystem- Parameters:
str
- the path as a string- Returns:
- the modified path
-
concat
Concatenate two strings- Parameters:
s1
- base string to appear firsts2
- second string to be appended to the first- Returns:
- the concatenated strings as a new string
-
removeStartingSlash
Remove the trailing forward slash path separator character from a path string- Parameters:
path
- the path to be processed- Returns:
- the modified path
-
stripLastSegment
Extract the last segments of a path string (using the forward slash as a path separator) For example, the path c:/folder1/folder2 will return the value 'folder2'.- Parameters:
path
- the path extract from- Returns:
- the last segment of the provided path as a string
-
copyStream
Copy the contents from anInputStream
to aOutputStream
- Parameters:
inputStream
- The source input stream to copy fromoutputStream
- the target output stream to copy to- Returns:
- return the total number of copied bytes as an integer
- Throws:
IOException
-
copyResource
public static boolean copyResource(Class<?> portTypeClass, String targetFile, String resource) throws IOException Copy a resource from the classpath to a temp file. NOTE: this is necessary for Glue web services, as .wsdl and .map files cannot be loaded from the classpath and much be copied to a temp file before being used- Parameters:
portTypeClass
- A Class in the same package as the resource to be loaded. This is usually a web service interface class and a .wsdl or .map file is expected to be in the same package.targetFile
- The name of the file to created in a temp subdirectoryresource
- URL of the resource to be copied to a temp directory, not included the URL protocol.- Returns:
- true if the operation was successful
- Throws:
IOException
-
removeWsdlFromCache
Remove a WSDL from the Glue cache and extracted resource cache- Parameters:
wsdlURL
- the URL of the .wsdl resource to remove from the resource cacheportTypeClass
- the web service interface class- Returns:
- true if the WSDL exists in the Glue cache and has been removed
-
stripClasspathProtocol
Strip the 'classpath:' protocol prefix from a URL string- Parameters:
url
- the URL string to process- Returns:
- the processed URL
-
processURL
Process a resource URL. If the URL is uses the 'classpath:' protocol, extract the resource to a temp subdirectory (since Glue can't use jar based resources directly) and return the new 'file:' protocol URL strings.- Parameters:
url
- the resource URLportTypeClass
- the web service interface class associated with this resource URL (for caching purposes)- Returns:
-
processURLs
Process an array of resource URLs. If any of the URL strings in the array uses the 'classpath:' protocol, we need to extract the resource to a temp subdirectory (since Glue can't use jar based resources directly) and return an array of new 'file:' protocol URL strings.- Parameters:
mapURLs
- an array of resource URL stringsportTypeClass
-- Returns:
-
getProcessTempDir
Get or create a temp directory unique to this process NOTE: necessary for generated a unique temp directory where multiple processes are using the WSClient library- Returns:
- the temp directory path as a string
- Throws:
IOException
-
getOsTempDir
Get the temp directory specified by the OS- Returns:
- the directory path as string
- Throws:
IOException
-
createTempDir
Create a unique temp subdirectory in the given base subdirectory- Parameters:
baseTempDir
- the base temp subdirectoryprefix
- the prefix to use when generating a unique subdirectory name- Returns:
- return the temp subdirectory path as a string
- Throws:
IOException
-
getClassloaderTempDir
Create a temp subdirectory for a specific classloader NOTE: this is to ensure different components have different temp subdirectories- Parameters:
classLoader
- the classloader to generate a unique temp subdirectory for- Returns:
- the unique temp subdirectory path as string
- Throws:
IOException
-
extractHostURL
Extract the host portion of a web service endpoint url. For example, extract http://localhost:8585 from the URL http://localhost:8585/services/basic/testEndpoint.- Parameters:
endpointURL
- the web service endpoint URL as string- Returns:
- the host portion of the web service endpoint URL
- Throws:
WSClientException
-
getResourceMapKey
-
reloadResource
-
constructClientAPI
-