Search in sources :

Example 6 with ClientException

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();
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) ClientException(org.apache.sling.testing.clients.ClientException)

Example 7 with ClientException

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;
}
Also used : InstanceConfigException(org.apache.sling.testing.clients.util.config.InstanceConfigException) ClientException(org.apache.sling.testing.clients.ClientException) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with ClientException

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;
}
Also used : Header(org.apache.http.Header) ClientException(org.apache.sling.testing.clients.ClientException) URI(java.net.URI)

Example 9 with ClientException

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);
    }
}
Also used : ClientException(org.apache.sling.testing.clients.ClientException) IOException(java.io.IOException)

Aggregations

ClientException (org.apache.sling.testing.clients.ClientException)9 JsonNode (org.codehaus.jackson.JsonNode)4 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 InstanceConfigException (org.apache.sling.testing.clients.util.config.InstanceConfigException)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Header (org.apache.http.Header)1