org.wso2.carbon.utils
Class CarbonUtils

java.lang.Object
  extended by org.wso2.carbon.utils.CarbonUtils

public class CarbonUtils
extends Object

A collection of useful utility methods


Constructor Summary
CarbonUtils()
           
 
Method Summary
static DeployerConfig[] addCappDeployer(DeployerConfig[] originalConfigs, org.apache.axis2.engine.AxisConfiguration axisConfig)
          Adds the cApp deployer config into the original DeployerConfig array..
static
<T> T[]
arrayCopyOf(T[] original)
          Returns a copy of the provided array.
static void checkSecurity()
           
static void checkSecurity(List<String> allowedClasses)
           
static void checkSecurity(Map<String,String> allowedMethods)
           
static String computeServiceHash(org.apache.axis2.description.AxisServiceGroup serviceGroup)
          Get the MD5 hash value of the service artifact corresponding to AxisServiceGroup serviceGroup
static String getAxis2Repo()
           
static String getAxis2ServicesDir(org.apache.axis2.engine.AxisConfiguration axisConfig)
          Reads the AAR services dir from the Axis config.
static String getAxis2Xml()
           
static String getBackendHttpPort(org.apache.axis2.context.ConfigurationContext configurationContext)
           
static byte[] getBytesFromFile(File file)
          Returns the contents of the file in a byte array.
static String getCAppDeploymentDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)
          This is method returns deployment dir for carbon apps for current tenant.
static String getCarbonCatalinaHome()
           
static String getCarbonConfigDirPath()
           
static String getCarbonHome()
           
static String getCarbonLogsPath()
           
static String getCarbonOSGiDropinsDir()
           
static String getCarbonRepository()
           
static String getCarbonSecurityConfigDirPath()
           
static String getCarbonTenantsDirPath()
           
static int getCommandListenerPort()
          Get the port of the command listener.
static String getComponentsRepo()
           
static org.apache.axis2.deployment.Deployer getDeployer(String className)
           
static String getEtcCarbonConfigDirPath()
           
static org.apache.axis2.description.AxisService getFaultyService(String serviceName, org.apache.axis2.context.ConfigurationContext configurationContext)
          Get a faulty service
static String getGhostMetafileDir(org.apache.axis2.engine.AxisConfiguration axisConfig)
           
static String getManagementTransport()
           
static String getMD5(byte[] content)
           
static int getPortFromServerConfig(String property)
          This is to read the port values defined in other config files, which are overridden from those in carbon.xml.
static String getProxyContextPath(boolean isWorkerNode)
          Returns the proxy context path value specified in the carbon.xml.(Duplicated Util Method)
static String getRegistryXMLPath()
           
static org.wso2.carbon.base.ServerConfiguration getServerConfiguration()
           
static String getServerURL(org.wso2.carbon.base.api.ServerConfigurationService serverConfig, org.apache.axis2.context.ConfigurationContext configCtx)
           
static String getServerURL(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession httpSession, org.apache.axis2.context.ConfigurationContext configCtx)
           
static String getServerXml()
           
static String getTenantTmpDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)
          There's a separate tmp space for each tenant under java temp dir.
static String getTmpDir()
           
static int getTransportPort(org.apache.axis2.engine.AxisConfiguration axisConfig, String transport)
          Get the port corresponding to a particular transport
static int getTransportPort(ConfigurationContextService configContextService, String transport)
          Get the port corresponding to a particular transport
static int getTransportPort(org.apache.axis2.context.ConfigurationContext configContext, String transport)
          Get the port corresponding to a particular transport
static int getTransportProxyPort(org.apache.axis2.engine.AxisConfiguration axisConfig, String transport)
          Get the proxy port corresponding to a particular transport
static int getTransportProxyPort(org.apache.axis2.context.ConfigurationContext configContext, String transport)
          Get the proxy port corresponding to a particular transport
static String getUserMgtXMLPath()
           
static boolean isAdminConsoleEnabled()
           
static boolean isChildNode()
          Check if this is an Instance started by a Java exec
static boolean isDepSyncEnabled()
          utility method to check whether deployment synchronizer enabled.
static boolean isFilteredOutService(org.apache.axis2.description.AxisService service)
          Checks whether the given AxisService is an Admin Service or a Hidden Service
static boolean isMasterNode()
          Check if this is a ChildNode or Not
static boolean isMultipleInstanceCase()
          Check whether this is the multiple Instance scenario- means started the server with -n arg
static boolean isOptimized()
          Check if the current server is optimized or not.
static boolean isReadOnlyNode()
          Check whether this is the a node which should readonly
static boolean isRemoteRegistry()
           
static boolean isRunningInStandaloneMode()
          Is this Carbon server running in standalone mode?
static boolean isRunningOnLocalTransportMode()
           
static boolean isURL(String location)
          Check whther the specified Strin corresponds to a URL
static boolean isWorkerNode()
          Check if the current server is a worker node In clustering setup some servers are run as worker nodes and some as management nodes
static Long lastUpdatedTime(org.apache.axis2.description.AxisServiceGroup serviceGroup)
          Get the last updated time of the service artifact corresponding to AxisServiceGroup serviceGroup
static void registerFaultyService(String artifactPath, String serviceType, org.apache.axis2.context.ConfigurationContext configurationContext)
          Register a faulty service
static InputStream replaceSystemVariablesInXml(InputStream xmlConfiguration)
           
static String replaceSystemVariablesInXml(String xmlConfiguration)
           
static void resolveLeafNodeValue(Node node)
           
static String resolveSystemProperty(String text)
           
static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe, org.apache.axis2.context.MessageContext msgContext)
          This is a utility method which can be used to set security headers in the message context.
static void setBasicAccessSecurityHeaders(String userName, String password, boolean rememberMe, org.apache.axis2.client.ServiceClient serviceClient)
          This is a utility method which can be used to set security headers in a service client.
static void setBasicAccessSecurityHeaders(String userName, String password, org.apache.axis2.client.ServiceClient serviceClient)
          This is a utility method which can be used to set security headers in a service client.
static InputStream toInputStream(Document doc)
           
static boolean useRegistryBasedRepository()
          Should we use a Registry based repo instead of a FileSystem based one?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CarbonUtils

public CarbonUtils()
Method Detail

isAdminConsoleEnabled

public static boolean isAdminConsoleEnabled()

getTransportPort

public static int getTransportPort(ConfigurationContextService configContextService,
                                   String transport)
Get the port corresponding to a particular transport

Parameters:
configContextService - The OSGi ConfigurationContextService
transport - The transport
Returns:
The port corresponding to the transport
Throws:
IllegalStateException - If no port is associated with the transport, or if this method has been called before the ListenerManager has started

getTransportPort

public static int getTransportPort(org.apache.axis2.context.ConfigurationContext configContext,
                                   String transport)
Get the port corresponding to a particular transport

Parameters:
configContext - The Axis2 ConfigurationContext
transport - The transport
Returns:
The port corresponding to the transport
Throws:
IllegalStateException - If no port is assocaited with the transport, or if this method has been called before the ListenerManager has started

getTransportProxyPort

public static int getTransportProxyPort(org.apache.axis2.context.ConfigurationContext configContext,
                                        String transport)
Get the proxy port corresponding to a particular transport

Parameters:
configContext - The Axis2 ConfigurationContext
transport - The transport
Returns:
The proxy port corresponding to the transport. -1 if the proxy port is not defined
Throws:
IllegalStateException - If no port is assocaited with the transport, or if this method has been called before the ListenerManager has started

getTransportPort

public static int getTransportPort(org.apache.axis2.engine.AxisConfiguration axisConfig,
                                   String transport)
Get the port corresponding to a particular transport

Parameters:
axisConfig - The AxisConfiguration
transport - The transport
Returns:
The port corresponding to the transport
Throws:
IllegalStateException - If no port is assocaited with the transport, or if this method has been called before the ListenerManager has started

getTransportProxyPort

public static int getTransportProxyPort(org.apache.axis2.engine.AxisConfiguration axisConfig,
                                        String transport)
Get the proxy port corresponding to a particular transport

Parameters:
axisConfig - The AxisConfiguration
transport - The transport
Returns:
The proxy port corresponding to the transport. -1 if this parameter is not defined
Throws:
IllegalStateException - If no port is assocaited with the transport, or if this method has been called before the ListenerManager has started

getAxis2Xml

public static String getAxis2Xml()

getServerXml

public static String getServerXml()

getCarbonHome

public static String getCarbonHome()

getCarbonCatalinaHome

public static String getCarbonCatalinaHome()

getCarbonTenantsDirPath

public static String getCarbonTenantsDirPath()

getEtcCarbonConfigDirPath

public static String getEtcCarbonConfigDirPath()

getCarbonSecurityConfigDirPath

public static String getCarbonSecurityConfigDirPath()

getCarbonConfigDirPath

public static String getCarbonConfigDirPath()

getCarbonLogsPath

public static String getCarbonLogsPath()

getComponentsRepo

public static String getComponentsRepo()

getCarbonOSGiDropinsDir

public static String getCarbonOSGiDropinsDir()

getAxis2Repo

public static String getAxis2Repo()

getRegistryXMLPath

public static String getRegistryXMLPath()

getUserMgtXMLPath

public static String getUserMgtXMLPath()

isURL

public static boolean isURL(String location)
Check whther the specified Strin corresponds to a URL

Parameters:
location - The String to be checked
Returns:
true - if location is a URL, false - otherwise

lastUpdatedTime

public static Long lastUpdatedTime(org.apache.axis2.description.AxisServiceGroup serviceGroup)
Get the last updated time of the service artifact corresponding to AxisServiceGroup serviceGroup

Parameters:
serviceGroup - The service group whose last updated time we need to get
Returns:
The last updated time of the service artifact corresponding to AxisServiceGroup serviceGroup. Will return null if a Axis2 URL repository is in use.

computeServiceHash

public static String computeServiceHash(org.apache.axis2.description.AxisServiceGroup serviceGroup)
Get the MD5 hash value of the service artifact corresponding to AxisServiceGroup serviceGroup

Parameters:
serviceGroup - The service group whose last updated time we need to get
Returns:
The MD5 hash of the service artifact corresponding to AxisServiceGroup serviceGroup. Will return null if a Axis2 URL repository is in use.

getTmpDir

public static String getTmpDir()
Returns:
absolute path to carbon tmp directory

getTenantTmpDirPath

public static String getTenantTmpDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)
There's a separate tmp space for each tenant under java temp dir. This method can be used to get the absolute path to current tenant's temp location. If the sub directories are not found already, those are created.

Parameters:
axisConfig - - AxisConfiguration instance of the current tenant
Returns:
- absolute path to tmp tenant space

getCommandListenerPort

public static int getCommandListenerPort()
Get the port of the command listener. A server socket is opened on this port to listen to incoming commands

Returns:
The command listener port

registerFaultyService

public static void registerFaultyService(String artifactPath,
                                         String serviceType,
                                         org.apache.axis2.context.ConfigurationContext configurationContext)
                                  throws org.apache.axis2.AxisFault
Register a faulty service

Parameters:
artifactPath - Path of the faulty service artifact
serviceType - Service type of the faulty service
configurationContext - ConfigurationContext
Throws:
org.apache.axis2.AxisFault - If an error occurs while creating the service type Axis2 parameter

getFaultyService

public static org.apache.axis2.description.AxisService getFaultyService(String serviceName,
                                                                        org.apache.axis2.context.ConfigurationContext configurationContext)
Get a faulty service

Parameters:
serviceName - Name of the faulty service
configurationContext - ConfigurationContext
Returns:
AxisService object corresponding to the serviceName

isRemoteRegistry

public static boolean isRemoteRegistry()
                                throws Exception
Throws:
Exception

getCarbonRepository

public static String getCarbonRepository()

getServerConfiguration

public static org.wso2.carbon.base.ServerConfiguration getServerConfiguration()

isMasterNode

public static boolean isMasterNode()
Check if this is a ChildNode or Not

Returns:
true if the instance is a child node in multiple instance scenario

isChildNode

public static boolean isChildNode()
Check if this is an Instance started by a Java exec

Returns:
true if this is an instance started by Java exec

isMultipleInstanceCase

public static boolean isMultipleInstanceCase()
Check whether this is the multiple Instance scenario- means started the server with -n arg

Returns:
true if the server started with -n argument

isReadOnlyNode

public static boolean isReadOnlyNode()
Check whether this is the a node which should readonly

Returns:
true if the server started with -n argument

getBytesFromFile

public static byte[] getBytesFromFile(File file)
                               throws CarbonException
Returns the contents of the file in a byte array.

Parameters:
file - the file the to read
Returns:
the content of the file
Throws:
CarbonException - throws if the operation failed.

getMD5

public static String getMD5(byte[] content)

isRunningInStandaloneMode

public static boolean isRunningInStandaloneMode()
Is this Carbon server running in standalone mode?

Returns:
true is this Carbon server is running in standalone mode, false - if it is running as a webapp within another servlet container

useRegistryBasedRepository

public static boolean useRegistryBasedRepository()
Should we use a Registry based repo instead of a FileSystem based one?

Returns:
true - if registry based repo should be used system-wide

checkSecurity

public static void checkSecurity()

checkSecurity

public static void checkSecurity(List<String> allowedClasses)

checkSecurity

public static void checkSecurity(Map<String,String> allowedMethods)

getBackendHttpPort

public static String getBackendHttpPort(org.apache.axis2.context.ConfigurationContext configurationContext)
                                 throws Exception
Throws:
Exception

getServerURL

public static String getServerURL(org.wso2.carbon.base.api.ServerConfigurationService serverConfig,
                                  org.apache.axis2.context.ConfigurationContext configCtx)

getServerURL

public static String getServerURL(javax.servlet.ServletContext servletContext,
                                  javax.servlet.http.HttpSession httpSession,
                                  org.apache.axis2.context.ConfigurationContext configCtx)

getManagementTransport

public static String getManagementTransport()
Returns:
The transport on which the management functionality is available

arrayCopyOf

public static <T> T[] arrayCopyOf(T[] original)
Returns a copy of the provided array. Same as the JDK 1.6 Arrays.copyOf() method

Type Parameters:
T - Type of objects in the original array
Parameters:
original - The original array
Returns:
Copy of the provided array

getPortFromServerConfig

public static int getPortFromServerConfig(String property)
This is to read the port values defined in other config files, which are overridden from those in carbon.xml.

Parameters:
property -
Returns:

isFilteredOutService

public static boolean isFilteredOutService(org.apache.axis2.description.AxisService service)
Checks whether the given AxisService is an Admin Service or a Hidden Service

Parameters:
service - - AxisService instance
Returns:
- filtered service or not

isRunningOnLocalTransportMode

public static boolean isRunningOnLocalTransportMode()

getAxis2ServicesDir

public static String getAxis2ServicesDir(org.apache.axis2.engine.AxisConfiguration axisConfig)
Reads the AAR services dir from the Axis config. if it is null, returns the default value used in Carbon

Parameters:
axisConfig - - AxisConfiguration instance
Returns:
- services dir name

setBasicAccessSecurityHeaders

public static void setBasicAccessSecurityHeaders(String userName,
                                                 String password,
                                                 boolean rememberMe,
                                                 org.apache.axis2.client.ServiceClient serviceClient)
This is a utility method which can be used to set security headers in a service client. This method will create authorization header according to basic security protocol. i.e. encodeBase64(username:password) and put it in a HTTP header with name "Authorization".

Parameters:
userName - User calling the service.
password - Password of the user.
rememberMe - true if UI asks to persist remember me cookie.
serviceClient - The service client used in the communication.

setBasicAccessSecurityHeaders

public static void setBasicAccessSecurityHeaders(String userName,
                                                 String password,
                                                 boolean rememberMe,
                                                 org.apache.axis2.context.MessageContext msgContext)
                                          throws org.apache.axis2.AxisFault
This is a utility method which can be used to set security headers in the message context. This method will create authorization header according to basic security protocol. i.e. encodeBase64(username:password) and put it in a HTTP header with name "Authorization".

Parameters:
userName - User calling the service.
password - Password of the user.
rememberMe - true if UI asks to persist remember me cookie.
msgContext - The MessageContext of the message.
Throws:
org.apache.axis2.AxisFault

setBasicAccessSecurityHeaders

public static void setBasicAccessSecurityHeaders(String userName,
                                                 String password,
                                                 org.apache.axis2.client.ServiceClient serviceClient)
This is a utility method which can be used to set security headers in a service client. This method will create authorization header according to basic security protocol. i.e. encodeBase64(username:password) and put it in a HTTP header with name "Authorization".

Parameters:
userName - User calling the service.
password - Password of the user.
serviceClient - The service client used in the communication.

addCappDeployer

public static DeployerConfig[] addCappDeployer(DeployerConfig[] originalConfigs,
                                               org.apache.axis2.engine.AxisConfiguration axisConfig)
Adds the cApp deployer config into the original DeployerConfig array.. This is to fix : https://wso2.org/jira/browse/CARBON-13598

Parameters:
originalConfigs - - original DeployerConfig array
axisConfig - - AxisConfiguration instance to get tenant id
Returns:
- new array which includes cApp deployer

getCAppDeploymentDirPath

public static String getCAppDeploymentDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)
This is method returns deployment dir for carbon apps for current tenant.

Parameters:
axisConfig - - AxisConfiguration instance of the current tenant
Returns:
- absolute path to tenant capp deployment space

replaceSystemVariablesInXml

public static InputStream replaceSystemVariablesInXml(InputStream xmlConfiguration)
                                               throws CarbonException
Parameters:
xmlConfiguration - InputStream that carries xml configuration
Returns:
returns a InputStream that has evaluated system variables in input
Throws:
CarbonException

resolveLeafNodeValue

public static void resolveLeafNodeValue(Node node)

replaceSystemVariablesInXml

public static String replaceSystemVariablesInXml(String xmlConfiguration)
                                          throws CarbonException
Throws:
CarbonException

resolveSystemProperty

public static String resolveSystemProperty(String text)

toInputStream

public static InputStream toInputStream(Document doc)
                                 throws CarbonException
Parameters:
doc - the DOM.Document to be converted to InputStream.
Returns:
Returns InputStream.
Throws:
CarbonException

isWorkerNode

public static boolean isWorkerNode()
Check if the current server is a worker node In clustering setup some servers are run as worker nodes and some as management nodes

Returns:

isOptimized

public static boolean isOptimized()
Check if the current server is optimized or not. This mode is more suitable to run Carbon kernel on resource constrained environments.

Returns:
isOptimized

isDepSyncEnabled

public static boolean isDepSyncEnabled()
utility method to check whether deployment synchronizer enabled.

Returns:

getGhostMetafileDir

public static String getGhostMetafileDir(org.apache.axis2.engine.AxisConfiguration axisConfig)

getDeployer

public static org.apache.axis2.deployment.Deployer getDeployer(String className)
                                                        throws CarbonException
Parameters:
className - name of the class to build the deployer
Returns:
Deployer
Throws:
Exception
CarbonException

getProxyContextPath

public static String getProxyContextPath(boolean isWorkerNode)
Returns the proxy context path value specified in the carbon.xml.(Duplicated Util Method)

Parameters:
isWorkerNode - If isWorkerNode is true then this method returns the proxy context path of the corresponding worker node. If the worker proxy context path is not specified, this method returns the value specified for the proxy context path.
Returns:
the proxy context path value.


Copyright © 2014 WSO2 Inc. All rights reserved.