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
public class OsgiConsoleClient extends SlingClient
A client that wraps the Felix OSGi Web Console REST API calls.- See Also:
- Web Console RESTful API
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.sling.testing.clients.SlingClient
SlingClient.Builder, SlingClient.InternalBuilder<T extends SlingClient>
-
-
Field Summary
Fields Modifier and Type Field Description static String
JSON_KEY_DATA
static String
JSON_KEY_ID
static String
JSON_KEY_STATE
static String
JSON_KEY_VERSION
-
Fields inherited from class org.apache.sling.testing.clients.SlingClient
CLIENT_CONNECTION_TIMEOUT_PROP, DEFAULT_NODE_TYPE, SUDO_COOKIE_NAME
-
-
Constructor Summary
Constructors Constructor Description OsgiConsoleClient(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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
checkBundleInstalled(String symbolicName, int waitTime, int retries)
Deprecated.does not respect polling practices; usewaitBundleInstalled(String, long, long)
insteadSlingHttpResponse
deleteConfiguration(String pid, int... expectedStatus)
Delete the config referenced by the PIDString
editConfiguration(String PID, String factoryPID, Map<String,Object> configProperties, int... expectedStatus)
Sets properties of a config referenced by its PID.String
editConfigurationWithWait(int waitCount, String PID, String factoryPID, Map<String,Object> configProperties, int... expectedStatus)
Deprecated.long
getBundleId(String symbolicName)
Get the id of the bundleBundleInfo
getBundleInfo(String id, int... expectedStatus)
Returns the wrapper for the bundle info jsonBundlesInfo
getBundlesInfo(int... expectedStatus)
Returns the wrapper for the bundles info jsonString
getBundleState(String symbolicName)
Get the state of the bundlestatic String
getBundleSymbolicName(File bundleFile)
Get the symbolic name from a bundle file by looking at the manifestString
getBundleVersion(String symbolicName)
Get the version of the bundlestatic String
getBundleVersionFromFile(File bundleFile)
Get the version form a bundle file by looking at the manifestComponentInfo
getComponentInfo(String id, int expectedStatus)
Returns the wrapper for the component info jsonComponentsInfo
getComponentsInfo(int... expectedStatus)
Returns the wrapper for the components info jsonMap<String,Object>
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.Map<String,Object>
getConfigurationWithWait(long waitCount, String pid, int... expectedStatus)
Deprecated.Map<String,Object>
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.SlingHttpResponse
installBundle(File f, boolean startBundle)
Install a bundle using the Felix webconsole HTTP interfaceSlingHttpResponse
installBundle(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
refreshPackages()
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 bundleSlingHttpResponse
uninstallBundle(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.String
waitEditConfiguration(long timeout, String PID, String factoryPID, Map<String,Object> configProperties, int... expectedStatus)
Sets properties of a config referenced by its PID.Map<String,Object>
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 started-
Methods 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 Detail
-
JSON_KEY_ID
public static final String JSON_KEY_ID
- See Also:
- Constant Field Values
-
JSON_KEY_VERSION
public static final String JSON_KEY_VERSION
- See Also:
- Constant Field Values
-
JSON_KEY_DATA
public static final String JSON_KEY_DATA
- See Also:
- Constant Field Values
-
JSON_KEY_STATE
public static final String JSON_KEY_STATE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OsgiConsoleClient
public OsgiConsoleClient(URI serverUrl, String userName, String password) throws ClientException
Default constructor. Simply callsSlingClient(URI, String, String)
- Parameters:
serverUrl
- the URL to the server under testuserName
- the user name 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 Detail
-
getBundlesInfo
public BundlesInfo getBundlesInfo(int... expectedStatus) throws ClientException
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
public BundleInfo getBundleInfo(String id, int... expectedStatus) throws ClientException
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
public ComponentsInfo getComponentsInfo(int... expectedStatus) throws ClientException
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
public ComponentInfo getComponentInfo(String id, int expectedStatus) throws ClientException
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:
- "OSGi Comp. R6, §112.5 Component Life Cycle"
-
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 ClientException
Sets 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, InterruptedException
Deprecated.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, TimeoutException
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:
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
public SlingHttpResponse uninstallBundle(String symbolicName) throws ClientException
Uninstall a bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- the sling response
- Throws:
ClientException
- if something went wrong with the request
-
installBundle
public SlingHttpResponse installBundle(File f, boolean startBundle) throws ClientException
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:
- "OSGi Core R6, §4.4.2 Bundle State"
-
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:
- "OSGi Core R6, §4.4.2 Bundle State"
-
getBundleId
public long getBundleId(String symbolicName) throws ClientException
Get the id of the bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- the id
- Throws:
ClientException
- if the id cannot be retrieved
-
getBundleVersion
public String getBundleVersion(String symbolicName) throws ClientException
Get the version of the bundle- Parameters:
symbolicName
- bundle symbolic name- Returns:
- bundle version
- Throws:
ClientException
- if the version is not retrieved
-
getBundleState
public String getBundleState(String symbolicName) throws ClientException
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
public void startBundle(String symbolicName) throws ClientException
Starts a bundle- Parameters:
symbolicName
- the name of the bundle- Throws:
ClientException
- if the request failed
-
stopBundle
public void stopBundle(String symbolicName) throws ClientException
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
public void refreshPackages() throws ClientException
Calls PackageAdmin.refreshPackages to force re-wiring of all the bundles.- Throws:
ClientException
- if the request failed
-
getBundleSymbolicName
public static String getBundleSymbolicName(File bundleFile) throws IOException
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
public static String getBundleVersionFromFile(File bundleFile) throws IOException
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
-
-