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;
}
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;
}
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;
}
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;
}