private URL toURL(HTTPContext context) { try { return new URI("http", null, context.getHost(), context.getPort(), null, null, null).toURL(); } catch (Exception e) { throw new RuntimeException("Could not convert HTTPContext to URL, " + context, e); } } }
@Override public String getHost() { initiateContext(); return context.getHost(); }
@Override public String getHost() { initiateContext(); return context.getHost(); }
private URL toURL(HTTPContext context) { try { return new URI("http", null, context.getHost(), context.getPort(), null, null, null).toURL(); } catch (Exception e) { throw new RuntimeException("Could not convert HTTPContext to URL, " + context, e); } } }
/** * Set the {@link HTTPContext} for this servlet. This is required for * <code>Servlet</code> to be fully initialized. Don't use * {@link #equals(Object)} prior to setting the <code>HTTPContext</code>, * which most likely implies not adding this to a collection beforehand * either. * * @param context * the context to set * * @throws IllegalArgumentException * if the context host is null * @see {@link HTTPContext#add(Servlet)} */ void setParent(HTTPContext context) { if (context.getHost() == null) { throw new IllegalArgumentException(context.getClass().getSimpleName() + " host must not be null"); } this.host = context.getHost(); this.port = context.getPort(); }
/** * Set the {@link HTTPContext} for this servlet. This is required for * <code>Servlet</code> to be fully initialized. Don't use * {@link #equals(Object)} prior to setting the <code>HTTPContext</code>, * which most likely implies not adding this to a collection beforehand * either. * * @param context * the context to set * * @throws IllegalArgumentException * if the context host is null * @see {@link HTTPContext#add(Servlet)} */ void setParent(HTTPContext context) { if (context.getHost() == null) { throw new IllegalArgumentException(context.getClass().getSimpleName() + " host must not be null"); } this.host = context.getHost(); this.port = context.getPort(); }
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 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); } } } }
return new URI("http", null, context.getHost(), context.getPort(), CommandBusOnServer.COMMAND_EVENT_BUS_MAPPING, null, null); } catch (URISyntaxException e) {
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); }
return httpContext.getHost();
@Test public void testHTTPContext() { HTTPContext httpContext = new HTTPContext(TEST_HOST, TEST_PORT); assertEquals(TEST_HOST, httpContext.getHost()); assertEquals(TEST_PORT, httpContext.getPort()); }
@Test public void testHTTPContext() { HTTPContext httpContext = new HTTPContext(TEST_HOST, TEST_PORT); assertEquals(TEST_HOST, httpContext.getHost()); assertEquals(TEST_PORT, httpContext.getPort()); }
@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 }
@Test // equal ip, different ports public void shouldUpdateWithPortFromDocker() throws Exception { Binding binding = new Binding(LOCALHOST); binding.addPortBinding(EXPOSED_PORT, BOUND_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(BOUND_PORT.intValue(), updated.getContexts(HTTPContext.class).iterator().next().getPort()); Assert.assertEquals(LOCALHOST, updated.getContexts(HTTPContext.class).iterator().next().getHost()); assertEventFired(ProtocolMetaData.class, 1); // twice, but original fire is intercepted and never hit the Counter }
if (contextObj instanceof HTTPContext) { HTTPContext context = (HTTPContext) contextObj; String ip = context.getHost(); int port = context.getPort(); final PortAddress mappedPort = portBindings.getMappedAddress(port);
if (contextObj instanceof HTTPContext) { HTTPContext context = (HTTPContext) contextObj; String ip = context.getHost(); int port = context.getPort(); final PortAddress mappedPort = portBindings.getMappedAddress(port);