1616import java .net .URI ;
1717import java .net .URISyntaxException ;
1818import java .text .Collator ;
19- import java .time .Instant ;
20- import java .time .temporal .ChronoUnit ;
2119import java .util .Collection ;
22- import java .util .Date ;
2320import java .util .List ;
2421import java .util .Locale ;
2522import java .util .Map ;
4037import javax .ws .rs .QueryParam ;
4138import javax .ws .rs .core .Context ;
4239import javax .ws .rs .core .MediaType ;
43- import javax .ws .rs .core .Request ;
4440import javax .ws .rs .core .Response ;
4541import javax .ws .rs .core .Response .Status ;
4642import javax .ws .rs .core .UriInfo ;
4945import org .eclipse .jdt .annotation .Nullable ;
5046import org .eclipse .jetty .http .HttpStatus ;
5147import org .openhab .core .addon .Addon ;
52- import org .openhab .core .addon .AddonEvent ;
5348import org .openhab .core .addon .AddonEventFactory ;
5449import org .openhab .core .addon .AddonInfo ;
5550import org .openhab .core .addon .AddonInfoRegistry ;
6459import org .openhab .core .config .discovery .addon .AddonSuggestionService ;
6560import org .openhab .core .events .Event ;
6661import org .openhab .core .events .EventPublisher ;
67- import org .openhab .core .events .EventSubscriber ;
6862import org .openhab .core .io .rest .JSONResponse ;
6963import org .openhab .core .io .rest .LocaleService ;
7064import org .openhab .core .io .rest .RESTConstants ;
112106@ SecurityRequirement (name = "oauth2" , scopes = { "admin" })
113107@ Tag (name = AddonResource .PATH_ADDONS )
114108@ NonNullByDefault
115- public class AddonResource implements RESTResource , EventSubscriber {
109+ public class AddonResource implements RESTResource {
116110
117111 private static final String THREAD_POOL_NAME = "addonService" ;
118112
119113 public static final String PATH_ADDONS = "addons" ;
120114
121115 public static final String DEFAULT_ADDON_SERVICE = "karaf" ;
122- private static final Set <String > SUBSCRIBED_EVENT_TYPES = Set .of (AddonEvent .TYPE );
123116
124117 private final Logger logger = LoggerFactory .getLogger (AddonResource .class );
125118 private final Set <AddonService > addonServices = new CopyOnWriteArraySet <>();
@@ -130,8 +123,6 @@ public class AddonResource implements RESTResource, EventSubscriber {
130123 private final ConfigDescriptionRegistry configDescriptionRegistry ;
131124 private final AddonSuggestionService addonSuggestionService ;
132125
133- private @ Nullable Date lastModified = null ;
134-
135126 private @ Context @ NonNullByDefault ({}) UriInfo uriInfo ;
136127
137128 @ Activate
@@ -151,57 +142,31 @@ public AddonResource(final @Reference EventPublisher eventPublisher, final @Refe
151142 @ Reference (cardinality = ReferenceCardinality .MULTIPLE , policy = ReferencePolicy .DYNAMIC )
152143 protected void addAddonService (AddonService featureService ) {
153144 this .addonServices .add (featureService );
154- lastModified = null ;
155145 }
156146
157147 protected void removeAddonService (AddonService featureService ) {
158148 this .addonServices .remove (featureService );
159149 }
160150
161- @ Override
162- public Set <String > getSubscribedEventTypes () {
163- return SUBSCRIBED_EVENT_TYPES ;
164- }
165-
166- @ Override
167- public void receive (Event event ) {
168- lastModified = null ;
169- }
170-
171- private boolean lastModifiedIsValid () {
172- return (lastModified != null ) && ((new Date ().getTime () - lastModified .getTime ()) <= 450 * 1000 );
173- }
174-
175151 @ GET
176152 @ Produces (MediaType .APPLICATION_JSON )
177153 @ Operation (operationId = "getAddons" , summary = "Get all add-ons." , responses = {
178154 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (array = @ ArraySchema (schema = @ Schema (implementation = Addon .class )))),
179155 @ ApiResponse (responseCode = "404" , description = "Service not found" ) })
180- public Response getAddon (final @ Context Request request ,
156+ public Response getAddon (
181157 @ HeaderParam ("Accept-Language" ) @ Parameter (description = "language" ) @ Nullable String language ,
182158 @ QueryParam ("serviceId" ) @ Parameter (description = "service ID" ) @ Nullable String serviceId ) {
183159 logger .debug ("Received HTTP GET request at '{}'" , uriInfo .getPath ());
184- if (lastModifiedIsValid ()) {
185- Response .ResponseBuilder responseBuilder = request .evaluatePreconditions (lastModified );
186- if (responseBuilder != null ) {
187- // send 304 Not Modified
188- return responseBuilder .build ();
189- }
190- } else {
191- lastModified = Date .from (Instant .now ().truncatedTo (ChronoUnit .SECONDS ));
192- }
193160
194161 final Locale locale = localeService .getLocale (language );
195162 if ("all" .equals (serviceId )) {
196- return Response .ok (new Stream2JSONInputStream (getAllAddons (locale ))).lastModified (lastModified )
197- .cacheControl (RESTConstants .CACHE_CONTROL ).build ();
163+ return Response .ok (new Stream2JSONInputStream (getAllAddons (locale ))).build ();
198164 } else {
199165 AddonService addonService = (serviceId != null ) ? getServiceById (serviceId ) : getDefaultService ();
200166 if (addonService == null ) {
201167 return Response .status (HttpStatus .NOT_FOUND_404 ).build ();
202168 }
203- return Response .ok (new Stream2JSONInputStream (addonService .getAddons (locale ).stream ()))
204- .lastModified (lastModified ).cacheControl (RESTConstants .CACHE_CONTROL ).build ();
169+ return Response .ok (new Stream2JSONInputStream (addonService .getAddons (locale ).stream ())).build ();
205170 }
206171 }
207172
@@ -210,23 +175,12 @@ public Response getAddon(final @Context Request request,
210175 @ Produces (MediaType .APPLICATION_JSON )
211176 @ Operation (operationId = "getAddonTypes" , summary = "Get all add-on types." , responses = {
212177 @ ApiResponse (responseCode = "200" , description = "OK" , content = @ Content (array = @ ArraySchema (schema = @ Schema (implementation = AddonType .class )))) })
213- public Response getServices (final @ Context Request request ,
178+ public Response getServices (
214179 @ HeaderParam ("Accept-Language" ) @ Parameter (description = "language" ) @ Nullable String language ) {
215180 logger .debug ("Received HTTP GET request at '{}'" , uriInfo .getPath ());
216- if (lastModifiedIsValid ()) {
217- Response .ResponseBuilder responseBuilder = request .evaluatePreconditions (lastModified );
218- if (responseBuilder != null ) {
219- // send 304 Not Modified
220- return responseBuilder .build ();
221- }
222- } else {
223- lastModified = Date .from (Instant .now ().truncatedTo (ChronoUnit .SECONDS ));
224- }
225-
226181 final Locale locale = localeService .getLocale (language );
227182 Stream <AddonServiceDTO > addonTypeStream = addonServices .stream ().map (s -> convertToAddonServiceDTO (s , locale ));
228- return Response .ok (new Stream2JSONInputStream (addonTypeStream )).lastModified (lastModified )
229- .cacheControl (RESTConstants .CACHE_CONTROL ).build ();
183+ return Response .ok (new Stream2JSONInputStream (addonTypeStream )).build ();
230184 }
231185
232186 @ GET
0 commit comments