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=========================================================
21 package org.onap.aai.aailog.logs;
23 public class ServiceName {
25 * Extract the service name from a URI path
26 * Service name should be the URI path up to two levels down from the version or less
28 * @param path the URI path
29 * @return the service name
31 public static String extractServiceName(String path) {
32 StringBuilder sBuilder = new StringBuilder();
33 String[] parts = path.split("/");
35 for (int i = 0; i < parts.length; i++) {
38 sBuilder.append(part).append("/");
43 if ((sBuilder.length() > 0) && (sBuilder.charAt(sBuilder.length() - 1) == '/')) {
44 sBuilder.deleteCharAt(sBuilder.length() - 1);
46 String serviceName = sBuilder.toString();
47 if (serviceName != null && (!serviceName.isEmpty())) {
48 serviceName = serviceName.replaceAll(",", "\\\\,");