Class WSClientUtil

java.lang.Object
com.webmethods.caf.wsclient.util.WSClientUtil

public class WSClientUtil extends Object
A collection of simple utility methods similar to PathUtil and StringTools provided by IBM My webMethods Server
  • Field Details

    • FORWARD_SLASH

      public static final String 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

      public static final String BACKWARD_SLASH
      See Also:
    • TEMP_DIR_PREFIX

      public static final String TEMP_DIR_PREFIX
      Prefix for temp directories created by WSClient
      See Also:
    • TEMP_FILENAME_PREFIX

      public static final String TEMP_FILENAME_PREFIX
      Prefix for temp filenames created by WSClient
      See Also:
    • CLASSPATH_PROTOCOL

      public static final String CLASSPATH_PROTOCOL
      Protocol prefix for a URL that describes a resource on the classpath
      See Also:
    • FILE_PROTOCOL

      public static final String FILE_PROTOCOL
      Protocol prefix for a URL that describes a resource on the filesystem
      See Also:
    • s_resourceMap

      public static Map<String,String> s_resourceMap
      Map of extracted resources and their filenames NOTE: not intended for external use
    • s_processTempDir

      public static String s_processTempDir
    • s_classloaderTempMap

      public static Map<Object,String> 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

      public static String getBaseName(String filePath)
      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

      public static 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.
      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

      public static String ensureTrailingSlash(String path)
      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

      public static String ensureForwardSlashes(String path)
      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

      public static String translateSlashToDot(String str)
      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

      public static String concat(String s1, String s2)
      Concatenate two strings
      Parameters:
      s1 - base string to appear first
      s2 - second string to be appended to the first
      Returns:
      the concatenated strings as a new string
    • removeStartingSlash

      public static String removeStartingSlash(String path)
      Remove the trailing forward slash path separator character from a path string
      Parameters:
      path - the path to be processed
      Returns:
      the modified path
    • stripLastSegment

      public static 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'.
      Parameters:
      path - the path extract from
      Returns:
      the last segment of the provided path as a string
    • copyStream

      public static int copyStream(InputStream inputStream, OutputStream outputStream) throws IOException
      Copy the contents from an InputStream to a OutputStream
      Parameters:
      inputStream - The source input stream to copy from
      outputStream - 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 subdirectory
      resource - 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

      public static boolean removeWsdlFromCache(String wsdlURL, Class<?> portTypeClass)
      Remove a WSDL from the Glue cache and extracted resource cache
      Parameters:
      wsdlURL - the URL of the .wsdl resource to remove from the resource cache
      portTypeClass - the web service interface class
      Returns:
      true if the WSDL exists in the Glue cache and has been removed
    • stripClasspathProtocol

      public static String stripClasspathProtocol(String url)
      Strip the 'classpath:' protocol prefix from a URL string
      Parameters:
      url - the URL string to process
      Returns:
      the processed URL
    • processURL

      public static String processURL(String url, Class<?> portTypeClass)
      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 URL
      portTypeClass - the web service interface class associated with this resource URL (for caching purposes)
      Returns:
    • processURLs

      public static String[] processURLs(String[] mapURLs, Class<?> portTypeClass)
      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 strings
      portTypeClass -
      Returns:
    • getProcessTempDir

      public static String getProcessTempDir() throws IOException
      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

      public static String getOsTempDir() throws IOException
      Get the temp directory specified by the OS
      Returns:
      the directory path as string
      Throws:
      IOException
    • createTempDir

      public static String createTempDir(String baseTempDir, String prefix) throws IOException
      Create a unique temp subdirectory in the given base subdirectory
      Parameters:
      baseTempDir - the base temp subdirectory
      prefix - the prefix to use when generating a unique subdirectory name
      Returns:
      return the temp subdirectory path as a string
      Throws:
      IOException
    • getClassloaderTempDir

      public static String getClassloaderTempDir(ClassLoader classLoader) throws IOException
      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

      public static String extractHostURL(String endpointURL) throws WSClientException
      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

      protected static String getResourceMapKey(String url, Class<?> portType)
    • reloadResource

      public static void reloadResource(Class<?> portTypeClass)
    • constructClientAPI

      public static Map constructClientAPI(Class clazz, String packageName, String operationName)