Search in sources :

Example 1 with FormEntityBuilder

use of org.apache.sling.testing.clients.util.FormEntityBuilder in project sling by apache.

the class OsgiConsoleClient method refreshPackages.

/**
     * Calls PackageAdmin.refreshPackages to force re-wiring of all the bundles.
     * @throws ClientException
     */
public void refreshPackages() throws ClientException {
    LOG.info("Refreshing packages.");
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("action", "refreshPackages");
    this.doPost(URL_BUNDLES, builder.build(), 200);
}
Also used : FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Example 2 with FormEntityBuilder

use of org.apache.sling.testing.clients.util.FormEntityBuilder in project sling by apache.

the class OsgiConsoleClient method uninstallBundle.

//
// Bundles
//
/**
     * Uninstall a bundle
     * @param symbolicName bundle symbolic name
     * @return the sling response
     * @throws ClientException
     */
public SlingHttpResponse uninstallBundle(String symbolicName) throws ClientException {
    final long bundleId = getBundleId(symbolicName);
    LOG.info("Uninstalling bundle {} with bundleId {}", symbolicName, bundleId);
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("action", "uninstall");
    return this.doPost(getBundlePath(symbolicName), builder.build(), 200);
}
Also used : FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Example 3 with FormEntityBuilder

use of org.apache.sling.testing.clients.util.FormEntityBuilder in project sling by apache.

the class OsgiConsoleClient method deleteConfiguration.

/**
     * Delete the config referenced by the PID
     *
     * @param pid pid
     * @param expectedStatus expected response status
     * @return the sling response
     * @throws ClientException if the response status does not match any of the expectedStatus
     */
public SlingHttpResponse deleteConfiguration(String pid, int... expectedStatus) throws ClientException {
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("apply", "1");
    builder.addParameter("delete", "1");
    // make the request
    SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + pid, builder.build());
    // check the returned status
    HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(200, expectedStatus));
    return resp;
}
Also used : SlingHttpResponse(org.apache.sling.testing.clients.SlingHttpResponse) FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Example 4 with FormEntityBuilder

use of org.apache.sling.testing.clients.util.FormEntityBuilder in project sling by apache.

the class OsgiConsoleClient method editConfiguration.

/**
     * Sets properties of a config referenced by its PID. the properties to be edited are passed as
     * a map of property name,value pairs.
     *
     * @param PID Persistent identity string
     * @param factoryPID Factory persistent identity string or {@code null}
     * @param configProperties map of properties
     * @param expectedStatus expected response status
     * @return the location of the config
     * @throws ClientException if the response status does not match any of the expectedStatus
     */
public String editConfiguration(String PID, String factoryPID, Map<String, Object> configProperties, int... expectedStatus) throws ClientException {
    FormEntityBuilder builder = FormEntityBuilder.create();
    builder.addParameter("apply", "true");
    builder.addParameter("action", "ajaxConfigManager");
    // send factory PID if set
    if (factoryPID != null) {
        builder.addParameter("factoryPid", factoryPID);
    }
    // add properties to edit
    StringBuilder propertyList = new StringBuilder("");
    for (String propName : configProperties.keySet()) {
        Object o = configProperties.get(propName);
        if (o instanceof String) {
            builder.addParameter(propName, (String) o);
        } else if (o instanceof String[]) {
            for (String s : (String[]) o) {
                builder.addParameter(propName, s);
            }
        }
        propertyList.append(propName).append(",");
    }
    // cut off the last comma
    builder.addParameter("propertylist", propertyList.substring(0, propertyList.length() - 1));
    // make the request
    SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + PID, builder.build());
    // check the returned status
    HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_MOVED_TEMPORARILY, expectedStatus));
    Header[] locationHeader = resp.getHeaders("Location");
    if (locationHeader != null && locationHeader.length == 1) {
        return locationHeader[0].getValue().substring(URL_CONFIGURATION.length() + 1);
    } else {
        return null;
    }
}
Also used : SlingHttpResponse(org.apache.sling.testing.clients.SlingHttpResponse) Header(org.apache.http.Header) FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Example 5 with FormEntityBuilder

use of org.apache.sling.testing.clients.util.FormEntityBuilder in project sling by apache.

the class SlingSpecificsSightlyIT method restartSightlyEngineBundle.

private void restartSightlyEngineBundle() throws InterruptedException, IOException {
    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(launchpadURL + "/system/console/bundles/org.apache.sling.scripting.sightly");
    // Stop bundle
    FormEntityBuilder formBuilder = FormEntityBuilder.create();
    post.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
    formBuilder.addParameter("action", "stop");
    post.setEntity(formBuilder.build());
    httpClient.execute(post);
    Thread.sleep(1000);
    // Start bundle
    formBuilder = FormEntityBuilder.create();
    post.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
    formBuilder.addParameter("action", "start");
    post.setEntity(formBuilder.build());
    httpClient.execute(post);
    Thread.sleep(1000);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FormEntityBuilder(org.apache.sling.testing.clients.util.FormEntityBuilder)

Aggregations

FormEntityBuilder (org.apache.sling.testing.clients.util.FormEntityBuilder)5 SlingHttpResponse (org.apache.sling.testing.clients.SlingHttpResponse)2 Header (org.apache.http.Header)1 HttpClient (org.apache.http.client.HttpClient)1 HttpPost (org.apache.http.client.methods.HttpPost)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1