@@ -0,0 +1,1900 @@
+/*%0A * Copyright 2014-2015 Red Hat, Inc. and/or its affiliates%0A * and other contributors as indicated by the @author tags.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.hawkular.metrics.api.jaxrs;%0A%0Aimport java.io.IOException;%0A%0Aimport javax.ws.rs.container.ContainerRequestContext;%0Aimport javax.ws.rs.container.ContainerRequestFilter;%0Aimport javax.ws.rs.core.Response;%0Aimport javax.ws.rs.ext.Provider;%0A%0A/**%0A * @author Stefan Negrea%0A *%0A */%0A@Provider%0Apublic class TenantIdFilter implements ContainerRequestFilter %7B%0A%0A    @Override%0A    public void filter(ContainerRequestContext requestContext) throws IOException %7B%0A        if (!requestContext.getUriInfo().getAbsolutePath().toString().contains(%22tenants%22)) %7B%0A            String tenantIdHeaderParam = requestContext.getHeaderString(%22tenantId%22);%0A            if (tenantIdHeaderParam == null %7C%7C tenantIdHeaderParam.isEmpty()) %7B%0A                String tenandIdQueryParam = requestContext.getUriInfo().getQueryParameters().getFirst(%22tenantId%22);%0A                if (tenandIdQueryParam == null %7C%7C tenandIdQueryParam.isEmpty()) %7B%0A                    requestContext.abortWith(Response.status(Response.Status.BAD_REQUEST)%0A                            .entity(new ApiError(%22Tenant id not specified%22)).build());%0A                %7D%0A%0A                requestContext.getHeaders().add(%22tenantId%22, tenandIdQueryParam);%0A            %7D%0A        %7D%0A    %7D%0A%7D

Add a filter to transform requests that have tenantId as a query param when header information is missing. The fallback mechanism gracefully attempts to recreate the tenantId header if the param with an identical name is present. This will allow an easy transition and backwards compatibility for clients that cannot set headers on requests.