2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.appc.flow.controller.node;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
31 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
32 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
33 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36 import java.util.Properties;
37 import org.apache.commons.lang.StringUtils;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 * Helper class for RestServiceNode
43 class ResourceUriExtractor {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
47 String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
48 String resourceUri = ctx.getAttribute(INPUT_URL);
50 if (StringUtils.isBlank(resourceUri)) {
51 resourceUri = getAddress(ctx, prop);
52 log.info("resourceUri= " + resourceUri);
53 resourceUri += getContext(ctx, prop);
54 log.info("resourceUri= " + resourceUri);
55 resourceUri += getSubContext(ctx, prop);
57 log.info("resourceUri= " + resourceUri);
62 private String getAddress(SvcLogicContext ctx, Properties prop) {
63 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
64 String portPath = ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
65 + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT);
66 String port = prop.getProperty(portPath);
67 return HTTP + address + ":" + port;
70 private String getContext(SvcLogicContext ctx, Properties prop) throws Exception {
72 String urlPath = ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "." + ctx.getAttribute(INPUT_REQUEST_ACTION)
73 + "." + REST_CONTEXT_URL;
74 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
75 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
76 } else if (prop.getProperty(urlPath) != null) {
77 context = "/" + prop.getProperty(urlPath);
79 throw new Exception("Could not find the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
84 private String getSubContext(SvcLogicContext ctx, Properties prop) throws Exception {
86 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_SUB_CONTEXT))) {
87 subContext = "/" + ctx.getAttribute(INPUT_SUB_CONTEXT);
88 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context") != null) {
89 subContext = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context");
92 "Could not find the sub context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));