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;
18 * Helper class for RestServiceNode
20 class ResourceUriExtractor {
22 private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
24 private ResourceUriExtractor() {
27 static String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
28 String resourceUri = ctx.getAttribute(INPUT_URL);
30 if (StringUtils.isBlank(resourceUri)) {
31 resourceUri = getAddress(ctx);
32 log.info("resourceUri= " + resourceUri);
33 resourceUri += getContext(ctx, prop);
34 log.info("resourceUri= " + resourceUri);
35 resourceUri += getSubContext(ctx, prop);
37 log.info("resourceUri= " + resourceUri);
42 private static String getAddress(SvcLogicContext ctx) {
43 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
44 String port = ctx.getAttribute(INPUT_PORT_NUMBER);
45 return HTTP + address + ":" + port;
48 private static String getContext(SvcLogicContext ctx, Properties prop) {
50 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
51 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
52 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context") != null) {
53 context = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context");
55 throw new IllegalArgumentException("Could Not found the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
60 private static String getSubContext(SvcLogicContext ctx, Properties prop) {
62 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_SUB_CONTEXT))) {
63 subContext = "/" + ctx.getAttribute(INPUT_SUB_CONTEXT);
64 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context") != null) {
65 subContext = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context");
67 throw new IllegalArgumentException("Could Not found the sub context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));