use of com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse in project pgadapter by GoogleCloudPlatform.
the class CopyFailMessage method sendPayload.
@Override
protected void sendPayload() throws Exception {
// If backend error occurred during copy-in mode, drop any subsequent CopyFail messages.
if (this.statement != null) {
MutationWriter mutationWriter = this.statement.getMutationWriter();
mutationWriter.rollback();
mutationWriter.closeErrorFile();
statement.close();
if (!statement.hasException(0)) {
new ErrorResponse(this.outputStream, new Exception(this.errorMessage), State.IOError).send();
}
}
this.connection.setStatus(ConnectionStatus.IDLE);
this.connection.removeActiveStatement(this.statement);
new ReadyResponse(this.outputStream, ReadyResponse.Status.IDLE).send();
}
use of com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse in project pgadapter by GoogleCloudPlatform.
the class ProxyServer method handleConnectionError.
/**
* Sends a message to the client that the connection could not be established.
*
* @param exception The exception that caused the connection request to fail.
* @param socket The socket that was created for the connection.
*/
private void handleConnectionError(SpannerException exception, Socket socket) {
logger.log(Level.SEVERE, exception, () -> String.format("Something went wrong in establishing a Spanner connection: %s", exception.getMessage()));
try {
DataOutputStream output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
new ErrorResponse(output, exception, ErrorResponse.State.ConnectionException, Severity.FATAL).send();
output.flush();
} catch (Exception e) {
logger.log(Level.WARNING, e, () -> String.format("Failed to send fatal error message to client: %s", e.getMessage()));
}
}
use of com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse 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();
}
}
use of com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse in project pgadapter by GoogleCloudPlatform.
the class ControlMessage method handleError.
/**
* Takes an Exception Object and relates its results to the user within the client.
*
* @param e The exception to be related.
* @throws Exception if there is some issue in the sending of the error messages.
*/
protected void handleError(Exception e) throws Exception {
new ErrorResponse(this.outputStream, e, State.RaiseException).send(false);
if (connection.getSpannerConnection().isInTransaction()) {
connection.getSpannerConnection().rollbackAsync();
connection.setStatus(ConnectionStatus.TRANSACTION_ABORTED);
}
this.outputStream.flush();
}
use of com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse 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());
}
}
Aggregations