2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
20 package org.onap.aai.interceptors.pre;
22 import java.io.IOException;
23 import java.util.Arrays;
24 import java.util.List;
27 import java.util.stream.Collectors;
29 import javax.annotation.Priority;
30 import javax.ws.rs.container.ContainerRequestContext;
31 import javax.ws.rs.container.ContainerRequestFilter;
32 import javax.ws.rs.container.PreMatching;
33 import javax.ws.rs.core.MultivaluedMap;
34 import javax.ws.rs.core.UriBuilder;
36 import org.onap.aai.interceptors.AAIContainerFilter;
39 @Priority(AAIRequestFilterPriority.HEADER_VALIDATION)
40 public class RequestModification extends AAIContainerFilter implements ContainerRequestFilter {
43 public void filter(ContainerRequestContext requestContext) throws IOException {
45 this.cleanDME2QueryParams(requestContext);
49 private void cleanDME2QueryParams(ContainerRequestContext request) {
50 UriBuilder builder = request.getUriInfo().getRequestUriBuilder();
51 MultivaluedMap<String, String> queries = request.getUriInfo().getQueryParameters();
53 String[] blacklist = { "version", "envContext", "routeOffer" };
54 Set<String> blacklistSet = Arrays.stream(blacklist).collect(Collectors.toSet());
56 boolean remove = true;
58 for (String param : blacklistSet) {
59 if (!queries.containsKey(param)) {
66 for (Map.Entry<String, List<String>> query : queries.entrySet()) {
67 String key = query.getKey();
68 if (blacklistSet.contains(key)) {
69 builder.replaceQueryParam(key);
73 request.setRequestUri(builder.build());