void log(Tomcat tomcat) { Connector[] connectors = tomcat.getService().findConnectors(); for (Connector connector : connectors) { if (StringUtils.equalsIgnoreCase(connector.getScheme(), "http")) { logHttp(connector); } else { throw new IllegalArgumentException("Unsupported connector: " + connector); } } }
private String getPortsDescription(boolean localPort) { StringBuilder ports = new StringBuilder(); for (Connector connector : this.tomcat.getService().findConnectors()) { if (ports.length() != 0) { ports.append(' '); } int port = localPort ? connector.getLocalPort() : connector.getPort(); ports.append(port).append(" (").append(connector.getScheme()).append(')'); } return ports.toString(); }
@Test public void unsupported_connector() { Connector connector = mock(Connector.class, Mockito.RETURNS_DEEP_STUBS); when(connector.getProtocol()).thenReturn("SPDY/1.1"); when(connector.getScheme()).thenReturn("spdy"); when(tomcat.getService().findConnectors()).thenReturn(new Connector[] {connector}); try { underTest.log(tomcat); fail(); } catch (IllegalArgumentException e) { // expected } }
@Test public void bind_to_specific_address() { Properties p = new Properties(); p.setProperty("sonar.web.port", "9000"); p.setProperty("sonar.web.host", "1.2.3.4"); TomcatConnectors.configure(tomcat, new Props(p)); verify(tomcat.getService()) .addConnector(argThat(c -> c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("1.2.3.4"))); }
@Test public void bind_to_all_addresses_by_default() { Properties p = new Properties(); p.setProperty("sonar.web.port", "9000"); TomcatConnectors.configure(tomcat, new Props(p)); verify(tomcat.getService()).addConnector(argThat(c -> c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("0.0.0.0"))); }
private void verifyHttpConnector(int expectedPort, Map<String, Object> expectedProps) { verify(tomcat.getService()).addConnector(argThat(c -> { if (!c.getScheme().equals("http")) { return false; } if (!c.getProtocol().equals(TomcatConnectors.HTTP_PROTOCOL)) { return false; } if (c.getPort() != expectedPort) { return false; } for (Map.Entry<String, Object> expectedProp : expectedProps.entrySet()) { if (!expectedProp.getValue().equals(c.getProperty(expectedProp.getKey()))) { return false; } } return true; })); } }
public String getScheme() { return connector.getScheme(); }
public String getScheme() { return connector.getScheme(); }
/** * Gets the network protocol that this connector handles. */ public String getProtocol() { String protocol = connector.getProtocol(); if(protocol.indexOf("AJP") > -1) { return WebManager.PROTOCOL_AJP; } else if(connector.getScheme().equalsIgnoreCase("http")) { return WebManager.PROTOCOL_HTTP; } else if(connector.getScheme().equalsIgnoreCase("https")) { return WebManager.PROTOCOL_HTTPS; } throw new IllegalStateException("Unknown protocol '"+protocol+"' and scheme '"+connector.getScheme()+"'"); }
@Override public String getScheme() { return getConnector().getScheme(); }
private void initializeConnectors() { org.apache.catalina.Service[] services = server.findServices(); for (org.apache.catalina.Service service : services) { for (Connector connector : service.findConnectors()) { if (connector.getScheme().equals("http")) { httpConnectors.add(connector); } else if (connector.getScheme().equals("https")) { httpsConnectors.add(connector); } } } }
private void initializeConnectors() { org.apache.catalina.Service[] services = server.findServices(); for (org.apache.catalina.Service service : services) { for (Connector connector : service.findConnectors()) { if (connector.getScheme().equals("http")) { httpConnectors.add(connector); } else if (connector.getScheme().equals("https")) { httpsConnectors.add(connector); } } } }
private static String address(final Collection<Connector> connectors, final String host, final String path) { final List<String> addresses = new ArrayList<>(); for (final Connector connector : connectors) { final URI address; try { address = new URI(connector.getScheme(), null, host, connector.getPort(), path, null, null); } catch (final Exception e) { // just an URI problem normally...shouldn't occur LOGGER.error("can't add container for path " + path, e); continue; } addresses.add(address.toString()); } return HttpUtil.selectSingleAddress(addresses); }
private static String address(final Collection<Connector> connectors, final String host, final String path) { final List<String> addresses = new ArrayList<String>(); for (final Connector connector : connectors) { final URI address; try { address = new URI(connector.getScheme(), null, host, connector.getPort(), path, null, null); } catch (final Exception e) { // just an URI problem normally...shouldn't occur LOGGER.error("can't add container for path " + path, e); continue; } addresses.add(address.toString()); } return HttpUtil.selectSingleAddress(addresses); }
private static String address(final Collection<Connector> connectors, final String host, final String path) { List<String> addresses = new ArrayList<String>(); for (Connector connector : connectors) { URI address; try { address = new URI(connector.getScheme(), null, host, connector.getPort(), path, null, null); } catch (Exception e) { // just an URI problem normally...shouldn't occur LOGGER.error("can't add container for path " + path, e); continue; } addresses.add(address.toString()); } return HttpUtil.selectSingleAddress(addresses); }
void log(Tomcat tomcat) { Connector[] connectors = tomcat.getService().findConnectors(); for (Connector connector : connectors) { if (StringUtils.equalsIgnoreCase(connector.getScheme(), "http")) { logHttp(connector); } else { throw new IllegalArgumentException("Unsupported connector: " + connector); } } }
public List<String> setWsContainer(String virtualHost, String contextRoot, String servletName, HttpListener wsContainer) throws Exception { if (virtualHost == null) virtualHost = engine.getDefaultHost(); Container host = engine.findChild(virtualHost); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'. Do you have a matchiing Host entry in the server.xml?"); } Context context = (Context) host.findChild("/" + contextRoot); if (context == null) { throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName()); } Wrapper wrapper = (Wrapper) context.findChild(servletName); if (wrapper == null) { throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName()); } setWsContainer(context, wrapper, wsContainer); // add service locations List<String> addresses = new ArrayList<String>(); for (Connector connector : connectors) { for (String mapping : wrapper.findMappings()) { URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), "/" + contextRoot + mapping, null, null); addresses.add(address.toString()); } } return addresses; }
/** * @return the base URL (with context) */ @Override public String getBaseUrl() { // Check is running Tomcat tom = getServer(); if (tom == null) { return null; } // Get parts of URL String host = "localhost"; String scheme = tom.getConnector().getScheme(); int port = tom.getConnector().getPort(); String contextPath = getContextPath(); // Build URL return scheme + "://" + host + ":" + port + contextPath; }
/** * Return the address. * * @return An address string */ public String getAddress() { String hostAddress = null; Connector connector = ServerUtil.getDefaultConnector(); if (connector.getProtocolHandler() instanceof Http11Protocol) { Http11Protocol protocol = (Http11Protocol) connector.getProtocolHandler(); InetAddress address = protocol.getAddress(); hostAddress = address.getHostAddress(); } else { ExtensionLogger.ROOT_LOGGER.unableToDetermineHostAddress(); hostAddress = ServerUtil.getDefaultHost().getHost().findAliases()[0]; } return connector.getScheme() + "://" + hostAddress + ":" + connector.getPort() + "/" + _contextName; }
/** * Return the address. * * @return An address string */ public String getAddress() { String hostAddress = null; Connector connector = ServerUtil.getDefaultConnector(); if (connector.getProtocolHandler() instanceof Http11Protocol) { Http11Protocol protocol = (Http11Protocol) connector.getProtocolHandler(); InetAddress address = protocol.getAddress(); hostAddress = address.getHostAddress(); } else { ExtensionLogger.ROOT_LOGGER.unableToDetermineHostAddress(); hostAddress = ServerUtil.getDefaultHost().getHost().findAliases()[0]; } return connector.getScheme() + "://" + hostAddress + ":" + connector.getPort() + "/" + _contextName; }