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:
java.io.Closeable,java.lang.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 java.lang.StringJSON_KEY_DATAstatic java.lang.StringJSON_KEY_IDstatic java.lang.StringJSON_KEY_STATEstatic java.lang.StringJSON_KEY_VERSION-
Fields inherited from class org.apache.sling.testing.clients.SlingClient
CLIENT_CONNECTION_TIMEOUT_PROP, DEFAULT_NODE_TYPE
-
-
Constructor Summary
Constructors Constructor Description OsgiConsoleClient(java.net.URI serverUrl, java.lang.String userName, java.lang.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 booleancheckBundleInstalled(java.lang.String symbolicName, int waitTime, int retries)Deprecated.does not respect polling practices; usewaitBundleInstalled(String, long, long)insteadSlingHttpResponsedeleteConfiguration(java.lang.String pid, int... expectedStatus)Delete the config referenced by the PIDjava.lang.StringeditConfiguration(java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.Object> configProperties, int... expectedStatus)Sets properties of a config referenced by its PID.java.lang.StringeditConfigurationWithWait(int waitCount, java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.Object> configProperties, int... expectedStatus)Deprecated.longgetBundleId(java.lang.String symbolicName)Get the id of the bundleBundleInfogetBundleInfo(java.lang.String id, int... expectedStatus)Returns the wrapper for the bundle info jsonBundlesInfogetBundlesInfo(int... expectedStatus)Returns the wrapper for the bundles info jsonjava.lang.StringgetBundleState(java.lang.String symbolicName)Get the state of the bundlestatic java.lang.StringgetBundleSymbolicName(java.io.File bundleFile)Get the symbolic name from a bundle file by looking at the manifestjava.lang.StringgetBundleVersion(java.lang.String symbolicName)Get the version of the bundlestatic java.lang.StringgetBundleVersionFromFile(java.io.File bundleFile)Get the version form a bundle file by looking at the manifestComponentInfogetComponentInfo(java.lang.String id, int expectedStatus)Returns the wrapper for the component info jsonComponentsInfogetComponentsInfo(int... expectedStatus)Returns the wrapper for the components info jsonjava.util.Map<java.lang.String,java.lang.Object>getConfiguration(java.lang.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.java.util.Map<java.lang.String,java.lang.Object>getConfigurationWithWait(long waitCount, java.lang.String pid, int... expectedStatus)Deprecated.SlingHttpResponseinstallBundle(java.io.File f, boolean startBundle)Install a bundle using the Felix webconsole HTTP interfaceSlingHttpResponseinstallBundle(java.io.File f, boolean startBundle, int startLevel)Install a bundle using the Felix webconsole HTTP interface, with a specific start levelbooleaninstallBundleWithRetry(java.io.File f, boolean startBundle, int startLevel, int waitTime, int retries)voidrefreshPackages()Calls PackageAdmin.refreshPackages to force re-wiring of all the bundles.voidstartBundle(java.lang.String symbolicName)Starts a bundlevoidstartBundlewithWait(java.lang.String symbolicName, int waitTime, int retries)Deprecated.voidstopBundle(java.lang.String symbolicName)Stop a bundleSlingHttpResponseuninstallBundle(java.lang.String symbolicName)Uninstall a bundlevoidwaitBundleInstalled(java.lang.String symbolicName, long timeout, long delay)Wait until the bundle is installed.voidwaitBundleStarted(java.lang.String symbolicName, long timeout, long delay)Wait until the bundle is startedvoidwaitComponentRegistered(java.lang.String componentName, long timeout, long delay)Wait until the component with the given name is registered.java.lang.StringwaitEditConfiguration(long timeout, java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.Object> configProperties, int... expectedStatus)Sets properties of a config referenced by its PID.java.util.Map<java.lang.String,java.lang.Object>waitGetConfiguration(long timeout, java.lang.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.voidwaitInstallBundle(java.io.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.voidwaitServiceRegistered(java.lang.String type, java.lang.String bundleSymbolicName, long timeout, long delay)Wait until the service with the given name is registered.voidwaitStartBundle(java.lang.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, exists, getJsonNode, getJsonNode, getNodeNameFromPath, getParentPath, getUUId, getUUID, 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, getUser, getValue, getValues, hasValue
-
-
-
-
Field Detail
-
JSON_KEY_ID
public static final java.lang.String JSON_KEY_ID
- See Also:
- Constant Field Values
-
JSON_KEY_VERSION
public static final java.lang.String JSON_KEY_VERSION
- See Also:
- Constant Field Values
-
JSON_KEY_DATA
public static final java.lang.String JSON_KEY_DATA
- See Also:
- Constant Field Values
-
JSON_KEY_STATE
public static final java.lang.String JSON_KEY_STATE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OsgiConsoleClient
public OsgiConsoleClient(java.net.URI serverUrl, java.lang.String userName, java.lang.String password) throws ClientExceptionDefault 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 ClientExceptionConstructor 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(java.lang.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(java.lang.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(java.lang.String componentName, long timeout, long delay) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWait 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 aTimeoutExceptionin millisecondsdelay- time to wait between checks of the state in milliseconds- Throws:
java.util.concurrent.TimeoutException- if the component did not become registered before timeout was reachedjava.lang.InterruptedException- if interrupted- See Also:
- "OSGi Comp. R6, §112.5 Component Life Cycle"
-
waitServiceRegistered
public void waitServiceRegistered(java.lang.String type, java.lang.String bundleSymbolicName, long timeout, long delay) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWait 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 benullin 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 aTimeoutExceptionin millisecondsdelay- time to wait between checks of the state in milliseconds- Throws:
java.util.concurrent.TimeoutException- if the component did not become registered before timeout was reachedjava.lang.InterruptedException- if interrupted
-
getConfiguration
public java.util.Map<java.lang.String,java.lang.Object> getConfiguration(java.lang.String pid, int... expectedStatus) throws ClientExceptionReturns 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
- Throws:
ClientException- if the response status does not match any of the expectedStatus
-
getConfigurationWithWait
@Deprecated public java.util.Map<java.lang.String,java.lang.Object> getConfigurationWithWait(long waitCount, java.lang.String pid, int... expectedStatus) throws ClientException, java.lang.InterruptedExceptionDeprecated.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:
ClientException- if the response status does not match any of the expectedStatusjava.lang.InterruptedException- to mark this operation as "waiting"
-
waitGetConfiguration
public java.util.Map<java.lang.String,java.lang.Object> waitGetConfiguration(long timeout, java.lang.String pid, int... expectedStatus) throws ClientException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionReturns 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 expectedStatusjava.lang.InterruptedException- to mark this operation as "waiting"java.util.concurrent.TimeoutException- if the timeout was reached
-
editConfiguration
public java.lang.String editConfiguration(java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.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 ornullconfigProperties- 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 java.lang.String editConfigurationWithWait(int waitCount, java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.Object> configProperties, int... expectedStatus) throws ClientException, java.lang.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 ornullconfigProperties- map of propertiesexpectedStatus- expected response status- Returns:
- the pid
- Throws:
ClientException- if the response status does not match any of the expectedStatusjava.lang.InterruptedException- to mark this operation as "waiting"
-
waitEditConfiguration
public java.lang.String waitEditConfiguration(long timeout, java.lang.String PID, java.lang.String factoryPID, java.util.Map<java.lang.String,java.lang.Object> configProperties, int... expectedStatus) throws ClientException, java.lang.InterruptedException, java.util.concurrent.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 ornullconfigProperties- map of propertiesexpectedStatus- expected response status- Returns:
- the pid
- Throws:
ClientException- if the response status does not match any of the expectedStatusjava.lang.InterruptedException- to mark this operation as "waiting"java.util.concurrent.TimeoutException- if the timeout was reached
-
deleteConfiguration
public SlingHttpResponse deleteConfiguration(java.lang.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(java.lang.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(java.io.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(java.io.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(java.lang.String symbolicName, int waitTime, int retries) throws java.lang.InterruptedExceptionDeprecated.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:
java.lang.InterruptedException- if interrupted
-
installBundleWithRetry
@Deprecated public boolean installBundleWithRetry(java.io.File f, boolean startBundle, int startLevel, int waitTime, int retries) throws ClientException, java.lang.InterruptedExceptionInstall 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 failedjava.lang.InterruptedException- if interrupted
-
waitInstallBundle
public void waitInstallBundle(java.io.File f, boolean startBundle, int startLevel, long timeout, long delay) throws ClientException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionInstall 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 aTimeoutExceptionin millisecondsdelay- time to wait between checks of the state in milliseconds- Throws:
ClientException- if the request failedjava.util.concurrent.TimeoutException- if the bundle did not install before timeout was reachedjava.lang.InterruptedException- if interrupted
-
waitBundleInstalled
public void waitBundleInstalled(java.lang.String symbolicName, long timeout, long delay) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWait until the bundle is installed.- Parameters:
symbolicName- symbolic name of bundletimeout- how long to wait for the bundle to be installed before throwing aTimeoutExceptionin millisecondsdelay- time to wait between checks of the state in milliseconds- Throws:
java.util.concurrent.TimeoutException- if the bundle did not install before timeout was reachedjava.lang.InterruptedException- if interrupted- See Also:
- "OSGi Core R6, §4.4.2 Bundle State"
-
waitBundleStarted
public void waitBundleStarted(java.lang.String symbolicName, long timeout, long delay) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWait until the bundle is started- Parameters:
symbolicName- symbolic name of bundletimeout- how long to wait for the bundle to be installed before throwing aTimeoutExceptionin milliseconds.delay- time to wait between checks of the state in milliseconds.- Throws:
java.util.concurrent.TimeoutException- if the bundle did not install before timeout was reachedjava.lang.InterruptedException- if interrupted- See Also:
- "OSGi Core R6, §4.4.2 Bundle State"
-
getBundleId
public long getBundleId(java.lang.String symbolicName) throws ClientExceptionGet the id of the bundle- Parameters:
symbolicName- bundle symbolic name- Returns:
- the id
- Throws:
ClientException- if the id cannot be retrieved
-
getBundleVersion
public java.lang.String getBundleVersion(java.lang.String symbolicName) throws ClientExceptionGet the version of the bundle- Parameters:
symbolicName- bundle symbolic name- Returns:
- bundle version
- Throws:
ClientException- if the version is not retrieved
-
getBundleState
public java.lang.String getBundleState(java.lang.String symbolicName) throws ClientExceptionGet 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(java.lang.String symbolicName) throws ClientExceptionStarts a bundle- Parameters:
symbolicName- the name of the bundle- Throws:
ClientException- if the request failed
-
stopBundle
public void stopBundle(java.lang.String symbolicName) throws ClientExceptionStop a bundle- Parameters:
symbolicName- the name of the bundle- Throws:
ClientException- if the request failed
-
startBundlewithWait
@Deprecated public void startBundlewithWait(java.lang.String symbolicName, int waitTime, int retries) throws ClientException, java.lang.InterruptedExceptionDeprecated.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 failedjava.lang.InterruptedException- if interrupted
-
waitStartBundle
public void waitStartBundle(java.lang.String symbolicName, long timeout, long delay) throws ClientException, java.lang.InterruptedException, java.util.concurrent.TimeoutExceptionStarts 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 failedjava.lang.InterruptedException- if interruptedjava.util.concurrent.TimeoutException- if starting timed out
-
refreshPackages
public void refreshPackages() throws ClientExceptionCalls PackageAdmin.refreshPackages to force re-wiring of all the bundles.- Throws:
ClientException- if the request failed
-
getBundleSymbolicName
public static java.lang.String getBundleSymbolicName(java.io.File bundleFile) throws java.io.IOExceptionGet the symbolic name from a bundle file by looking at the manifest- Parameters:
bundleFile- bundle file- Returns:
- the name extracted from the manifest
- Throws:
java.io.IOException- if reading the jar failed
-
getBundleVersionFromFile
public static java.lang.String getBundleVersionFromFile(java.io.File bundleFile) throws java.io.IOExceptionGet the version form a bundle file by looking at the manifest- Parameters:
bundleFile- bundle file- Returns:
- the version
- Throws:
java.io.IOException- if reading the bundle jar failed
-
-