This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac51974fa0 Refactor PostgreSQLDialectExceptionMapper (#20631)
9ac51974fa0 is described below
commit 9ac51974fa02b42bd029952b9096075ef61f0299
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 29 16:35:58 2022 +0800
Refactor PostgreSQLDialectExceptionMapper (#20631)
---
...InvalidAuthorizationSpecificationException.java | 6 ++---
.../mapper/PostgreSQLDialectExceptionMapper.java | 15 ++++++++-----
.../vendor/PostgreSQLServerErrorMessage.java | 26 +++++++++++++++-------
.../frontend/exception/ExpectedExceptions.java | 6 ++---
.../frontend/exception/ExpectedExceptionsTest.java | 10 ++++-----
.../OpenGaussAuthenticationEngine.java | 2 +-
.../opengauss/err/OpenGaussErrorPacketFactory.java | 4 ----
.../OpenGaussAuthenticationEngineTest.java | 2 +-
.../PostgreSQLAuthenticationEngine.java | 2 +-
.../postgresql/err/PostgreSQLErrPacketFactory.java | 11 ++++-----
.../PostgreSQLAuthenticationEngineTest.java | 2 +-
11 files changed, 45 insertions(+), 41 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidAuthorizationSpecificationException.java
similarity index 85%
copy from
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
copy to
shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidAuthorizationSpecificationException.java
index dd3d4408cb8..fbcfcf53908 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
+++
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/exception/InvalidAuthorizationSpecificationException.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception;
+package org.apache.shardingsphere.dialect.postgresql.exception;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.proxy.frontend.exception.FrontendException;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
/**
* Invalid authorization specification exception.
*/
@RequiredArgsConstructor
@Getter
-public final class InvalidAuthorizationSpecificationException extends
FrontendException {
+public final class InvalidAuthorizationSpecificationException extends
SQLDialectException {
private static final long serialVersionUID = -7169979989631579431L;
diff --git
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
index dca1f089778..a8ea4e1e1a6 100644
---
a/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
+++
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/mapper/PostgreSQLDialectExceptionMapper.java
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.dialect.postgresql.mapper;
-import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
-import
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
-import
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import
org.apache.shardingsphere.dialect.exception.connection.TooManyConnectionsException;
import
org.apache.shardingsphere.dialect.exception.data.InsertColumnsAndValuesMismatchedException;
import
org.apache.shardingsphere.dialect.exception.data.InvalidParameterValueException;
-import
org.apache.shardingsphere.dialect.exception.connection.TooManyConnectionsException;
import
org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException;
-import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
+import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
+import
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
+import
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLServerErrorMessage;
+import
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
@@ -54,6 +56,9 @@ public final class PostgreSQLDialectExceptionMapper
implements SQLDialectExcepti
if (sqlDialectException instanceof TooManyConnectionsException) {
return new
PSQLException(PostgreSQLVendorError.DATA_SOURCE_REJECTED_CONNECTION_ATTEMPT.getReason(),
null);
}
+ if (sqlDialectException instanceof
InvalidAuthorizationSpecificationException) {
+ return new PSQLException(new PostgreSQLServerErrorMessage("FATAL",
PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION,
sqlDialectException.getMessage()).toServerErrorMessage());
+ }
return new PSQLException(sqlDialectException.getMessage(),
PSQLState.UNEXPECTED_ERROR);
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLServerErrorMessage.java
similarity index 55%
rename from
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
rename to
shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLServerErrorMessage.java
index dd3d4408cb8..7dc69baeb15 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/exception/InvalidAuthorizationSpecificationException.java
+++
b/shardingsphere-dialect-exception/shardingsphere-postgresql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/postgresql/vendor/PostgreSQLServerErrorMessage.java
@@ -15,20 +15,30 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception;
+package org.apache.shardingsphere.dialect.postgresql.vendor;
-import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.proxy.frontend.exception.FrontendException;
+import org.apache.shardingsphere.infra.util.exception.sql.vendor.VendorError;
+import org.postgresql.util.ServerErrorMessage;
/**
- * Invalid authorization specification exception.
+ * PostgreSQL server error message.
*/
@RequiredArgsConstructor
-@Getter
-public final class InvalidAuthorizationSpecificationException extends
FrontendException {
+public final class PostgreSQLServerErrorMessage {
- private static final long serialVersionUID = -7169979989631579431L;
+ private final String severity;
- private final String message;
+ private final VendorError vendorError;
+
+ private final String reason;
+
+ /**
+ * To server error message.
+ *
+ * @return server error message
+ */
+ public ServerErrorMessage toServerErrorMessage() {
+ return new ServerErrorMessage("S" + severity + "\0" + "V" + severity +
"\0" + "C" + vendorError.getSqlState().getValue() + "\0" + "M" + reason);
+ }
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
index 82d3a744f2c..31306fe9131 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptions.java
@@ -19,10 +19,9 @@ package org.apache.shardingsphere.proxy.frontend.exception;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
import org.apache.shardingsphere.infra.util.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.util.exception.ShardingSphereInsideException;
-import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
import java.util.Collection;
import java.util.HashSet;
@@ -38,8 +37,7 @@ public final class ExpectedExceptions {
static {
EXCEPTIONS.add(ShardingSphereException.class);
EXCEPTIONS.add(ShardingSphereInsideException.class);
- EXCEPTIONS.add(ShardingSphereConfigurationException.class);
- EXCEPTIONS.add(SQLParsingException.class);
+ EXCEPTIONS.add(ShardingSphereSQLException.class);
}
/**
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
index df121f8a448..444e96b8776 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/exception/ExpectedExceptionsTest.java
@@ -17,11 +17,10 @@
package org.apache.shardingsphere.proxy.frontend.exception;
-import
org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException;
-import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
import org.apache.shardingsphere.infra.util.exception.ShardingSphereException;
import
org.apache.shardingsphere.infra.util.exception.ShardingSphereInsideException;
-import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
@@ -33,9 +32,8 @@ public final class ExpectedExceptionsTest {
public void assertIsExpected() {
assertTrue(ExpectedExceptions.isExpected(ShardingSphereException.class));
assertTrue(ExpectedExceptions.isExpected(ShardingSphereInsideException.class));
-
assertTrue(ExpectedExceptions.isExpected(ShardingSphereConfigurationException.class));
- assertTrue(ExpectedExceptions.isExpected(SQLParsingException.class));
-
assertTrue(ExpectedExceptions.isExpected(NoDatabaseSelectedException.class));
+ assertTrue(ExpectedExceptions.isExpected(SQLDialectException.class));
+
assertTrue(ExpectedExceptions.isExpected(ShardingSphereSQLException.class));
}
@Test
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
index 9e16d1ac954..72f94287028 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
@@ -38,7 +38,7 @@ import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationRes
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;
import
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.PostgreSQLLoginResult;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
+import
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactory.java
index 1f5a9d462e2..ded9c122f4d 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactory.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.dialect.exception.SQLDialectException;
import
org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapperFactory;
import
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
@@ -82,9 +81,6 @@ public final class OpenGaussErrorPacketFactory {
if (cause instanceof ShardingSphereSQLException) {
return createErrorResponsePacket(((ShardingSphereSQLException)
cause).toSQLException());
}
- if (cause instanceof InvalidAuthorizationSpecificationException) {
- return new
OpenGaussErrorResponsePacket(PostgreSQLMessageSeverityLevel.FATAL,
PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION.getSqlState().getValue(),
cause.getMessage());
- }
if (cause instanceof PostgreSQLProtocolViolationException) {
return new
OpenGaussErrorResponsePacket(PostgreSQLMessageSeverityLevel.FATAL,
PostgreSQLVendorError.PROTOCOL_VIOLATION.getSqlState().getValue(),
String.format("expected %s response, got message type %s",
((PostgreSQLProtocolViolationException) cause).getExpectedMessageType(),
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
index 31883d1b652..3f83aa8a535 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java
@@ -43,7 +43,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
import org.apache.shardingsphere.proxy.frontend.opengauss.ProxyContextRestorer;
import
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.fixture.OpenGaussAuthenticationAlgorithm;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
+import
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
import org.junit.Before;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
index c037ffb2a3f..2a9e06bd304 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
@@ -42,7 +42,7 @@ import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationRes
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;
import
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLAuthenticator;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
+import
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
index ec0d4a444b5..e93fee466b9 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
@@ -26,7 +26,6 @@ import
org.apache.shardingsphere.dialect.SQLExceptionTransformEngine;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
import
org.apache.shardingsphere.dialect.postgresql.vendor.PostgreSQLVendorError;
import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
import org.postgresql.util.PSQLException;
@@ -50,14 +49,10 @@ public final class PostgreSQLErrPacketFactory {
if (cause instanceof PSQLException && null != ((PSQLException)
cause).getServerErrorMessage()) {
return createErrorResponsePacket(((PSQLException)
cause).getServerErrorMessage());
}
- if (cause instanceof InvalidAuthorizationSpecificationException) {
- return
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.FATAL,
PostgreSQLVendorError.INVALID_AUTHORIZATION_SPECIFICATION,
cause.getMessage()).build();
- }
if (cause instanceof PostgreSQLProtocolViolationException) {
return
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.FATAL,
PostgreSQLVendorError.PROTOCOL_VIOLATION,
String.format("expected %s response, got message type %s",
((PostgreSQLProtocolViolationException) cause).getExpectedMessageType(),
- ((PostgreSQLProtocolViolationException)
cause).getActualMessageType()))
- .build();
+ ((PostgreSQLProtocolViolationException)
cause).getActualMessageType())).build();
}
if (cause instanceof PostgreSQLAuthenticationException) {
return
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.FATAL,
((PostgreSQLAuthenticationException) cause).getVendorError(),
cause.getMessage()).build();
@@ -78,7 +73,9 @@ public final class PostgreSQLErrPacketFactory {
}
private static PostgreSQLErrorResponsePacket
createErrorResponsePacket(final SQLException cause) {
- // TODO consider what severity to use
+ if (cause instanceof PSQLException && null != ((PSQLException)
cause).getServerErrorMessage()) {
+ return createErrorResponsePacket(((PSQLException)
cause).getServerErrorMessage());
+ }
String sqlState = Strings.isNullOrEmpty(cause.getSQLState()) ?
PostgreSQLVendorError.SYSTEM_ERROR.getSqlState().getValue() :
cause.getSQLState();
String message = Strings.isNullOrEmpty(cause.getMessage()) ?
cause.toString() : cause.getMessage();
return
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.ERROR,
sqlState, message).build();
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
index 01778a2650c..e5a0247e106 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java
@@ -44,7 +44,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
import
org.apache.shardingsphere.proxy.frontend.postgresql.ProxyContextRestorer;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.PostgreSQLMD5PasswordAuthenticator;
-import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
+import
org.apache.shardingsphere.dialect.postgresql.exception.InvalidAuthorizationSpecificationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import
org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
import org.junit.Before;