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.aailog.logs;
22 public class ServiceName {
24 * Extract the service name from a URI path
25 * Service name should be the URI path up to two levels down from the version or less
26 * @param path the URI path
27 * @return the service name
29 public static String extractServiceName (String path) {
30 StringBuilder sBuilder = new StringBuilder();
31 String[] parts = path.split("/");
33 for (int i = 0; i < parts.length; i++) {
36 sBuilder.append(part).append("/");
41 if ((sBuilder.length() > 0) && (sBuilder.charAt(sBuilder.length()-1) == '/')) {
42 sBuilder.deleteCharAt(sBuilder.length()-1);
44 String serviceName = sBuilder.toString();
45 if (serviceName != null && (!serviceName.isEmpty())) {
46 serviceName = serviceName.replaceAll(",", "\\\\,");