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() {}
26 static String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
27 String resourceUri = ctx.getAttribute(INPUT_URL);
29 if (StringUtils.isBlank(resourceUri)) {
30 resourceUri = getAddress(ctx);
31 log.info("resourceUri= " + resourceUri);
32 resourceUri += getContext(ctx, prop);
33 log.info("resourceUri= " + resourceUri);
34 resourceUri += getSubContext(ctx, prop);
36 log.info("resourceUri= " + resourceUri);
41 private static String getAddress(SvcLogicContext ctx) {
42 String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
43 String port = ctx.getAttribute(INPUT_PORT_NUMBER);
44 return HTTP + address + ":" + port;
47 private static String getContext(SvcLogicContext ctx, Properties prop) {
49 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
50 context = "/" + ctx.getAttribute(INPUT_CONTEXT);
51 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context") != null) {
52 context = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".context");
54 throw new IllegalArgumentException("Could Not found the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
59 private static String getSubContext(SvcLogicContext ctx, Properties prop) {
61 if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_SUB_CONTEXT))) {
62 subContext = "/" + ctx.getAttribute(INPUT_SUB_CONTEXT);
63 } else if (prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context") != null) {
64 subContext = "/" + prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION) + ".sub-context");
66 throw new IllegalArgumentException("Could Not found the sub context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));