Search in sources :

Example 1 with TerminateResponse

use of com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse in project pgadapter by GoogleCloudPlatform.

the class ConnectionHandler method handleError.

/**
 * Takes an Exception Object and relates its results to the user within the client.
 *
 * @param e The exception to be related.
 * @throws IOException if there is some issue in the sending of the error messages.
 */
private void handleError(DataOutputStream output, Exception e) throws Exception {
    logger.log(Level.WARNING, e, () -> String.format("Exception on connection handler with ID %s: %s", getName(), e));
    if (this.status == ConnectionStatus.TERMINATED) {
        new ErrorResponse(output, e, ErrorResponse.State.InternalError, Severity.FATAL).send();
        new TerminateResponse(output).send();
    } else if (this.status == ConnectionStatus.COPY_IN) {
        new ErrorResponse(output, e, ErrorResponse.State.InternalError).send();
    } else {
        this.status = ConnectionStatus.IDLE;
        new ErrorResponse(output, e, ErrorResponse.State.InternalError).send();
        new ReadyResponse(output, ReadyResponse.Status.IDLE).send();
    }
}
Also used : TerminateResponse(com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse) ReadyResponse(com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse) ErrorResponse(com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse)

Example 2 with TerminateResponse

use of com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse in project pgadapter by GoogleCloudPlatform.

the class PasswordMessage method sendPayload.

protected void sendPayload() throws Exception {
    if (useAuthentication() && !checkCredentials(this.username, this.password)) {
        new ErrorResponse(this.outputStream, new Exception("Could not Authenticate User"), State.InternalError).send();
        new TerminateResponse(this.outputStream).send();
    } else {
        BootstrapMessage.sendStartupMessage(this.outputStream, this.connection.getConnectionId(), this.connection.getSecret(), this.connection.getServer().getOptions());
    }
}
Also used : TerminateResponse(com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse) ErrorResponse(com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse)

Aggregations

ErrorResponse (com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse)2 TerminateResponse (com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse)2 ReadyResponse (com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse)1