in src/main/java/org/apache/cassandra/sidecar/routes/AbstractHandler.java [108:155]
protected abstract void handleInternal(RoutingContext context,
HttpServerRequest httpRequest,
String host,
SocketAddress remoteAddress,
T request);
/**
* Returns the host from the path if the requests contains the {@code /instance/} path parameter,
* otherwise it returns the host parsed from the request.
*
* @param context the routing context
* @return the host for the routing context
* @throws HttpException when the {@code /instance/} path parameter is {@code null}
*/
public String host(RoutingContext context)
{
if (context.request().params().contains(INSTANCE_ID))
{
String instanceIdParam = context.request().getParam(INSTANCE_ID);
if (instanceIdParam == null)
{
throw new HttpException(HttpResponseStatus.BAD_REQUEST.code(),
"InstanceId query parameter must be provided");
}
InstanceMetadata instance;
try
{
int instanceId = Integer.parseInt(instanceIdParam);
instance = metadataFetcher.instance(instanceId);
}
catch (NumberFormatException ex)
{
throw new HttpException(HttpResponseStatus.BAD_REQUEST.code(),
"InstanceId query parameter must be a valid integer");
}
catch (NoSuchElementException | IllegalStateException ex)
{
throw new HttpException(HttpResponseStatus.NOT_FOUND.code(), ex.getMessage());
}
return instance.host();
}
else
{
return extractHostAddressWithoutPort(context.request().host());
}
}