Search in sources :

Example 1 with Host

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

the class ServiceMappedHostFunctionProcessor 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);
                Host host = template.getHost();
                if (host != null) {
                    String hostStr = host.getFirstValue().getPattern();
                    if (hostmap != null) {
                        switch(context.getDirection()) {
                            case IN:
                                parameter = hostmap.resolveInboundHostName(hostStr);
                                break;
                            case OUT:
                                parameter = hostmap.resolveOutboundHostName(hostStr);
                                break;
                        }
                    } else {
                        parameter = hostStr;
                    }
                }
            }
            results.add(parameter);
        }
    }
    return results;
}
Also used : Host(org.apache.knox.gateway.util.urltemplate.Host) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 2 with Host

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

the class ServiceHostFunctionProcessor 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);
                Host host = template.getHost();
                if (host != null) {
                    parameter = host.getFirstValue().getPattern();
                }
            }
            results.add(parameter);
        }
    }
    return results;
}
Also used : Host(org.apache.knox.gateway.util.urltemplate.Host) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 3 with Host

use of org.apache.knox.gateway.util.urltemplate.Host 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 4 with Host

use of org.apache.knox.gateway.util.urltemplate.Host 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

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