1818 */
1919
2020/*
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.
2222 * Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2323 */
2424package opengrok .auth .plugin .util ;
@@ -44,27 +44,28 @@ private RestfulClient() {
4444 }
4545
4646 /**
47- * Perform HTTP PUT request.
47+ * Perform HTTP POST request.
4848 * @param uri URI
4949 * @param input JSON string contents
5050 * @return HTTP status or -1
5151 */
5252 public static int postIt (String uri , String input ) {
5353 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 ))) {
5560
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+ }
6165
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+ }
6568 }
66-
67- return status ;
6869 } catch (Exception e ) {
6970 LOGGER .log (Level .WARNING , "REST request failed" , e );
7071 return -1 ;
0 commit comments