Search in sources :

Example 1 with Port

use of org.apache.knox.gateway.util.urltemplate.Port in project knox by apache.

the class ServiceMappedAddressFunctionProcessor method resolve.

public String resolve(UrlRewriter.Direction direction, String parameter) throws Exception {
    String addr = parameter;
    String url = lookupServiceUrl(parameter);
    if (url != null) {
        Template template = Parser.parseLiteral(url);
        Host host = template.getHost();
        String hostStr = null;
        if (host != null) {
            hostStr = host.getFirstValue().getPattern();
            if (hostmap != null) {
                switch(direction) {
                    case IN:
                        hostStr = hostmap.resolveInboundHostName(hostStr);
                        break;
                    case OUT:
                        hostStr = hostmap.resolveOutboundHostName(hostStr);
                        break;
                }
            }
        }
        Port port = template.getPort();
        String portStr = null;
        if (port != null) {
            portStr = port.getFirstValue().getPattern();
        }
        if (hostStr != null && portStr != null) {
            addr = hostStr + ":" + portStr;
        } else if (host != null && port == null) {
            addr = hostStr;
        } else if (host == null && port != null) {
            addr = ":" + portStr;
        }
    }
    return addr;
}
Also used : Port(org.apache.knox.gateway.util.urltemplate.Port) Host(org.apache.knox.gateway.util.urltemplate.Host) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 2 with Port

use of org.apache.knox.gateway.util.urltemplate.Port in project knox by apache.

the class ServicePortFunctionProcessor method resolve.

@Override
public List<String> resolve(UrlRewriteContext context, List<String> parameters) throws Exception {
    List<String> results = null;
    if (parameters != null) {
        results = new ArrayList<String>(parameters.size());
        for (String parameter : parameters) {
            String url = lookupServiceUrl(parameter);
            if (url != null) {
                Template template = Parser.parseLiteral(url);
                Port port = template.getPort();
                if (port != null) {
                    parameter = port.getFirstValue().getPattern();
                }
            }
            results.add(parameter);
        }
    }
    return results;
}
Also used : Port(org.apache.knox.gateway.util.urltemplate.Port) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 3 with Port

use of org.apache.knox.gateway.util.urltemplate.Port in project knox by apache.

the class ServiceAddressFunctionProcessor method resolve.

public String resolve(String parameter) throws Exception {
    String addr = parameter;
    String url = lookupServiceUrl(parameter);
    if (url != null) {
        Template template = Parser.parseLiteral(url);
        Host host = template.getHost();
        String hostStr = null;
        if (host != null) {
            hostStr = host.getFirstValue().getPattern();
        }
        Port port = template.getPort();
        String portStr = null;
        if (port != null) {
            portStr = port.getFirstValue().getPattern();
        }
        if (hostStr != null && portStr != null) {
            addr = hostStr + ":" + portStr;
        } else if (host != null && port == null) {
            addr = hostStr;
        } else if (host == null && port != null) {
            addr = ":" + portStr;
        }
    }
    return addr;
}
Also used : Port(org.apache.knox.gateway.util.urltemplate.Port) Host(org.apache.knox.gateway.util.urltemplate.Host) Template(org.apache.knox.gateway.util.urltemplate.Template)

Aggregations

Port (org.apache.knox.gateway.util.urltemplate.Port)3 Template (org.apache.knox.gateway.util.urltemplate.Template)3 Host (org.apache.knox.gateway.util.urltemplate.Host)2