|
18 | 18 | */ |
19 | 19 |
|
20 | 20 | /* |
21 | | - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. |
| 21 | + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. |
22 | 22 | */ |
23 | 23 | package org.opengrok.indexer.index; |
24 | 24 |
|
| 25 | +import jakarta.ws.rs.client.Client; |
25 | 26 | import org.opengrok.indexer.configuration.RuntimeEnvironment; |
26 | 27 |
|
27 | 28 | import jakarta.ws.rs.ProcessingException; |
@@ -68,19 +69,23 @@ public static void enableProjects(final String host) throws |
68 | 69 | ResponseProcessingException, |
69 | 70 | ProcessingException, |
70 | 71 | WebApplicationException { |
71 | | - final Invocation.Builder request = ClientBuilder.newClient() |
72 | | - .target(host) |
73 | | - .path("api") |
74 | | - .path("v1") |
75 | | - .path("configuration") |
76 | | - .path("projectsEnabled") |
77 | | - .request() |
78 | | - .headers(getWebAppHeaders()); |
79 | | - final String enabled = request.get(String.class); |
80 | | - if (!Boolean.parseBoolean(enabled)) { |
81 | | - final Response r = request.put(Entity.text(Boolean.TRUE.toString())); |
82 | | - if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { |
83 | | - throw new WebApplicationException(String.format("Unable to enable projects: %s", r.getStatusInfo().getReasonPhrase()), r.getStatus()); |
| 72 | + |
| 73 | + try (Client client = ClientBuilder.newClient()) { |
| 74 | + final Invocation.Builder request = client.target(host) |
| 75 | + .path("api") |
| 76 | + .path("v1") |
| 77 | + .path("configuration") |
| 78 | + .path("projectsEnabled") |
| 79 | + .request() |
| 80 | + .headers(getWebAppHeaders()); |
| 81 | + final String enabled = request.get(String.class); |
| 82 | + if (!Boolean.parseBoolean(enabled)) { |
| 83 | + try (final Response r = request.put(Entity.text(Boolean.TRUE.toString()))) { |
| 84 | + if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { |
| 85 | + throw new WebApplicationException(String.format("Unable to enable projects: %s", |
| 86 | + r.getStatusInfo().getReasonPhrase()), r.getStatus()); |
| 87 | + } |
| 88 | + } |
84 | 89 | } |
85 | 90 | } |
86 | 91 | } |
|
0 commit comments