Class OsgiConsoleClient
java.lang.Object
org.apache.sling.testing.clients.AbstractSlingClient
org.apache.sling.testing.clients.SlingClient
org.apache.sling.testing.clients.osgi.OsgiConsoleClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.http.client.HttpClient
A client that wraps the Felix OSGi Web Console REST API calls.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sling.testing.clients.SlingClient
SlingClient.Builder, SlingClient.InternalBuilder<T extends SlingClient>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class org.apache.sling.testing.clients.SlingClient
CLIENT_CONNECTION_TIMEOUT_PROP, DEFAULT_NODE_TYPE, SUDO_COOKIE_NAME
-
Constructor Summary
ConstructorsConstructorDescriptionOsgiConsoleClient
(URI serverUrl, String userName, String password) Default constructor.OsgiConsoleClient
(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config) Constructor used by adaptTo() and InternalBuilder classes. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkBundleInstalled
(String symbolicName, int waitTime, int retries) Deprecated.deleteConfiguration
(String pid, int... expectedStatus) Delete the config referenced by the PIDeditConfiguration
(String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) Sets properties of a config referenced by its PID.editConfigurationWithWait
(int waitCount, String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) Deprecated.long
getBundleId
(String symbolicName) Get the id of the bundlegetBundleInfo
(String id, int... expectedStatus) Returns the wrapper for the bundle info jsongetBundlesInfo
(int... expectedStatus) Returns the wrapper for the bundles info jsongetBundleState
(String symbolicName) Get the state of the bundlestatic String
getBundleSymbolicName
(File bundleFile) Get the symbolic name from a bundle file by looking at the manifestgetBundleVersion
(String symbolicName) Get the version of the bundlestatic String
getBundleVersionFromFile
(File bundleFile) Get the version form a bundle file by looking at the manifestgetComponentInfo
(String id, int expectedStatus) Returns the wrapper for the component info jsongetComponentsInfo
(int... expectedStatus) Returns the wrapper for the components info jsongetConfigPIDFromServices
(String serviceType, String propertyName, String propertyValue, long timeout, long delay) Performs a search of a config PID through the service information.getConfiguration
(String pid, int... expectedStatus) Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names.getConfigurationWithWait
(long waitCount, String pid, int... expectedStatus) Deprecated.getOSGiConfiguration
(String pid, int... expectedStatus) Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names.installBundle
(File f, boolean startBundle) Install a bundle using the Felix webconsole HTTP interfaceinstallBundle
(File f, boolean startBundle, int startLevel) Install a bundle using the Felix webconsole HTTP interface, with a specific start levelboolean
installBundleWithRetry
(File f, boolean startBundle, int startLevel, int waitTime, int retries) void
Calls PackageAdmin.refreshPackages to force re-wiring of all the bundles.void
startBundle
(String symbolicName) Starts a bundlevoid
startBundlewithWait
(String symbolicName, int waitTime, int retries) Deprecated.void
stopBundle
(String symbolicName) Stop a bundleuninstallBundle
(String symbolicName) Uninstall a bundlevoid
waitBundleInstalled
(String symbolicName, long timeout, long delay) Wait until the bundle is installed.void
waitBundleStarted
(String symbolicName, long timeout, long delay) Wait until the bundle is startedvoid
waitComponentRegistered
(String componentName, long timeout, long delay) Wait until the component with the given name is registered.waitEditConfiguration
(long timeout, String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) Sets properties of a config referenced by its PID.waitGetConfiguration
(long timeout, String pid, int... expectedStatus) Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names.void
waitInstallBundle
(File f, boolean startBundle, int startLevel, long timeout, long delay) Install a bundle using the Felix webconsole HTTP interface and wait for it to be installed.void
waitServiceRegistered
(String type, String bundleSymbolicName, long timeout, long delay) Wait until the service with the given name is registered.void
waitStartBundle
(String symbolicName, long timeout, long delay) Starts a bundle and waits for it to be startedMethods inherited from class org.apache.sling.testing.clients.SlingClient
createFolder, createNode, createNodeRecursive, deletePath, doGetJson, endImpersonation, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUser, getUUId, getUUID, impersonate, importContent, importContent, importJson, move, setPropertiesString, setPropertyString, setPropertyStringArray, upload, waitExists, waitUntilExists
Methods inherited from class org.apache.sling.testing.clients.AbstractSlingClient
adaptTo, addValue, close, doDelete, doGet, doGet, doGet, doHead, doPatch, doPost, doPost, doPut, doRawRequest, doRequest, doStreamGet, doStreamPost, doStreamRequest, execute, execute, execute, execute, execute, execute, execute, execute, getClientId, getConnectionManager, getCookieStore, getCredentialsProvider, getParams, getPassword, getPath, getPath, getUrl, getUrl, getUrl, getValue, getValues, hasValue
-
Field Details
-
JSON_KEY_ID
- See Also:
-
JSON_KEY_VERSION
- See Also:
-
JSON_KEY_DATA
- See Also:
-
JSON_KEY_STATE
- See Also:
-
-
Constructor Details
-
OsgiConsoleClient
Default constructor. Simply callsSlingClient(URI, String, String)
- Parameters:
serverUrl
- the URL to the server under testuserName
- the username used for authenticationpassword
- the password for this user- Throws:
ClientException
- if the client cannot be instantiated
-
OsgiConsoleClient
public OsgiConsoleClient(org.apache.http.impl.client.CloseableHttpClient http, SlingClientConfig config) throws ClientException Constructor used by adaptTo() and InternalBuilder classes. Should not be called directly in the code- Parameters:
http
- http client to be used for requestsconfig
- sling specific configs- Throws:
ClientException
- if the client cannot be instantiated
-
-
Method Details
-
getBundlesInfo
Returns the wrapper for the bundles info json- Parameters:
expectedStatus
- list of accepted statuses of the response- Returns:
- all the bundles info
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
getBundleInfo
Returns the wrapper for the bundle info json- Parameters:
id
- the id of the bundleexpectedStatus
- list of accepted statuses of the response- Returns:
- the bundle info
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
getComponentsInfo
Returns the wrapper for the components info json- Parameters:
expectedStatus
- list of accepted statuses of the response- Returns:
- the components info
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
getComponentInfo
Returns the wrapper for the component info json- Parameters:
id
- the id of the componentexpectedStatus
- list of accepted statuses of the response- Returns:
- the component info
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
waitComponentRegistered
public void waitComponentRegistered(String componentName, long timeout, long delay) throws TimeoutException, InterruptedException Wait until the component with the given name is registered. This means the component must be either in state "Registered" or "Active". The state registered is called "satisfied" in the Felix DS Web Console- Parameters:
componentName
- the component's nametimeout
- how long to wait for the component to become registered before throwing aTimeoutException
in millisecondsdelay
- time to wait between checks of the state in milliseconds- Throws:
TimeoutException
- if the component did not become registered before timeout was reachedInterruptedException
- if interrupted- See Also:
-
waitServiceRegistered
public void waitServiceRegistered(String type, String bundleSymbolicName, long timeout, long delay) throws TimeoutException, InterruptedException Wait until the service with the given name is registered. This means the component must be either in state "Registered" or "Active".- Parameters:
type
- the type of the service (usually the name of a Java interface)bundleSymbolicName
- the symbolic name of the bundle supposed to register that service. May benull
in which case this method just waits for any service with the requested type being registered (independent of the registering bundle).timeout
- how long to wait for the component to become registered before throwing aTimeoutException
in millisecondsdelay
- time to wait between checks of the state in milliseconds- Throws:
TimeoutException
- if the component did not become registered before timeout was reachedInterruptedException
- if interrupted
-
getConfiguration
public Map<String,Object> getConfiguration(String pid, int... expectedStatus) throws ClientException Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names. If properties are not set in the corresponding OSGi configuration but metatype information is available, the defaults from the metatype will be included.- Parameters:
pid
- the pid of the configurationexpectedStatus
- list of accepted statuses of the response- Returns:
- the properties as a map
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
getOSGiConfiguration
public Map<String,Object> getOSGiConfiguration(String pid, int... expectedStatus) throws ClientException Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names.- Parameters:
pid
- the pid of the configurationexpectedStatus
- list of accepted statuses of the response- Returns:
- the properties as a map or
null
if the configuration does not exist - Throws:
ClientException
- if the response status does not match any of the expectedStatus- Since:
- 2.1.0
-
getConfigurationWithWait
@Deprecated public Map<String,Object> getConfigurationWithWait(long waitCount, String pid, int... expectedStatus) throws TestingValidationException, InterruptedException Deprecated.Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names. The method waits until the configuration has been set.- Parameters:
waitCount
- The number of maximum wait intervals of 500ms. Between each wait interval, the method polls the backend to see if the configuration ahs been set.pid
- pidexpectedStatus
- expected response status- Returns:
- the config properties
- Throws:
TestingValidationException
- if the response status does not match any of the expectedStatusInterruptedException
- to mark this operation as "waiting"
-
waitGetConfiguration
public Map<String,Object> waitGetConfiguration(long timeout, String pid, int... expectedStatus) throws ClientException, InterruptedException, TimeoutException Returns a map of all properties set for the config referenced by the PID, where the map keys are the property names. The method waits until the configuration has been set.- Parameters:
timeout
- Maximum time to wait for the configuration to be available, in ms.pid
- service pidexpectedStatus
- expected response status- Returns:
- the config properties
- Throws:
ClientException
- if the response status does not match any of the expectedStatusInterruptedException
- to mark this operation as "waiting"TimeoutException
- if the timeout was reached
-
editConfiguration
public String editConfiguration(String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) throws ClientExceptionSets properties of a config referenced by its PID. the properties to be edited are passed as a map of property name,value pairs.- Parameters:
PID
- Persistent identity stringfactoryPID
- Factory persistent identity string ornull
configProperties
- map of propertiesexpectedStatus
- expected response status- Returns:
- the location of the config
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
editConfigurationWithWait
@Deprecated public String editConfigurationWithWait(int waitCount, String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) throws ClientException, InterruptedExceptionDeprecated.Sets properties of a config referenced by its PID. the properties to be edited are passed as a map of property (name,value) pairs. The method waits until the configuration has been set.- Parameters:
waitCount
- The number of maximum wait intervals of 500ms. Between each wait interval, the method polls the backend to see if the configuration ahs been set.PID
- Persistent identity stringfactoryPID
- Factory persistent identity string ornull
configProperties
- map of propertiesexpectedStatus
- expected response status- Returns:
- the pid
- Throws:
ClientException
- if the response status does not match any of the expectedStatusInterruptedException
- to mark this operation as "waiting"
-
waitEditConfiguration
public String waitEditConfiguration(long timeout, String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) throws ClientException, InterruptedException, TimeoutExceptionSets properties of a config referenced by its PID. the properties to be edited are passed as a map of property (name,value) pairs. The method waits until the configuration has been set.- Parameters:
timeout
- Max time to wait for the configuration to be set, in msPID
- Persistent identity stringfactoryPID
- Factory persistent identity string ornull
configProperties
- map of propertiesexpectedStatus
- expected response status- Returns:
- the pid
- Throws:
ClientException
- if the response status does not match any of the expectedStatusInterruptedException
- to mark this operation as "waiting"TimeoutException
- if the timeout was reached
-
deleteConfiguration
public SlingHttpResponse deleteConfiguration(String pid, int... expectedStatus) throws ClientException Delete the config referenced by the PID- Parameters:
pid
- pidexpectedStatus
- expected response status- Returns:
- the sling response
- Throws:
ClientException
- if the response status does not match any of the expectedStatus
-
uninstallBundle
Uninstall a bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- the sling response
- Throws:
ClientException
- if something went wrong with the request
-
installBundle
Install a bundle using the Felix webconsole HTTP interface- Parameters:
f
- the bundle filestartBundle
- whether to start the bundle or not- Returns:
- the sling response
- Throws:
ClientException
- if the request failed
-
installBundle
public SlingHttpResponse installBundle(File f, boolean startBundle, int startLevel) throws ClientException Install a bundle using the Felix webconsole HTTP interface, with a specific start level- Parameters:
f
- bundle filestartBundle
- whether to start or just install the bundlestartLevel
- start level- Returns:
- the sling response
- Throws:
ClientException
- if the request failed
-
checkBundleInstalled
@Deprecated public boolean checkBundleInstalled(String symbolicName, int waitTime, int retries) throws InterruptedException Deprecated.does not respect polling practices; usewaitBundleInstalled(String, long, long)
insteadCheck that specified bundle is installed and retries every {{waitTime}} milliseconds, until the bundle is installed or the number of retries was reached- Parameters:
symbolicName
- the name of the bundlewaitTime
- How many milliseconds to wait between retriesretries
- the number of retries- Returns:
- true if the bundle was installed until the retries stop, false otherwise
- Throws:
InterruptedException
- if interrupted
-
installBundleWithRetry
@Deprecated public boolean installBundleWithRetry(File f, boolean startBundle, int startLevel, int waitTime, int retries) throws ClientException, InterruptedException Install a bundle using the Felix webconsole HTTP interface and wait for it to be installed- Parameters:
f
- the bundle filestartBundle
- whether to start the bundle or notstartLevel
- the start level of the bundle. negative values mean default start levelwaitTime
- how long to wait between retries of checking the bundleretries
- how many times to check for the bundle to be installed, until giving up- Returns:
- true if the bundle was successfully installed, false otherwise
- Throws:
ClientException
- if the request failedInterruptedException
- if interrupted
-
waitInstallBundle
public void waitInstallBundle(File f, boolean startBundle, int startLevel, long timeout, long delay) throws ClientException, InterruptedException, TimeoutException Install a bundle using the Felix webconsole HTTP interface and wait for it to be installed.- Parameters:
f
- the bundle filestartBundle
- whether to start the bundle or notstartLevel
- the start level of the bundle. negative values mean default start leveltimeout
- how long to wait for the bundle to be installed before throwing aTimeoutException
in millisecondsdelay
- time to wait between checks of the state in milliseconds- Throws:
ClientException
- if the request failedTimeoutException
- if the bundle did not install before timeout was reachedInterruptedException
- if interrupted
-
waitBundleInstalled
public void waitBundleInstalled(String symbolicName, long timeout, long delay) throws TimeoutException, InterruptedException Wait until the bundle is installed.- Parameters:
symbolicName
- symbolic name of bundletimeout
- how long to wait for the bundle to be installed before throwing aTimeoutException
in millisecondsdelay
- time to wait between checks of the state in milliseconds- Throws:
TimeoutException
- if the bundle did not install before timeout was reachedInterruptedException
- if interrupted- See Also:
-
waitBundleStarted
public void waitBundleStarted(String symbolicName, long timeout, long delay) throws TimeoutException, InterruptedException Wait until the bundle is started- Parameters:
symbolicName
- symbolic name of bundletimeout
- how long to wait for the bundle to be installed before throwing aTimeoutException
in milliseconds.delay
- time to wait between checks of the state in milliseconds.- Throws:
TimeoutException
- if the bundle did not install before timeout was reachedInterruptedException
- if interrupted- See Also:
-
getBundleId
Get the id of the bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- the id
- Throws:
ClientException
- if the id cannot be retrieved
-
getBundleVersion
Get the version of the bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- bundle version
- Throws:
ClientException
- if the version is not retrieved
-
getBundleState
Get the state of the bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- the state of the bundle
- Throws:
ClientException
- if the state cannot be retrieved
-
startBundle
Starts a bundle- Parameters:
symbolicName
- the name of the bundle- Throws:
ClientException
- if the request failed
-
stopBundle
Stop a bundle- Parameters:
symbolicName
- the name of the bundle- Throws:
ClientException
- if the request failed
-
startBundlewithWait
@Deprecated public void startBundlewithWait(String symbolicName, int waitTime, int retries) throws ClientException, InterruptedException Deprecated.Starts a bundle and waits for it to be started- Parameters:
symbolicName
- the name of the bundlewaitTime
- How many milliseconds to wait between retriesretries
- the number of retries- Throws:
ClientException
- if the request failedInterruptedException
- if interrupted
-
waitStartBundle
public void waitStartBundle(String symbolicName, long timeout, long delay) throws ClientException, InterruptedException, TimeoutException Starts a bundle and waits for it to be started- Parameters:
symbolicName
- the name of the bundletimeout
- max time to wait for the bundle to start, in msdelay
- time to wait between status checks, in ms- Throws:
ClientException
- if the request failedInterruptedException
- if interruptedTimeoutException
- if starting timed out
-
refreshPackages
Calls PackageAdmin.refreshPackages to force re-wiring of all the bundles.- Throws:
ClientException
- if the request failed
-
getConfigPIDFromServices
public String getConfigPIDFromServices(String serviceType, String propertyName, String propertyValue, long timeout, long delay) throws ClientException, InterruptedException, TimeoutException Performs a search of a config PID through the service information.This is useful for the case where:
- We don't have the exact config PID (common if it is a factory config we didn't create).
- We have to search the config with a property having a defined value
- Parameters:
serviceType
- The type of service.propertyName
- The name of the property with the unique value to search.propertyValue
- The unique value to be searched.- Returns:
- The final config PID. Null if it is not found.*
- Throws:
ClientException
InterruptedException
TimeoutException
-
getBundleSymbolicName
Get the symbolic name from a bundle file by looking at the manifest- Parameters:
bundleFile
- bundle file- Returns:
- the name extracted from the manifest
- Throws:
IOException
- if reading the jar failed
-
getBundleVersionFromFile
Get the version form a bundle file by looking at the manifest- Parameters:
bundleFile
- bundle file- Returns:
- the version
- Throws:
IOException
- if reading the bundle jar failed
-
waitBundleInstalled(String, long, long)
instead