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