18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2019, 2021 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2020, Chris Fraire <[email protected] >.
23
23
*/
24
24
package opengrok .auth .plugin .util ;
@@ -44,27 +44,28 @@ private RestfulClient() {
44
44
}
45
45
46
46
/**
47
- * Perform HTTP PUT request.
47
+ * Perform HTTP POST request.
48
48
* @param uri URI
49
49
* @param input JSON string contents
50
50
* @return HTTP status or -1
51
51
*/
52
52
public static int postIt (String uri , String input ) {
53
53
try {
54
- Client client = ClientBuilder .newClient ();
54
+ try (Client client = ClientBuilder .newClient ()) {
55
+ LOGGER .log (Level .FINEST , "sending REST POST request to {0}: {1}" ,
56
+ new Object []{uri , input });
57
+ try (Response response = client .target (uri )
58
+ .request (MediaType .APPLICATION_JSON )
59
+ .post (Entity .entity (input , MediaType .APPLICATION_JSON ))) {
55
60
56
- LOGGER .log (Level .FINEST , "sending REST POST request to {0}: {1}" ,
57
- new Object []{uri , input });
58
- Response response = client .target (uri )
59
- .request (MediaType .APPLICATION_JSON )
60
- .post (Entity .entity (input , MediaType .APPLICATION_JSON ));
61
+ int status = response .getStatus ();
62
+ if (status != HttpServletResponse .SC_CREATED ) {
63
+ LOGGER .log (Level .WARNING , "REST request failed: HTTP error code : {0}" , status );
64
+ }
61
65
62
- int status = response .getStatus ();
63
- if (status != HttpServletResponse .SC_CREATED ) {
64
- LOGGER .log (Level .WARNING , "REST request failed: HTTP error code : {0}" , status );
66
+ return status ;
67
+ }
65
68
}
66
-
67
- return status ;
68
69
} catch (Exception e ) {
69
70
LOGGER .log (Level .WARNING , "REST request failed" , e );
70
71
return -1 ;
0 commit comments