/** * Build a {@link Send} response on {@link #authenticate()} failure. The actual response is sent out when * {@link #sendAuthenticationFailureResponse()} is called. */ private void buildResponseOnAuthenticateFailure(RequestContext context, AbstractResponse response) { authenticationFailureSend = context.buildResponse(response); }
public short apiVersion() { // Use v0 when serializing an unhandled ApiVersion response if (isUnsupportedApiVersionsRequest()) return 0; return header.apiVersion(); }
RequestContext context = new RequestContext(header, "0", InetAddress.getLocalHost(), KafkaPrincipal.ANONYMOUS, new ListenerName("ssl"), SecurityProtocol.SASL_SSL); assertEquals(0, context.apiVersion()); requestBuffer.flip(); RequestAndSize requestAndSize = context.parseRequest(requestBuffer); assertTrue(requestAndSize.request instanceof ApiVersionsRequest); ApiVersionsRequest request = (ApiVersionsRequest) requestAndSize.request; assertTrue(request.hasUnsupportedRequestVersion()); Send send = context.buildResponse(new ApiVersionsResponse(0, Errors.UNSUPPORTED_VERSION, Collections.<ApiVersionsResponse.ApiVersion>emptyList())); ByteBufferChannel channel = new ByteBufferChannel(256);
RequestContext requestContext = new RequestContext(header, connectionId, clientAddress(), KafkaPrincipal.ANONYMOUS, listenerName, securityProtocol); RequestAndSize requestAndSize = requestContext.parseRequest(requestBuffer); if (apiKey == ApiKeys.API_VERSIONS) handleApiVersionsRequest(requestContext, (ApiVersionsRequest) requestAndSize.request);
public Send buildResponse(AbstractResponse body) { ResponseHeader responseHeader = header.toResponseHeader(); return body.toSend(connectionId, responseHeader, apiVersion()); }
ApiKeys apiKey = header.apiKey(); short version = header.apiVersion(); RequestContext requestContext = new RequestContext(header, connectionId, clientAddress(), KafkaPrincipal.ANONYMOUS, listenerName, securityProtocol); RequestAndSize requestAndSize = requestContext.parseRequest(requestBuffer); if (apiKey != ApiKeys.SASL_AUTHENTICATE) { IllegalSaslStateException e = new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL authentication.");
private void sendKafkaResponse(RequestContext context, AbstractResponse response) throws IOException { sendKafkaResponse(context.buildResponse(response)); }
public RequestAndSize parseRequest(ByteBuffer buffer) { if (isUnsupportedApiVersionsRequest()) { // Unsupported ApiVersion requests are treated as v0 requests and are not parsed ApiVersionsRequest apiVersionsRequest = new ApiVersionsRequest((short) 0, header.apiVersion()); return new RequestAndSize(apiVersionsRequest, 0); } else { ApiKeys apiKey = header.apiKey(); try { short apiVersion = header.apiVersion(); Struct struct = apiKey.parseRequest(apiVersion, buffer); AbstractRequest body = AbstractRequest.parseRequest(apiKey, apiVersion, struct); return new RequestAndSize(body, struct.sizeOf()); } catch (Throwable ex) { throw new InvalidRequestException("Error getting request for apiKey: " + apiKey + ", apiVersion: " + header.apiVersion() + ", connectionId: " + connectionId + ", listenerName: " + listenerName + ", principal: " + principal, ex); } } }