@@ -56,7 +56,6 @@ public AdminManager(AdminConfig adminConfig) {
5656 */
5757 public void setAdminConfig (AdminConfig adminConfig ) {
5858 this .adminConfig = adminConfig ;
59- this .restTemplate = RestTemplateUtil .newRestTemplate (adminConfig );
6059 }
6160
6261 public void init () {
@@ -82,7 +81,7 @@ public boolean execute() {
8281 headers .setContentType (MediaType .APPLICATION_JSON );
8382 HttpEntity <String > entity = new HttpEntity <>(payload , headers );
8483 try {
85- ResponseEntity <String > response = restTemplate .exchange (uri , HttpMethod .POST , entity , String .class );
84+ ResponseEntity <String > response = getRestTemplate () .exchange (uri , HttpMethod .POST , entity , String .class );
8685 logger .info ("Initialization response: " + response );
8786 // According to http://docs.marklogic.com/REST/POST/admin/v1/init, a 202 is sent back in the event a
8887 // restart is needed. A 400 or 401 will be thrown as an error by RestTemplate.
@@ -132,7 +131,7 @@ public boolean execute() {
132131 headers .setContentType (MediaType .APPLICATION_JSON );
133132 HttpEntity <String > entity = new HttpEntity <>(payload , headers );
134133 try {
135- ResponseEntity <String > response = restTemplate .exchange (uri , HttpMethod .POST , entity , String .class );
134+ ResponseEntity <String > response = getRestTemplate () .exchange (uri , HttpMethod .POST , entity , String .class );
136135 logger .info ("Admin installation response: " + response );
137136 // According to http://docs.marklogic.com/REST/POST/admin/v1/init, a 202 is sent back in the event a
138137 // restart is needed. A 400 or 401 will be thrown as an error by RestTemplate.
@@ -166,7 +165,7 @@ public void invokeActionRequiringRestart(ActionRequiringRestart action) {
166165 }
167166
168167 public String getLastRestartTimestamp () {
169- return restTemplate .getForEntity (adminConfig .buildUri ("/admin/v1/timestamp" ), String .class ).getBody ();
168+ return getRestTemplate () .getForEntity (adminConfig .buildUri ("/admin/v1/timestamp" ), String .class ).getBody ();
170169 }
171170
172171 public void waitForRestart () {
@@ -230,7 +229,7 @@ public boolean execute() {
230229 }
231230
232231 public Fragment getServerConfig () {
233- return new Fragment (restTemplate .getForObject (adminConfig .buildUri ("/admin/v1/server-config" ), String .class ));
232+ return new Fragment (getRestTemplate () .getForObject (adminConfig .buildUri ("/admin/v1/server-config" ), String .class ));
234233 }
235234
236235 public String getServerVersion () {
@@ -271,7 +270,7 @@ public byte[] postJoiningHostConfig(Fragment joiningHostConfig, String group, St
271270 HttpEntity <MultiValueMap <String , String >> entity = new HttpEntity <>(map , headers );
272271
273272 URI url = adminConfig .buildUri ("/admin/v1/cluster-config" );
274- ResponseEntity <byte []> bytes = restTemplate .exchange (url , HttpMethod .POST , entity , byte [].class );
273+ ResponseEntity <byte []> bytes = getRestTemplate () .exchange (url , HttpMethod .POST , entity , byte [].class );
275274 return bytes .getBody ();
276275 }
277276
@@ -288,7 +287,7 @@ public void postClustConfigToJoiningHost(byte[] clusterConfigZipBytes) {
288287 URI clusterConfigUri = adminConfig .buildUri ("/admin/v1/cluster-config" );
289288
290289 HttpEntity <Resource > resourceEntity = new HttpEntity <>(new ByteArrayResource (clusterConfigZipBytes ), headers );
291- ResponseEntity <String > response = restTemplate .exchange (clusterConfigUri , HttpMethod .POST , resourceEntity , String .class );
290+ ResponseEntity <String > response = getRestTemplate () .exchange (clusterConfigUri , HttpMethod .POST , resourceEntity , String .class );
292291 if (response .getStatusCode ().value () == 202 ){
293292 waitForRestart ();
294293 }
@@ -299,7 +298,7 @@ public void postClustConfigToJoiningHost(byte[] clusterConfigZipBytes) {
299298 * Note that once it does so, the server will need to be initialized again
300299 */
301300 public void leaveCluster () {
302- ResponseEntity <String > response = restTemplate .exchange (adminConfig .buildUri ("/admin/v1/host-config" ), HttpMethod .DELETE , null , String .class );
301+ ResponseEntity <String > response = getRestTemplate () .exchange (adminConfig .buildUri ("/admin/v1/host-config" ), HttpMethod .DELETE , null , String .class );
303302 if (response .getStatusCode ().value () == 202 ) {
304303 waitForRestart ();
305304 }
@@ -310,6 +309,9 @@ public AdminConfig getAdminConfig() {
310309 }
311310
312311 public RestTemplate getRestTemplate () {
313- return restTemplate ;
312+ if (this .restTemplate == null ) {
313+ this .restTemplate = RestTemplateUtil .newRestTemplate (adminConfig );
314+ }
315+ return this .restTemplate ;
314316 }
315317}
0 commit comments