2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. 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.appc.flow.controller.node;
22 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP;
23 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import java.util.Properties;
33 import org.apache.commons.lang.StringUtils;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38 * Helper class for RestServiceNode
40 class ResourceUriExtractor {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
44 String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
45 String resourceUri = ctx.getAttribute(INPUT_URL);
47 if (StringUtils.isBlank(resourceUri)) {
48 resourceUri = getAddress(ctx);
49 log.info("resourceUri= " + resourceUri);
50 resourceUri += getContext(ctx, prop);
51 log.info("resourceUri= " + resourceUri);
52 resourceUri += getSubContext(ctx, prop);
54 log.info("resourceUri= " + resourceUri);
59 private String getAddress(SvcLogicContext ctx) {
60 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
61 String port = ctx.getAttribute(INPUT_PORT_NUMBER);
62 return HTTP + address + ":" + port;
65 private String getContext(SvcLogicContext ctx, Properties prop) throws Exception {
67 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
68 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
69 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context") != null) {
70 context = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context");
72 throw new Exception("Could Not found the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
77 private String getSubContext(SvcLogicContext ctx, Properties prop) throws Exception {
79 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_SUB_CONTEXT))) {
80 subContext = "/" + ctx.getAttribute(INPUT_SUB_CONTEXT);
81 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context") != null) {
82 subContext = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context");
84 throw new Exception("Could Not found the sub context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));