Initialize the httpd configuration section.
| 36 | |
| 37 | /** Initialize the {@code httpd} configuration section. */ |
| 38 | @Singleton |
| 39 | class InitHttpd implements InitStep { |
| 40 | private final ConsoleUI ui; |
| 41 | private final SitePaths site; |
| 42 | private final InitFlags flags; |
| 43 | private final Section httpd; |
| 44 | private final Section gerrit; |
| 45 | |
| 46 | @Inject |
| 47 | InitHttpd( |
| 48 | final ConsoleUI ui, |
| 49 | final SitePaths site, |
| 50 | final InitFlags flags, |
| 51 | final Section.Factory sections) { |
| 52 | this.ui = ui; |
| 53 | this.site = site; |
| 54 | this.flags = flags; |
| 55 | this.httpd = sections.get("httpd", null); |
| 56 | this.gerrit = sections.get("gerrit", null); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void run() throws IOException, InterruptedException { |
| 61 | ui.header("HTTP Daemon"); |
| 62 | |
| 63 | boolean anySsl = false; |
| 64 | // If any listenUrls are present, validate whether it can be parsed as URL. |
| 65 | String[] listenUrls = httpd.getList("listenUrl"); |
| 66 | for (String listenUrl : listenUrls) { |
| 67 | if (listenUrl != null && !listenUrl.isEmpty()) { |
| 68 | try { |
| 69 | final URI u = toURI(listenUrl); |
| 70 | if (u.getScheme().startsWith("https")) { |
| 71 | anySsl = true; |
| 72 | } |
| 73 | } catch (URISyntaxException e) { |
| 74 | System.err.println( |
| 75 | String.format( |
| 76 | "warning: invalid httpd.listenUrl entry: '%s'. Gerrit may not be able to start.", |
| 77 | listenUrl)); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (listenUrls.length > 1) { |
| 83 | // Because we will return early here, we will warn about steps otherwise being covered. |
| 84 | if (!ui.isBatch()) { |
| 85 | System.err.println( |
| 86 | "Interactive configuration is not supported with multiple entries of " |
| 87 | + "httpd.listenUrl."); |
| 88 | } |
| 89 | if (anySsl) { |
| 90 | System.err.println( |
| 91 | "Generating self-signed SSL certificates is not supported with multiple " |
| 92 | + "entries of httpd.listenUrl."); |
| 93 | } |
| 94 | String canonicalWebUrlDefaultString = ""; |
| 95 | if (listenUrls[0] != null && !listenUrls[0].isEmpty()) { |
nothing calls this directly
no outgoing calls
no test coverage detected