Package org.wso2.carbon.utils
Class CarbonUtils
java.lang.Object
org.wso2.carbon.utils.CarbonUtils
A collection of useful utility methods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 voidstatic 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 booleanCheck if admin services are disabled or not.static Stringstatic StringgetAxis2ServicesDir(org.apache.axis2.engine.AxisConfiguration axisConfig) Reads the AAR services dir from the Axis config.static Stringstatic 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 Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic intGet the port of the command listener.static Stringstatic org.apache.axis2.deployment.DeployergetDeployer(String className) getDiagnosticLogMode(int tenantId) Get the diagnostic log mode for the tenant.static Stringstatic 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 Stringstatic 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 Stringstatic TransformerFactoryCreate a secure process enabled TransformerFactory.static org.wso2.carbon.base.ServerConfigurationstatic 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 Stringstatic StringgetTenantTmpDirPath(org.apache.axis2.engine.AxisConfiguration axisConfig) There's a separate tmp space for each tenant under java temp dir.static Stringstatic 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 Stringstatic booleanstatic booleanCheck if this is an Instance started by a Java execstatic booleanutility method to check whether deployment synchronizer enabled.static booleanChecks whether diagnostic logs are enabled.static booleanCheck whether the V2 audit logs are enabled.static booleanisFilteredOutService(org.apache.axis2.description.AxisService service) Checks whether the given AxisService is an Admin Service or a Hidden Servicestatic booleanFunction to extract InputValidationEnabled configuration from carbon.xml.static booleanDeprecated.static booleanFunction to extract ManagementConsoleDeprecationBannerEnabled configuration from carbon.xml.static booleanCheck if this is a ChildNode or Notstatic booleanCheck if microsecond truncate is enabled in log management configuration.static booleanCheck whether this is the multiple Instance scenario- means started the server with -n argstatic booleanCheck if the current server is optimized or not.static booleanCheck whether this is the a node which should readonlystatic booleanstatic booleanIs this Carbon server running in standalone mode?static booleanstatic booleanCheck whther the specified Strin corresponds to a URLstatic booleanCheck 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 voidpublishAuditLogs(Map<String, Object> auditLogData) Publish audit logs to the audit log file.static voidpublishDiagnosticLog(Map<String, Object> diagnosticLogData) Publish diagnostic log to the diagnostic log file.Retrieves the 'DiagnosticLogMode' from the cached ServerConfiguration.static 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 voidsetDiagnosticLogMode(int tenantId) Retrieves the 'DiagnosticLogMode' from the ServerConfiguration and process it before returning.static InputStreamtoInputStream(Document doc) static booleanShould we use a Registry based repo instead of a FileSystem based one?
-
Constructor Details
-
CarbonUtils
public CarbonUtils()
-
-
Method Details
-
isAdminConsoleEnabled
public static boolean isAdminConsoleEnabled() -
isMicrosecondTruncateEnabled
public static boolean isMicrosecondTruncateEnabled()Check if microsecond truncate is enabled in log management configuration.- Returns:
- true if microsecond truncate is enabled, false otherwise
-
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
-
getServerXml
-
getCarbonHome
-
getCarbonCatalinaHome
-
getCarbonTenantsDirPath
-
getEtcCarbonConfigDirPath
-
getCarbonSecurityConfigDirPath
-
getCarbonConfigDirPath
-
getCarbonLogsPath
-
getComponentsRepo
-
getCarbonOSGiDropinsDir
-
getAxis2Repo
-
getRegistryXMLPath
-
getUserMgtXMLPath
-
isURL
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
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
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
- Returns:
- absolute path to carbon tmp directory
-
getTenantTmpDirPath
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
-
isRemoteRegistry
- Throws:
Exception
-
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
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
-
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
-
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
- 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
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
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
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
-
replaceSystemVariablesInXml
- Throws:
CarbonException
-
resolveSystemProperty
-
toInputStream
- Parameters:
doc- the DOM.Document to be converted to InputStream.- Returns:
- Returns InputStream.
- Throws:
CarbonException
-
getSecureTransformerFactory
public static TransformerFactory getSecureTransformerFactory() throws TransformerConfigurationExceptionCreate a secure process enabled TransformerFactory.- Returns:
- A new instance of TransformerFactory.
- Throws:
TransformerConfigurationException- if a configuration error has occurred while processing XML securely.
-
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
-
disableAdminServices
public static boolean disableAdminServices()Check if admin services are disabled or not. Enabled by default for latest IS versions.- Returns:
- disableAdminServices.
-
isDepSyncEnabled
public static boolean isDepSyncEnabled()utility method to check whether deployment synchronizer enabled.- Returns:
-
getGhostMetafileDir
-
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
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.
-
isLegacyAuditLogsDisabled
Deprecated.UseisEnableV2AuditLogs()instead.Check whether the legacy audit logs are disabled.- Returns:
- Whether legacy audit logs are disabled.
-
isEnableV2AuditLogs
public static boolean isEnableV2AuditLogs()Check whether the V2 audit logs are enabled.- Returns:
- Whether V2 audit logs are enabled.
-
publishAuditLogs
Publish audit logs to the audit log file.- Parameters:
auditLogData- Audit log event data required for log.
-
isDiagnosticLogsEnabled
public static boolean isDiagnosticLogsEnabled()Checks whether diagnostic logs are enabled.- Returns:
- false if DiagnosticLogMode is NONE, true otherwise.
-
getDiagnosticLogMode
Get the diagnostic log mode for the tenant.- Parameters:
tenantId- Tenant ID.- Returns:
- Diagnostic log mode.
-
setDiagnosticLogMode
public static void setDiagnosticLogMode(int tenantId) Retrieves the 'DiagnosticLogMode' from the ServerConfiguration and process it before returning. -
readDiagnosticLogMode
Retrieves the 'DiagnosticLogMode' from the cached ServerConfiguration.- Returns:
- the DiagnosticLogMode.
-
publishDiagnosticLog
Publish diagnostic log to the diagnostic log file.- Parameters:
diagnosticLogData- Diagnostic log event data required for log.
-
isInputValidationEnabled
public static boolean isInputValidationEnabled()Function to extract InputValidationEnabled configuration from carbon.xml.<InputValidationEnabled>true</InputValidationEnabled>- Returns:
- isInputValidationEnabled.
-
isManagementConsoleBannerEnabled
public static boolean isManagementConsoleBannerEnabled()Function to extract ManagementConsoleDeprecationBannerEnabled configuration from carbon.xml.<ManagementConsoleDeprecationBannerEnabled>true</ManagementConsoleDeprecationBannerEnabled>- Returns:
- isManagementConsoleBannerEnabled.
-
isEnableV2AuditLogs()instead.