Fixed the karaf webconsole test.

This commit is contained in:
Claus Ibsen 2013-10-01 14:12:24 +02:00
parent b8d5ca8383
commit 92ee5c6bab
1 changed files with 30 additions and 12 deletions

View File

@ -22,6 +22,7 @@ import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
@ -46,28 +47,45 @@ public class ActiveMQBrokerNdWebConsoleFeatureTest extends ActiveMQBrokerFeature
@Override
protected void produceMessage(String nameAndPayload) throws Exception {
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
System.err.println(executeCommand("activemq:bstat").trim());
System.err.println("attempting to access web console..");
GetMethod get = new GetMethod(WEB_CONSOLE_URL + "index.jsp");
// Give console some time to start
boolean done = false;
int loop = 0;
while (!done && loop < 30) {
loop++;
try {
int code = client.executeMethod(get);
if (code > 399 && code < 500) {
// code 4xx we should retry
System.err.println("web console not accessible yet - status code " + code);
TimeUnit.SECONDS.sleep(1);
} else {
done = true;
}
} catch (Exception ignored) {}
}
assertEquals("get succeeded on " + get, 200, get.getStatusCode());
System.err.println("attempting publish via web console..");
// need to first get the secret
get = new GetMethod(WEB_CONSOLE_URL + "send.jsp");
get.setDoAuthentication(true);
// set credentials
client.getState().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(USER, PASSWORD)
);
// need to first get the secret
GetMethod get = new GetMethod(WEB_CONSOLE_URL + "send.jsp");
get.setDoAuthentication(true);
// Give console some time to start
for (int i=0; i<20; i++) {
TimeUnit.SECONDS.sleep(1);
try {
i = client.executeMethod(get);
} catch (java.net.ConnectException ignored) {}
}
assertEquals("get succeeded on " + get, 200, get.getStatusCode());
int code = client.executeMethod(get);
assertEquals("get succeeded on " + get, 200, code);
String response = get.getResponseBodyAsString();
final String secretMarker = "<input type=\"hidden\" name=\"secret\" value=\"";