use of io.fabric8.gateway.SocketWrapper in project fabric8 by jboss-fuse.
the class DetectingGateway method route.
public void route(final SocketWrapper socket, ConnectionParameters params, final Buffer received) {
NetClient client = null;
if (params.protocolVirtualHost == null) {
params.protocolVirtualHost = defaultVirtualHost;
}
HashSet<String> schemes = new HashSet<String>(Arrays.asList(params.protocolSchemes));
if (params.protocolVirtualHost != null) {
List<ServiceDetails> services = serviceMap.getServices(params.protocolVirtualHost);
// Lets try again with the defaultVirtualHost
if (services.isEmpty() && !params.protocolVirtualHost.equals(defaultVirtualHost)) {
params.protocolVirtualHost = defaultVirtualHost;
services = serviceMap.getServices(params.protocolVirtualHost);
}
LOG.debug(String.format("%d services match the virtual host", services.size()));
if (!services.isEmpty()) {
ClientRequestFacade clientRequestFacade = clientRequestFacadeFactory.create(socket, params);
ServiceDetails serviceDetails = serviceLoadBalancer.choose(services, clientRequestFacade);
if (serviceDetails != null) {
List<String> urlStrings = serviceDetails.getServices();
LOG.debug("Selected service exposes the following URLS: {}", urlStrings);
for (String urlString : urlStrings) {
if (Strings.notEmpty(urlString)) {
// lets create a client for this request...
try {
URI uri = new URI(urlString);
// URL url = new URL(urlString);
String urlProtocol = uri.getScheme();
if (schemes.contains(urlProtocol)) {
if (!socket.remoteAddress().toString().equals(clientRequestFacade.getClientRequestKey())) {
LOG.info(String.format("Connecting client from '%s' (with key '%s') requesting virtual host '%s' to '%s:%d' using the %s protocol", socket.remoteAddress(), clientRequestFacade.getClientRequestKey(), params.protocolVirtualHost, uri.getHost(), uri.getPort(), params.protocol));
} else {
LOG.info(String.format("Connecting client from '%s' requesting virtual host '%s' to '%s:%d' using the %s protocol", socket.remoteAddress(), params.protocolVirtualHost, uri.getHost(), uri.getPort(), params.protocol));
}
client = createClient(params, socket, uri, received);
break;
}
} catch (URISyntaxException e) {
LOG.warn("Failed to parse URI: " + urlString + ". " + e, e);
}
}
}
}
}
}
if (client == null) {
// failed to route
handleConnectFailure(socket, String.format("No endpoint available for virtual host '%s' and protocol %s", params.protocolVirtualHost, params.protocol));
}
}
use of io.fabric8.gateway.SocketWrapper in project fabric8 by jboss-fuse.
the class AmqpProtocol method snoopConnectionParameters.
@Override
public void snoopConnectionParameters(final SocketWrapper socket, final Buffer received, final Handler<ConnectionParameters> handler) {
// We can't yet snoop the virtual host info from a AMQP connection..
final AmqpProtocolDecoder h = new AmqpProtocolDecoder(this);
handler.handle(new ConnectionParameters());
}
Aggregations