in src/main/java/org/apache/sling/testing/clients/osgi/OsgiConsoleClient.java [440:478]
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)) {
// The location header can contain a relative or an absolute URL
// Gathering where the URL_CONFIGURATION substring starts will allow adapting to both cases
int urlPathStart = locationHeader[0].getValue().indexOf(URL_CONFIGURATION);
return locationHeader[0].getValue().substring(urlPathStart + URL_CONFIGURATION.length() + 1);
} else {
return null;
}
}