Refine search
private static ProtocolMetaData newHttpProtocolMetaData(final ServerService ss, final String contextRoot) { final HTTPContext httpContext = new HTTPContext(ss.getIP(), ss.getPort()); httpContext.add(new Servlet("ArquillianServletRunner", contextRoot)); return new ProtocolMetaData().addContext(httpContext); } }
private URL locateCommandEventBusURI(HTTPContext context) { List<Servlet> contextServlets = context.getServlets(); if (contextServlets == null) { throw new IllegalArgumentException("Could not determine URI for WarpFilter in context " + context + ". There are no Servlets in context."); } Set<String> contextRoots = new HashSet<String>(); for (Servlet servlet : contextServlets) { contextRoots.add(servlet.getContextRoot()); } if (contextRoots.size() == 1) { try { URI baseURI = context.getServlets().get(0).getBaseURI(); return new URL("http", baseURI.getHost(), baseURI.getPort(), baseURI.getPath()); } catch (MalformedURLException e) { throw new RuntimeException("Could not convert Servlet to URI, " + context.getServlets().get(0), e); } } else { try { return new URL("http", context.getHost(), context.getPort(), "/"); } catch (MalformedURLException e) { throw new RuntimeException("Could not convert HTTPContext to URI, " + context, e); } } } }
private HTTPContext locateNamedHttpContext(ProtocolMetaData metaData, String value) { for (HTTPContext context : metaData.getContexts(HTTPContext.class)) { if (value.equals(context.getName())) { return context; } } throw new IllegalArgumentException( "Could not find named context " + value + " in metadata. " + "Please verify your @" + TargetsContainer.class.getName() + " definition"); }
@Test public void shouldBeAbleToInjectBaseContextURLQualified() throws Exception { URLBaseContextClassQualified test = execute( URLBaseContextClassQualified.class, ProtocolMetaData.class, new ProtocolMetaData() .addContext(new HTTPContext("TEST-Y", 8080)), new ProtocolMetaData() .addContext(new HTTPContext("TEST-X", 8080))); Assert.assertEquals("http://TEST-X:8080", test.url.toExternalForm()); }
/** * Creates the {@link HTTPContext} instance, with the required preconditions in place. * * @throws Exception * When an exception is encountered during creation of the context. */ private void buildHTTPContext() throws Exception { // If there are no running servers, we'll abort as the test cannot be executed. if (wlServerRuntimes.length < 1) { throw new DeploymentException("None of the targets are in the RUNNING state."); } else { // For now, we'll use the first server to populate the context. // This may change in a future Arquillian release, // to allow different strategies for testing a clustered deployment. ObjectName wlServerRuntime = wlServerRuntimes[0]; String httpUrlAsString = (String) connection.invoke(wlServerRuntime, "getURL", new Object[] { "http" }, new String[] { "java.lang.String" } ); URL serverHttpUrl = new URL(httpUrlAsString); httpContext = new HTTPContext(serverHttpUrl.getHost(), serverHttpUrl.getPort()); List<ObjectName> servletRuntimes = findServletRuntimes(wlServerRuntime, deploymentName); for (ObjectName servletRuntime : servletRuntimes) { String servletName = (String) connection.getAttribute(servletRuntime, "ServletName"); String servletContextRoot = (String) connection.getAttribute(servletRuntime, "ContextPath"); httpContext.add(new Servlet(servletName, servletContextRoot)); } } }
@Test // equal ports, different ip public void shouldUpdateWithIPFromDocker() throws Exception { Binding binding = new Binding(GATEWAY_IP); binding.addPortBinding(EXPOSED_PORT, EXPOSED_PORT); Mockito.when(cube.getMetadata(HasPortBindings.class)).thenReturn(new TestPortBindings(binding)); bind(ContainerScoped.class, Container.class, new ContainerImpl(CUBE_CONTAINER_NAME, deployableContainer, new ContainerDefImpl("arquillian.xml"))); ProtocolMetaData metadata = new ProtocolMetaData(); metadata.addContext(new HTTPContext(LOCALHOST, EXPOSED_PORT).add(new Servlet("A", "B"))); bind(DeploymentScoped.class, ProtocolMetaData.class, metadata); fire(metadata); ProtocolMetaData updated = getManager().getContext(DeploymentContext.class) .getObjectStore().get(ProtocolMetaData.class); Assert.assertEquals(EXPOSED_PORT.intValue(), updated.getContexts(HTTPContext.class).iterator().next().getPort()); Assert.assertEquals(GATEWAY_IP, updated.getContexts(HTTPContext.class).iterator().next().getHost()); assertEventFired(ProtocolMetaData.class, 1); // twice, but original fire is intercepted and never hit the Counter }
ProtocolMetaData updatedMetaData = new ProtocolMetaData(); boolean updated = false; return; for (Object contextObj : originalMetaData.getContexts()) { if (contextObj instanceof HTTPContext) { HTTPContext context = (HTTPContext) contextObj; String ip = context.getHost(); int port = context.getPort(); final PortAddress mappedPort = portBindings.getMappedAddress(port); final String bindingIp; HTTPContext newContext = new HTTPContext(ip, port); for (Servlet servlet : context.getServlets()) { newContext.add(servlet); updatedMetaData.addContext(newContext);
for (final ServletInfo servletInfo : webapp.servlets) { if (http == null) { http = HTTPContext.class.cast(metaData.getContexts().iterator().next()); http.add(new Servlet(servletInfo.servletName, webapp.contextRoot)); http = HTTPContext.class.cast(metaData.getContexts().iterator().next()); http.add(new Servlet(path.substring(path.lastIndexOf('!') + 2).replace(".class", "").replace("/", "."), webapp.contextRoot)); return new ProtocolMetaData();
@Override protected HTTPContext locateHTTPContext(Method method) { HTTPContext previous = null; if (httpContexts != null && httpContexts.size() > 0) { previous = super.locateHTTPContext(method); } final ModuleContext mc = locateModuleContext(method); HTTPContext context; if (previous == null) { context = new HTTPContext(mc.getHost(), mc.getPort()); addArquillianServlet(context); } else { context = new HTTPContext(previous.getName(), mc.getHost(), mc.getPort()); boolean foundArqServlet = false; for (Servlet servlet : previous.getServlets()) { if (foundArqServlet == false && ServletMethodExecutor.ARQUILLIAN_SERVLET_NAME.equals(servlet.getName())) { foundArqServlet = true; } context.add(servlet); } if (foundArqServlet == false) { addArquillianServlet(context); } } return context; }
/** * @param management * @return */ private static HTTPContext extractHTTPContext(ManagementView management) throws Exception { Set<String> contextRootDeployments = management.getMatchingDeploymentName("http\\-.*"); if (contextRootDeployments.size() > 0) { String deploymentName = contextRootDeployments.iterator().next(); String expression = ".*\\-.*?(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})-(.*)"; return new HTTPContext(deploymentName.replaceAll(expression, "$1"), Integer.parseInt(deploymentName .replaceAll(expression, "$2"))); } return null; }
@Test public void testHTTPContext() { HTTPContext httpContext = new HTTPContext(TEST_HOST, TEST_PORT); assertEquals(TEST_HOST, httpContext.getHost()); assertEquals(TEST_PORT, httpContext.getPort()); }
return null; if (metaData.hasContext(HTTPContext.class)) { HTTPContext context = null; if (targets != null) { context = locateNamedHttpContext(metaData, targets.value()); } else { context = metaData.getContexts(HTTPContext.class).iterator().next(); Servlet servlet = context.getServletByName(resource.value().getSimpleName()); if (servlet == null) { servlet = context.getServletByName(resource.value().getName()); else if (allInSameContext(context.getServlets())) { return toURL(context.getServlets().get(0)); } else { return toURL(context);
private URI locateAuthURI(ProtocolMetaData data) { Collection<HTTPContext> contexts = data.getContexts(HTTPContext.class); if(contexts == null || contexts.size() == 0 || contexts.size() > 1) { throw new RuntimeException("Could not determine auth URL: " + contexts); } HTTPContext context = contexts.iterator().next(); return URI.create(context.getServlets().get(0).getBaseURI()+ "auth"); }
@Override public HTTPContext add(Servlet servlet) { initiateContext(); return context.add(servlet); }
public static URI determineBaseURI(ServletProtocolConfiguration config, HTTPContext context, String servletName) { String scheme = config.getScheme(); String host = config.getHost(); Integer port = config.getPort(); // TODO: can not set contextRoot in config, change to prefixContextRoot String contextRoot = null; //protocolConfiguration.getContextRoot(); Servlet servlet = context.getServletByName(servletName); if (servlet != null) { // use the context where the Arquillian servlet is found if (scheme == null) { scheme = "http"; } if (host == null) { host = context.getHost(); } if (port == null) { port = context.getPort(); } contextRoot = servlet.getContextRoot(); } else { throw new IllegalArgumentException( servletName + " not found. " + "Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer."); } return URI.create(scheme + "://" + host + ":" + port + contextRoot); }
protected URI getBaseURL() { HTTPContext context = metaDataInst.get().getContext(HTTPContext.class); if (allInSameContext(context.getServlets())) { return context.getServlets().get(0).getBaseURI(); } throw new IllegalStateException("No baseURL found in HTTPContext"); }
protected URI getBaseURI(Method method) throws Exception { ProtocolDefinition definition = registry.get().getProtocol(ProtocolDescription.DEFAULT); ModulesProtocolConfiguration configuration = (ModulesProtocolConfiguration) definition.createProtocolConfiguration(); HTTPContext context = ModulesApi.findHTTPContext(configuration, protocolMetaData, method); return context.getServlets().get(0).getBaseURI(); }
public Servlet getServletByName(String name) { for (Servlet servlet : getServlets()) { if (servlet.getName().equals(name)) { return servlet; } } return null; }