1 package org.onap.appc.flow.controller.node;
3 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP;
4 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
5 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
6 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
7 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
8 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
9 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
11 import com.att.eelf.configuration.EELFLogger;
12 import com.att.eelf.configuration.EELFManager;
13 import java.util.Properties;
14 import org.apache.commons.lang.StringUtils;
15 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
16 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
19 * Helper class for RestServiceNode
21 class ResourceUriExtractor {
23 private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
25 String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
26 String resourceUri = ctx.getAttribute(INPUT_URL);
28 if (StringUtils.isBlank(resourceUri)) {
29 resourceUri = getAddress(ctx);
30 log.info("resourceUri= " + resourceUri);
31 resourceUri += getContext(ctx, prop);
32 log.info("resourceUri= " + resourceUri);
33 resourceUri += getSubContext(ctx, prop);
35 log.info("resourceUri= " + resourceUri);
40 private String getAddress(SvcLogicContext ctx) {
41 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
42 String port = ctx.getAttribute(INPUT_PORT_NUMBER);
43 return HTTP + address + ":" + port;
46 private String getContext(SvcLogicContext ctx, Properties prop) throws Exception {
48 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
49 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
50 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context") != null) {
51 context = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context");
53 throw new Exception("Could Not found the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
58 private String getSubContext(SvcLogicContext ctx, Properties prop) throws Exception {
60 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_SUB_CONTEXT))) {
61 subContext = "/" + ctx.getAttribute(INPUT_SUB_CONTEXT);
62 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context") != null) {
63 subContext = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context");
65 throw new Exception("Could Not found the sub context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));