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_URL;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import org.apache.commons.lang.StringUtils;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 * Helper class for RestServiceNode
39 class ResourceUriExtractor {
41 private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
43 String extractResourceUri(SvcLogicContext ctx) throws Exception {
44 String resourceUri = ctx.getAttribute(INPUT_URL);
46 if (StringUtils.isBlank(resourceUri)) {
47 resourceUri = getAddress(ctx);
48 log.info("resourceUri= " + resourceUri);
49 resourceUri += getContext(ctx);
50 log.info("resourceUri= " + resourceUri);
53 log.info("resourceUri= " + resourceUri);
58 private String getAddress(SvcLogicContext ctx) {
59 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
60 String port = ctx.getAttribute(REST_PORT);
61 return HTTP + address + ":" + port;
64 private String getContext(SvcLogicContext ctx) throws Exception {
66 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
67 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
68 } else if (StringUtils.isNotBlank(ctx.getAttribute(REST_CONTEXT_URL))) {
69 context = "/" + ctx.getAttribute(REST_CONTEXT_URL);
71 throw new Exception("Could not find the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));