2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.interceptors.pre;
23 import java.io.IOException;
24 import java.util.Arrays;
25 import java.util.List;
28 import java.util.stream.Collectors;
30 import javax.annotation.Priority;
31 import javax.ws.rs.container.ContainerRequestContext;
32 import javax.ws.rs.container.ContainerRequestFilter;
33 import javax.ws.rs.container.PreMatching;
34 import javax.ws.rs.core.MultivaluedMap;
35 import javax.ws.rs.core.UriBuilder;
37 import org.onap.aai.interceptors.AAIContainerFilter;
40 @Priority(AAIRequestFilterPriority.HEADER_VALIDATION)
41 public class RequestModification extends AAIContainerFilter implements ContainerRequestFilter {
44 public void filter(ContainerRequestContext requestContext) throws IOException {
46 this.cleanDME2QueryParams(requestContext);
50 private void cleanDME2QueryParams(ContainerRequestContext request) {
51 UriBuilder builder = request.getUriInfo().getRequestUriBuilder();
52 MultivaluedMap<String, String> queries = request.getUriInfo().getQueryParameters();
54 String[] blacklist = { "version", "envContext", "routeOffer" };
55 Set<String> blacklistSet = Arrays.stream(blacklist).collect(Collectors.toSet());
57 boolean remove = true;
59 for (String param : blacklistSet) {
60 if (!queries.containsKey(param)) {
67 for (Map.Entry<String, List<String>> query : queries.entrySet()) {
68 String key = query.getKey();
69 if (blacklistSet.contains(key)) {
70 builder.replaceQueryParam(key);
74 request.setRequestUri(builder.build());