21
21
import java .util .List ;
22
22
23
23
import io .netty .buffer .ByteBuf ;
24
+ import io .vertx .db2client .DB2Exception ;
24
25
25
26
public class DRDAConnectResponse extends DRDAResponse {
26
27
@@ -1141,8 +1142,7 @@ private void parseSECCHKRM() {
1141
1142
private void parseACCSECreply (int securityMechanism ) {
1142
1143
int peekCP = peekCodePoint ();
1143
1144
if (peekCP != CodePoint .ACCSECRD ) {
1144
- throw new IllegalStateException (String .format ("Expecting ACCSECRD codepoint (0x14AC) but got %04x" , peekCP ));
1145
- //parseAccessSecurityError(netConnection);
1145
+ parseAccessSecurityError ();
1146
1146
}
1147
1147
parseACCSECRD (securityMechanism );
1148
1148
@@ -1154,6 +1154,191 @@ private void parseACCSECreply(int securityMechanism) {
1154
1154
// }
1155
1155
}
1156
1156
1157
+ private void parseAccessSecurityError () {
1158
+ int peekCP = peekCodePoint ();
1159
+ switch (peekCP ) {
1160
+ case CodePoint .CMDCHKRM :
1161
+ parseCMDCHKRM ();
1162
+ break ;
1163
+ case CodePoint .RDBNFNRM :
1164
+ parseRDBNFNRM ();
1165
+ break ;
1166
+ case CodePoint .RDBAFLRM :
1167
+ parseRdbAccessFailed ();
1168
+ break ;
1169
+ default :
1170
+ parseCommonError (peekCP );
1171
+ }
1172
+ }
1173
+
1174
+ // RDB Not Found Reply Message indicates that the target
1175
+ // server cannot find the specified relational database.
1176
+ // PROTOCOL architects an SQLSTATE of 08004.
1177
+ //
1178
+ // Messages
1179
+ // SQLSTATE : 8004
1180
+ // The application server rejected establishment of the connection.
1181
+ // SQLCODE : -30061
1182
+ // The database alias or database name <name> was not found at the remote node.
1183
+ // The statement cannot be processed.
1184
+ //
1185
+ //
1186
+ // Returned from Server:
1187
+ // SVRCOD - required (8 - ERROR)
1188
+ // RDBNAM - required
1189
+ private void parseRDBNFNRM () {
1190
+ boolean svrcodReceived = false ;
1191
+ int svrcod = CodePoint .SVRCOD_INFO ;
1192
+ boolean rdbnamReceived = false ;
1193
+ String rdbnam = null ;
1194
+
1195
+ parseLengthAndMatchCodePoint (CodePoint .RDBNFNRM );
1196
+ pushLengthOnCollectionStack ();
1197
+ int peekCP = peekCodePoint ();
1198
+
1199
+ while (peekCP != END_OF_COLLECTION ) {
1200
+
1201
+ boolean foundInPass = false ;
1202
+
1203
+ if (peekCP == CodePoint .SVRCOD ) {
1204
+ foundInPass = true ;
1205
+ svrcodReceived = checkAndGetReceivedFlag (svrcodReceived );
1206
+ svrcod = parseSVRCOD (CodePoint .SVRCOD_ERROR , CodePoint .SVRCOD_ERROR );
1207
+ peekCP = peekCodePoint ();
1208
+ }
1209
+
1210
+ if (peekCP == CodePoint .RDBNAM ) {
1211
+ foundInPass = true ;
1212
+ rdbnamReceived = checkAndGetReceivedFlag (rdbnamReceived );
1213
+ rdbnam = parseRDBNAM (true );
1214
+ peekCP = peekCodePoint ();
1215
+ }
1216
+
1217
+ if (peekCP == CodePoint .SRVDGN ) {
1218
+ foundInPass = true ;
1219
+ String serverDiagnostics = parseSRVDGN ();
1220
+ // TODO: @AGG Log the server diagnostics here
1221
+ peekCP = peekCodePoint ();
1222
+ }
1223
+
1224
+ if (!foundInPass ) {
1225
+ throwUnknownCodepoint (peekCP );
1226
+ }
1227
+
1228
+ }
1229
+ popCollectionStack ();
1230
+ if (!svrcodReceived )
1231
+ throwMissingRequiredCodepoint ("SVRCOD" , CodePoint .SVRCOD );
1232
+ if (!rdbnamReceived )
1233
+ throwMissingRequiredCodepoint ("RDBNAM" , CodePoint .RDBNAM );
1234
+
1235
+ // netAgent_.setSvrcod(svrcod);
1236
+ throw new DB2Exception ("The requested database was not found: " + metadata .databaseName ,
1237
+ SqlCode .RDB_NOT_FOUND , SQLState .NET_DATABASE_NOT_FOUND );
1238
+ // agent_.accumulateChainBreakingReadExceptionAndThrow(new DisconnectException(agent_,
1239
+ // new ClientMessageId(SQLState.NET_DATABASE_NOT_FOUND),
1240
+ // netConnection.databaseName_));
1241
+ }
1242
+
1243
+ private void parseRdbAccessFailed () {
1244
+ parseRDBAFLRM ();
1245
+
1246
+ // an SQLCARD is returned if an RDBALFRM is returned.
1247
+ // this SQLCARD always follows the RDBALFRM.
1248
+ // TYPDEFNAM and TYPDEFOVR are MTLINC
1249
+
1250
+ if (peekCodePoint () == CodePoint .TYPDEFNAM ) {
1251
+ parseTYPDEFNAM ();
1252
+ parseTYPDEFOVR ();
1253
+ } else {
1254
+ parseTYPDEFOVR ();
1255
+ parseTYPDEFNAM ();
1256
+ }
1257
+
1258
+ NetSqlca netSqlca = parseSQLCARD (null );
1259
+
1260
+ //Check if the SQLCARD has null SQLException
1261
+ if (netSqlca .getSqlErrmc () == null ) {
1262
+ // netConnection.setConnectionNull(true);
1263
+ } else {
1264
+ NetSqlca .complete (netSqlca );
1265
+ }
1266
+ }
1267
+
1268
+ // RDB Access Failed Reply Message specifies that the relational
1269
+ // database failed the attempted connection.
1270
+ // An SQLCARD object must also be returned, following the
1271
+ // RDBAFLRM, to explain why the RDB failed the connection.
1272
+ // In addition, the target SQLAM instance is destroyed.
1273
+ // The SQLSTATE is returned in the SQLCARD.
1274
+ //
1275
+ // Messages
1276
+ // SQLSTATE : 58009
1277
+ // Execution failed due to a distribution protocol error that caused deallocation of the conversation.
1278
+ // SQLCODE : -30020
1279
+ // Execution failed because of a Distributed Protocol
1280
+ // Error that will affect the successful execution of subsequent
1281
+ // commands and SQL statements: Reason Code <reason-code>.
1282
+ // Some possible reason codes include:
1283
+ // 121C Indicates that the user is not authorized to perform the requested command.
1284
+ // 1232 The command could not be completed because of a permanent error.
1285
+ // In most cases, the server will be in the process of an abend.
1286
+ // 220A The target server has received an invalid data description.
1287
+ // If a user SQLDA is specified, ensure that the fields are
1288
+ // initialized correctly. Also, ensure that the length does not
1289
+ // exceed the maximum allowed length for the data type being used.
1290
+ //
1291
+ // The command or statement cannot be processed. The current
1292
+ // transaction is rolled back and the application is disconnected
1293
+ // from the remote database.
1294
+ //
1295
+ //
1296
+ // Returned from Server:
1297
+ // SVRCOD - required (8 - ERROR)
1298
+ // RDBNAM - required
1299
+ //
1300
+ private void parseRDBAFLRM () {
1301
+ boolean svrcodReceived = false ;
1302
+ int svrcod = CodePoint .SVRCOD_INFO ;
1303
+ boolean rdbnamReceived = false ;
1304
+ String rdbnam = null ;
1305
+
1306
+ parseLengthAndMatchCodePoint (CodePoint .RDBAFLRM );
1307
+ pushLengthOnCollectionStack ();
1308
+ int peekCP = peekCodePoint ();
1309
+
1310
+ while (peekCP != END_OF_COLLECTION ) {
1311
+
1312
+ boolean foundInPass = false ;
1313
+
1314
+ if (peekCP == CodePoint .SVRCOD ) {
1315
+ foundInPass = true ;
1316
+ svrcodReceived = checkAndGetReceivedFlag (svrcodReceived );
1317
+ svrcod = parseSVRCOD (CodePoint .SVRCOD_ERROR , CodePoint .SVRCOD_ERROR );
1318
+ peekCP = peekCodePoint ();
1319
+ }
1320
+
1321
+ if (peekCP == CodePoint .RDBNAM ) {
1322
+ foundInPass = true ;
1323
+ rdbnamReceived = checkAndGetReceivedFlag (rdbnamReceived );
1324
+ rdbnam = parseRDBNAM (true );
1325
+ peekCP = peekCodePoint ();
1326
+ }
1327
+
1328
+ if (!foundInPass ) {
1329
+ throwUnknownCodepoint (peekCP );
1330
+ }
1331
+
1332
+ }
1333
+ popCollectionStack ();
1334
+ if (!svrcodReceived )
1335
+ throwMissingRequiredCodepoint ("SVRCOD" , CodePoint .SVRCOD );
1336
+ if (!rdbnamReceived )
1337
+ throwMissingRequiredCodepoint ("RDBNAM" , CodePoint .RDBNAM );
1338
+
1339
+ // netAgent_.setSvrcod(svrcod);
1340
+ }
1341
+
1157
1342
// The Access Security Reply Data (ACSECRD) Collection Object contains
1158
1343
// the security information from a target server's security manager.
1159
1344
// this method returns the security check code received from the server
0 commit comments