Modified: ace/trunk/org.apache.ace.test/src/org/apache/ace/it/IntegrationTestBase.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.test/src/org/apache/ace/it/IntegrationTestBase.java?rev=1530984&r1=1530983&r2=1530984&view=diff ============================================================================== --- ace/trunk/org.apache.ace.test/src/org/apache/ace/it/IntegrationTestBase.java (original) +++ ace/trunk/org.apache.ace.test/src/org/apache/ace/it/IntegrationTestBase.java Thu Oct 10 14:11:13 2013 @@ -21,9 +21,11 @@ package org.apache.ace.it; import static java.util.concurrent.TimeUnit.SECONDS; import static org.apache.ace.test.utils.Util.properties; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; +import java.net.ConnectException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -36,6 +38,7 @@ import java.util.concurrent.TimeUnit; import junit.framework.TestCase; +import org.apache.ace.test.constants.TestConstants; import org.apache.felix.dm.Component; import org.apache.felix.dm.ComponentDependencyDeclaration; import org.apache.felix.dm.ComponentStateListener; @@ -128,6 +131,11 @@ public class IntegrationTestBase extends * configure("org.apache.felix.http", * "org.osgi.service.http.port", "1234"); * </pre> + * + * @param pid + * the configuration PID to configure; + * @param configuration + * the configuration key/values (as pairs). */ protected void configure(String pid, String... configuration) throws IOException { Properties props = properties(configuration); @@ -137,6 +145,60 @@ public class IntegrationTestBase extends } /** + * Configures the "org.apache.felix.http" and waits until the service is actually ready to process requests. + * <p> + * The reason that this method exists is that configuring the Felix HTTP bundle causes it to actually stop and + * restart, which is done asynchronously. This means that we cannot be sure that depending code is always able to + * directly use the HTTP service after its been configured. + * </p> + * + * @param port + * the new port to run the HTTP service on; + * @param configuration + * the extra (optional) configuration key/values (as pairs). + * @see #configure(String, String...) + */ + protected void configureHttpService(int port, String... configuration) throws IOException, InterruptedException { + final String httpPID = "org.apache.felix.http"; + final String portProperty = "org.osgi.service.http.port"; + final String expectedPort = Integer.toString(port); + + // Do not track this configuration (yet)... + Properties props = properties(configuration); + props.put(portProperty, expectedPort); + + Configuration config = getConfiguration(httpPID); + config.update(props); + + // This ugly warth is necessary as Felix HTTP currently brings the entire service down & up if it gets + // reconfigured. There is no other way for us to tell whether the server is ready to accept calls... + URL url = new URL(String.format("http://localhost:%d/", port)); + int tries = 50; + boolean ready = false; + do { + Thread.sleep(50); + + try { + InputStream is = url.openStream(); + is.close(); + ready = true; + } + catch (ConnectException exception) { + // Not there yet... + } + catch (FileNotFoundException exception) { + // Ok; expected... + ready = true; + } + } + while (!ready && tries-- > 0); + + if (tries == 0) { + throw new IOException("Failed waiting on HTTP service?!"); + } + } + + /** * The 'after' callback will be called after all components from {@link #getDependencies} have been started.<br> * <br> * The {@link #after} callback is most useful for configuring additional services after all mandatory services are @@ -476,6 +538,11 @@ public class IntegrationTestBase extends m_dependencyManager.add(component); } + System.setProperty("org.apache.ace.server.port", Integer.toString(TestConstants.PORT)); + + // Ensure the HTTP service is running on the port we expect... + configureHttpService(TestConstants.PORT); + // Call back the implementation... configureProvisionedServices(); @@ -486,10 +553,6 @@ public class IntegrationTestBase extends } configureAdditionalServices(); - - // Wait for CM to settle or we may get "socket closed" due to HTTP service restarts - // JaWi: no longer needed with Felix HTTP v2.2.1? - // Thread.sleep(500); } catch (InterruptedException e) { fail("Interrupted while waiting for services to get started.");
Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java?rev=1530984&r1=1530983&r2=1530984&view=diff ============================================================================== --- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java (original) +++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/VaadinClient.java Thu Oct 10 14:11:13 2013 @@ -114,11 +114,11 @@ public class VaadinClient extends com.va private static long SESSION_ID = 1; - private static String targetRepo = "target"; - private static String shopRepo = "shop"; - private static String deployRepo = "deployment"; - private static String customerName = "apache"; - private static String endpoint = "/repository"; + private static final String targetRepo = "target"; + private static final String shopRepo = "shop"; + private static final String deployRepo = "deployment"; + private static final String customerName = "apache"; + private static final String endpoint = "/repository"; private volatile AuthenticationService m_authenticationService; private volatile BundleContext m_context; @@ -1029,7 +1029,7 @@ public class VaadinClient extends com.va RepositoryAdminLoginContext context = m_admin.createLoginContext(user); // @formatter:off - context.setObrBase(m_obrUrl) + context .add(context.createShopRepositoryContext() .setLocation(m_repository).setCustomer(customerName).setName(shopRepo).setWriteable()) .add(context.createTargetRepositoryContext()
