use of org.apache.sling.testing.clients.ClientException in project sling by apache.
the class OsgiConsoleClient method getBundleState.
/**
* Get the state of the bundle
* @param symbolicName bundle symbolic name
* @return the state of the bundle
* @throws ClientException if the state cannot be retrieved
*/
public String getBundleState(String symbolicName) throws ClientException {
final JsonNode bundle = getBundleData(symbolicName);
final JsonNode stateNode = bundle.get(JSON_KEY_STATE);
if (stateNode == null) {
throw new ClientException("Cannot get state from bundle json");
}
return stateNode.getTextValue();
}
use of org.apache.sling.testing.clients.ClientException in project sling by apache.
the class OsgiInstanceConfig method save.
/**
* Save the current OSGi configuration for the PID defined in the constructor
*
* @throws InstanceConfigException if the config cannot be saved
*/
public InstanceConfig save() throws InstanceConfigException, InterruptedException {
try {
this.config = osgiClient.waitGetConfiguration(WAIT_TIMEOUT, this.configPID);
LOG.info("Saved OSGi config for {}. It is currently this: {}", this.configPID, this.config);
} catch (ClientException e) {
throw new InstanceConfigException("Error getting config", e);
} catch (TimeoutException e) {
throw new InstanceConfigException("Timeout of " + WAIT_TIMEOUT + " ms was reached while waiting for the configuration", e);
}
return this;
}
use of org.apache.sling.testing.clients.ClientException in project sling by apache.
the class HttpUtils method getLocationHeader.
/**
* Get the first 'Location' header and verify it's a valid URI.
*
* @param response HttpResponse the http response
* @return the location path
* @throws ClientException never (kept for uniformity)
*/
public static String getLocationHeader(HttpResponse response) throws ClientException {
if (response == null)
throw new ClientException("Response must not be null!");
String locationPath = null;
Header locationHeader = response.getFirstHeader("Location");
if (locationHeader != null) {
String location = locationHeader.getValue();
URI locationURI = URI.create(location);
locationPath = locationURI.getPath();
}
if (locationPath == null) {
throw new ClientException("not able to determine location path");
}
return locationPath;
}
use of org.apache.sling.testing.clients.ClientException in project sling by apache.
the class BundlesInstaller method isInstalled.
/**
* Checks if a bundle is installed or not. Does not retry.
* @param bundleFile bundle file
* @return true if the bundle is installed
* @throws ClientException if the state of the bundle could not be determined
*/
public boolean isInstalled(File bundleFile) throws ClientException {
String bundleSymbolicName = "";
try {
bundleSymbolicName = OsgiConsoleClient.getBundleSymbolicName(bundleFile);
log.debug("Checking if installed: " + bundleSymbolicName);
osgiConsoleClient.getBundleState(bundleSymbolicName);
log.debug("Already installed: " + bundleSymbolicName);
return true;
} catch (ClientException e) {
log.debug("Not yet installed: " + bundleSymbolicName);
return false;
} catch (IOException e) {
log.debug("Failed to retrieve bundle symbolic name from file. ", e);
throw new ClientException("Failed to retrieve bundle symbolic name from file. ", e);
}
}
Aggregations