2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nest.internal.wwn.rest;
15 import java.io.IOException;
17 import javax.ws.rs.client.ClientRequestContext;
18 import javax.ws.rs.client.ClientRequestFilter;
19 import javax.ws.rs.core.HttpHeaders;
20 import javax.ws.rs.core.MultivaluedMap;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
26 * Inserts Authorization and Cache-Control headers for requests on the streaming WWN REST API.
28 * @author Wouter Born - Initial contribution
29 * @author Wouter Born - Replace polling with REST streaming
32 public class WWNStreamingRequestFilter implements ClientRequestFilter {
33 private final String accessToken;
35 public WWNStreamingRequestFilter(String accessToken) {
36 this.accessToken = accessToken;
40 public void filter(@Nullable ClientRequestContext requestContext) throws IOException {
41 if (requestContext != null) {
42 MultivaluedMap<String, Object> headers = requestContext.getHeaders();
43 headers.putSingle(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
44 headers.putSingle(HttpHeaders.CACHE_CONTROL, "no-cache");