Package org.wso2.carbon.utils
Class CarbonUtils
- java.lang.Object
-
- org.wso2.carbon.utils.CarbonUtils
-
public class CarbonUtils extends Object
A collection of useful utility methods
-
-
Constructor Summary
Constructors Constructor Description CarbonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 voidcheckSecurity()static voidcheckSecurity(List<String> allowedClasses)static voidcheckSecurity(Map<String,String> allowedMethods)static StringcomputeServiceHash(org.apache.axis2.description.AxisServiceGroup serviceGroup)Get the MD5 hash value of the service artifact corresponding to AxisServiceGroup serviceGroupstatic StringgetAxis2Repo()static StringgetAxis2ServicesDir(org.apache.axis2.engine.AxisConfiguration axisConfig)Reads the AAR services dir from the Axis config.static StringgetAxis2Xml()static StringgetBackendHttpPort(org.apache.axis2.context.ConfigurationContext configurationContext)static byte[]getBytesFromFile(File file)Returns the contents of the file in a byte array.static StringgetCAppDeploymentDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)This is method returns deployment dir for carbon apps for current tenant.static StringgetCarbonCatalinaHome()static StringgetCarbonConfigDirPath()static StringgetCarbonHome()static StringgetCarbonLogsPath()static StringgetCarbonOSGiDropinsDir()static StringgetCarbonRepository()static StringgetCarbonSecurityConfigDirPath()static StringgetCarbonTenantsDirPath()static intgetCommandListenerPort()Get the port of the command listener.static StringgetComponentsRepo()static org.apache.axis2.deployment.DeployergetDeployer(String className)static StringgetEtcCarbonConfigDirPath()static org.apache.axis2.description.AxisServicegetFaultyService(String serviceName, org.apache.axis2.context.ConfigurationContext configurationContext)Get a faulty servicestatic StringgetGhostMetafileDir(org.apache.axis2.engine.AxisConfiguration axisConfig)static StringgetManagementTransport()static StringgetMD5(byte[] content)static intgetPortFromServerConfig(String property)This is to read the port values defined in other config files, which are overridden from those in carbon.xml.static StringgetProxyContextPath(boolean isWorkerNode)Returns the proxy context path value specified in the carbon.xml.(Duplicated Util Method)static StringgetRegistryXMLPath()static TransformerFactorygetSecureTransformerFactory()Create a secure process enabled TransformerFactorystatic org.wso2.carbon.base.ServerConfigurationgetServerConfiguration()static StringgetServerURL(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession httpSession, org.apache.axis2.context.ConfigurationContext configCtx)static StringgetServerURL(org.wso2.carbon.base.api.ServerConfigurationService serverConfig, org.apache.axis2.context.ConfigurationContext configCtx)static StringgetServerXml()static StringgetTenantTmpDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig)There's a separate tmp space for each tenant under java temp dir.static StringgetTmpDir()static intgetTransportPort(org.apache.axis2.context.ConfigurationContext configContext, String transport)Get the port corresponding to a particular transportstatic intgetTransportPort(org.apache.axis2.engine.AxisConfiguration axisConfig, String transport)Get the port corresponding to a particular transportstatic intgetTransportPort(ConfigurationContextService configContextService, String transport)Get the port corresponding to a particular transportstatic intgetTransportProxyPort(org.apache.axis2.context.ConfigurationContext configContext, String transport)Get the proxy port corresponding to a particular transportstatic intgetTransportProxyPort(org.apache.axis2.engine.AxisConfiguration axisConfig, String transport)Get the proxy port corresponding to a particular transportstatic StringgetUserMgtXMLPath()static booleanisAdminConsoleEnabled()static booleanisChildNode()Check if this is an Instance started by a Java execstatic booleanisDepSyncEnabled()utility method to check whether deployment synchronizer enabled.static booleanisFilteredOutService(org.apache.axis2.description.AxisService service)Checks whether the given AxisService is an Admin Service or a Hidden Servicestatic booleanisMasterNode()Check if this is a ChildNode or Notstatic booleanisMultipleInstanceCase()Check whether this is the multiple Instance scenario- means started the server with -n argstatic booleanisOptimized()Check if the current server is optimized or not.static booleanisReadOnlyNode()Check whether this is the a node which should readonlystatic booleanisRemoteRegistry()static booleanisRunningInStandaloneMode()Is this Carbon server running in standalone mode?static booleanisRunningOnLocalTransportMode()static booleanisURL(String location)Check whther the specified Strin corresponds to a URLstatic booleanisWorkerNode()Check if the current server is a worker node In clustering setup some servers are run as worker nodes and some as management nodesstatic LonglastUpdatedTime(org.apache.axis2.description.AxisServiceGroup serviceGroup)Get the last updated time of the service artifact corresponding to AxisServiceGroup serviceGroupstatic voidregisterFaultyService(String artifactPath, String serviceType, org.apache.axis2.context.ConfigurationContext configurationContext)Register a faulty servicestatic InputStreamreplaceSystemVariablesInXml(InputStream xmlConfiguration)static StringreplaceSystemVariablesInXml(String xmlConfiguration)static voidresolveLeafNodeValue(Node node)static StringresolveSystemProperty(String text)static voidsetBasicAccessSecurityHeaders(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 voidsetBasicAccessSecurityHeaders(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 voidsetBasicAccessSecurityHeaders(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 InputStreamtoInputStream(Document doc)static booleanuseRegistryBasedRepository()Should we use a Registry based repo instead of a FileSystem based one?
-
-
-
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 ConfigurationContextServicetransport- 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 ConfigurationContexttransport- 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 ConfigurationContexttransport- 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 AxisConfigurationtransport- 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 AxisConfigurationtransport- 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
locationis 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 artifactserviceType- Service type of the faulty serviceconfigurationContext- 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 serviceconfigurationContext- ConfigurationContext- Returns:
- AxisService object corresponding to the
serviceName
-
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()
-
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-trueif 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-trueif 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 arrayaxisConfig- - 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
-
toInputStream
public static InputStream toInputStream(Document doc) throws CarbonException
- Parameters:
doc- the DOM.Document to be converted to InputStream.- Returns:
- Returns InputStream.
- Throws:
CarbonException
-
getSecureTransformerFactory
public static TransformerFactory getSecureTransformerFactory() throws TransformerConfigurationException
Create a secure process enabled TransformerFactory- Returns:
- Throws:
TransformerConfigurationException
-
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:
ExceptionCarbonException
-
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.
-
-