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.so.apihandler.filters;
23 import java.io.IOException;
25 import javax.ws.rs.container.ContainerRequestContext;
26 import javax.ws.rs.container.ContainerRequestFilter;
27 import javax.ws.rs.container.PreMatching;
28 import javax.ws.rs.core.UriInfo;
29 import org.onap.so.apihandlerinfra.Constants;
33 public class RequestUriFilter implements ContainerRequestFilter {
35 private String requestURI;
38 public void filter(ContainerRequestContext context) throws IOException {
39 UriInfo uriInfo = context.getUriInfo();
40 URI baseURI = uriInfo.getBaseUri();
41 requestURI = uriInfo.getPath();
43 if (requestURI.contains("onap/so/infra/serviceInstances")) {
44 requestURI = requestURI.replaceFirst("serviceInstances", "serviceInstantiation");
45 if (!requestURI.contains(Constants.SERVICE_INSTANCE_PATH)) {
46 // Adds /serviceInstances after the version provided in the URI
47 requestURI = new StringBuilder(requestURI)
48 .insert(requestURI.indexOf(Constants.SERVICE_INSTANTIATION_PATH) + 24,
49 Constants.SERVICE_INSTANCE_PATH)
52 requestURI = baseURI + requestURI;
53 URI uri = URI.create(requestURI);
54 context.setRequestUri(uri);
58 public String getRequestUri() {