21
21
package password .pwm .svc .version ;
22
22
23
23
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
24
+ import lombok .AccessLevel ;
24
25
import lombok .Builder ;
25
26
import lombok .Value ;
26
27
import password .pwm .AppAttribute ;
53
54
import password .pwm .util .java .TimeDuration ;
54
55
import password .pwm .util .localdb .LocalDB ;
55
56
import password .pwm .util .logging .PwmLogger ;
56
- import password .pwm .ws .server .RestResultBean ;
57
57
58
58
import java .io .Serializable ;
59
59
import java .lang .reflect .ParameterizedType ;
@@ -161,6 +161,10 @@ private void scheduleNextCheck()
161
161
return ;
162
162
}
163
163
164
+ this .nextScheduledCheck = Instant .now ().plus ( 1 , ChronoUnit .MINUTES );
165
+ executorService .schedule ( new PeriodicCheck (), 1 , TimeUnit .MINUTES );
166
+
167
+ /*
164
168
final VersionCheckInfoCache localCache = cacheHolder.getVersionCheckInfoCache();
165
169
166
170
final TimeDuration idealDurationUntilNextCheck = localCache.getLastError() != null && localCache.getCurrentVersion() == null
@@ -185,6 +189,8 @@ private void scheduleNextCheck()
185
189
186
190
LOGGER.trace( SessionLabel.VERSIONCHECK_SESSION_LABEL, () -> "scheduled next check execution at " + JavaHelper.toIsoDate( nextScheduledCheck )
187
191
+ " in " + delayUntilNextExecution.asCompactString() );
192
+
193
+ */
188
194
}
189
195
190
196
private class PeriodicCheck implements Runnable
@@ -247,16 +253,17 @@ private PublishVersionBean executeFetch()
247
253
248
254
if ( response .getStatusCode () == 200 )
249
255
{
250
- final Type restResultBeanType = newParameterizedType ( RestResultBean .class , PublishVersionBean .class );
256
+ final Type restResultBeanType = newParameterizedType ( RestObjectBean .class , PublishVersionBean .class );
251
257
252
258
final String body = response .getBody ();
253
- final RestResultBean restResultBean = JsonUtil .deserialize ( body , restResultBeanType );
254
- return ( PublishVersionBean ) restResultBean .getData ();
259
+ final RestObjectBean < PublishVersionBean > restResultBean = JsonUtil .deserialize ( body , restResultBeanType );
260
+ return restResultBean .getData ();
255
261
}
256
262
else
257
263
{
258
264
LOGGER .debug ( SessionLabel .VERSIONCHECK_SESSION_LABEL , () -> "error reading cloud current version information: " + response );
259
- final String msg = "error reading cloud current version information: " + response .getStatusCode () + " " + response .getStatusPhrase ();
265
+ final String msg = "error reading cloud current version information: " + response .getStatusCode ()
266
+ + " " + ( response .getStatusPhrase () == null ? "" : response .getStatusPhrase () );
260
267
throw PwmUnrecoverableException .newException ( PwmError .ERROR_UNREACHABLE_CLOUD_SERVICE , msg );
261
268
}
262
269
}
@@ -444,4 +451,29 @@ public Type getOwnerType()
444
451
}
445
452
};
446
453
}
454
+
455
+ @ Value
456
+ @ Builder ( toBuilder = true , access = AccessLevel .PACKAGE )
457
+ private static class RestObjectBean <T > implements Serializable
458
+ {
459
+ private static final long serialVersionUID = 1L ;
460
+
461
+ private final T data ;
462
+ private final boolean error ;
463
+ private final int errorCode ;
464
+ private final String errorMessage ;
465
+ private final String errorDetail ;
466
+ private final String successMessage ;
467
+
468
+ @ SuppressFBWarnings ( "SE_TRANSIENT_FIELD_NOT_RESTORED" )
469
+ private final transient Class <T > classOfT ;
470
+
471
+ public static <T > RestObjectBean <T > withData ( final T data , final Class <T > classOfT )
472
+ {
473
+ return RestObjectBean .<T >builder ()
474
+ .data ( data )
475
+ .classOfT ( classOfT )
476
+ .build ();
477
+ }
478
+ }
447
479
}
0 commit comments