1 21 22 32 33 package org.apache.derby.impl.drda; 34 import java.util.Hashtable ; 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 37 class DRDAProtocolException extends Exception 38 { 39 40 43 44 protected static final int NO_ASSOC_ERRCD = 0; 45 protected static final int NO_CODPNT_ARG = 0; 46 47 48 private DRDAConnThread agent; 49 50 private int correlationID; 52 53 private byte[] crrtkn; 55 56 private int codpntArg; 58 59 private DRDAProtocolExceptionInfo exceptionInfo; 60 61 private int errorCodePoint; 63 64 private int svrcod; 66 67 private int errcd; 69 70 private String messageid; 72 73 private String rdbnam; 75 76 private String srvdgn; 78 79 private Object [] messageArgs; 81 82 private String msg; 85 86 private static Hashtable errorInfoTable; 87 88 protected static String DRDA_Proto_CMDCHKRM= "DRDA_Proto_CMDCHKRM"; 89 protected static String DRDA_Proto_CMDNSPRM= "DRDA_Proto_CMDNSPRM"; 90 protected static String DRDA_Proto_DTAMCHRM= "DRDA_Proto_DTAMCHRM"; 91 92 protected static String DRDA_Proto_OBJNSPRM = "DRDA_Proto_OBJNSPRM"; 93 protected static String DRDA_Proto_PKGBNARM= "DRDA_Proto_PKGBNARM"; 94 protected static String DRDA_Proto_PRCCNVRM= "DRDA_Proto_PRCCNVRM"; 95 protected static String DRDA_Proto_PRMNSRM = "DRDA_Proto_PRMNSPRM"; 96 97 protected static String DRDA_Proto_SYNTAXRM= "DRDA_Proto_SYNTAXRM"; 98 protected static String DRDA_Proto_VALNSPRM= "DRDA_Proto_VALNSPRM"; 99 protected static String DRDA_Proto_MGRLVLRM= "DRDA_Proto_MGRLVLRM"; 100 protected static String DRDA_Proto_RDBNFNRM= "DRDA_Proto_RDBNFNRM"; 101 102 protected static String DRDA_Disconnect= "DRDA_Disconnect"; 103 protected static String DRDA_AgentError= "DRDA_AgentError"; 104 105 static { 106 110 111 errorInfoTable = new Hashtable (); 112 113 errorInfoTable.put( 114 DRDA_Proto_CMDCHKRM, 115 new DRDAProtocolExceptionInfo( 116 CodePoint.CMDCHKRM, 117 CodePoint.SVRCOD_ERROR, 118 NO_ASSOC_ERRCD, 119 false)); 120 121 errorInfoTable.put( 122 DRDA_Proto_CMDNSPRM, 123 new DRDAProtocolExceptionInfo( 124 CodePoint.CMDNSPRM, 125 CodePoint.SVRCOD_ERROR, 126 NO_ASSOC_ERRCD, 127 true)); 128 errorInfoTable.put( 129 DRDA_Proto_DTAMCHRM, 130 new DRDAProtocolExceptionInfo( 131 CodePoint.DTAMCHRM, 132 CodePoint.SVRCOD_ERROR, 133 NO_ASSOC_ERRCD, 134 false)); 135 errorInfoTable.put( 136 DRDA_Proto_OBJNSPRM, 137 new DRDAProtocolExceptionInfo( 138 CodePoint.OBJNSPRM, 139 CodePoint.SVRCOD_ERROR, 140 NO_ASSOC_ERRCD, 141 true)); 142 143 errorInfoTable.put( 144 DRDA_Proto_PKGBNARM, 145 new DRDAProtocolExceptionInfo( 146 CodePoint.PKGBNARM, 147 CodePoint.SVRCOD_ERROR, 148 NO_ASSOC_ERRCD, 149 false)); 150 151 errorInfoTable.put(DRDA_Proto_PRCCNVRM, 152 new DRDAProtocolExceptionInfo( 153 CodePoint.PRCCNVRM, 154 CodePoint.SVRCOD_ERROR, 155 CodePoint.PRCCNVCD, 156 false)); 157 158 errorInfoTable.put(DRDA_Proto_SYNTAXRM, 159 new DRDAProtocolExceptionInfo( 160 CodePoint.SYNTAXRM, 161 CodePoint.SVRCOD_ERROR, 162 CodePoint.SYNERRCD, 163 true)); 164 165 errorInfoTable.put(DRDA_Proto_VALNSPRM, 166 new DRDAProtocolExceptionInfo( 167 CodePoint.VALNSPRM, 168 CodePoint.SVRCOD_ERROR, 169 NO_ASSOC_ERRCD, 170 true)); 171 172 errorInfoTable.put(DRDA_Proto_MGRLVLRM, 173 new DRDAProtocolExceptionInfo( 174 CodePoint.MGRLVLRM, 175 CodePoint.SVRCOD_ERROR, 176 NO_ASSOC_ERRCD, 177 false)); 178 179 errorInfoTable.put(DRDA_Proto_RDBNFNRM, 180 new DRDAProtocolExceptionInfo( 181 CodePoint.RDBNFNRM, 182 CodePoint.SVRCOD_ERROR, 183 NO_ASSOC_ERRCD, 184 false)); 185 186 187 errorInfoTable.put(DRDA_Disconnect, 188 new DRDAProtocolExceptionInfo( 189 0, 190 0, 191 NO_ASSOC_ERRCD, 192 false)); 193 194 errorInfoTable.put(DRDA_AgentError, 198 new DRDAProtocolExceptionInfo( 199 CodePoint.AGNPRMRM, 200 CodePoint.SVRCOD_PRMDMG, 201 NO_ASSOC_ERRCD, 202 false)); 203 204 } 205 206 207 220 221 DRDAProtocolException(String msgid, 222 DRDAConnThread agent, 223 int cpArg, 224 int errCdArg, Object []args) 225 226 { 227 228 boolean agentError = false; 229 230 exceptionInfo = 231 (DRDAProtocolExceptionInfo) errorInfoTable.get(msgid); 232 233 if (agent != null) 234 { 235 this.correlationID = agent.getCorrelationID(); 236 this.crrtkn = agent.getCrrtkn(); 237 } 238 239 this.codpntArg= cpArg; 240 this.errorCodePoint = exceptionInfo.errorCodePoint; 241 this.errcd = errCdArg; 242 this.messageid = msgid; 243 244 if (msgid.equals(DRDA_AgentError)) 245 { 246 this.svrcod = ((Integer )args[0]).intValue(); 247 this.rdbnam = (String )args[1]; 248 String srvdgn = (String )args[2]; 250 msg = "Execution failed because of Permanent Agent Error: SVRCOD = " + 251 java.lang.Integer.toHexString(this.svrcod) + 252 "; RDBNAM = "+ rdbnam +"; diagnostic msg = "+ srvdgn; 253 agentError = true; 254 } 255 else if (msgid.equals(DRDA_Proto_RDBNFNRM)) 256 { 257 this.svrcod = exceptionInfo.svrcod; 258 this.rdbnam = (String )args[0]; 259 msg = "Execution failed because of Distributed Protocol Error: " 260 + messageid + 261 "; RDBNAM = "+ rdbnam; 262 } 263 else 264 { 265 this.svrcod = exceptionInfo.svrcod; 266 msg = "Execution failed because of a Distributed Protocol Error: " 267 + messageid + 268 "; CODPNT arg = " + java.lang.Integer.toHexString(cpArg) + 269 "; Error Code Value = " + java.lang.Integer.toHexString(errCdArg); 270 } 271 272 273 if (!agentError && args != null) 274 { 275 messageArgs = args; 276 for (int i = 0; i < args.length; i++) 277 { 278 if (msgid.equals(DRDA_Proto_MGRLVLRM)) 280 msg += "," + 281 java.lang.Integer.toHexString(((Integer )args[i]).intValue()); 282 else 283 msg += "," + args[i]; 284 285 } 286 } 287 288 289 if (!isDisconnectException()) 292 { 293 DRDAConnThread.println2Log(agent.getDbName(), 294 agent.getSession().drdaID, 295 msg); 296 NetworkServerControlImpl s = agent.getServer(); 297 s.consoleExceptionPrintTrace(this); 298 } 299 } 300 301 DRDAProtocolException(String msgid, 303 DRDAConnThread agent, 304 int cpArg, 305 int errCdArg) 306 { 307 this(msgid,agent, cpArg, errCdArg, (Object []) null); 308 } 309 310 311 protected static DRDAProtocolException newDisconnectException(DRDAConnThread 312 agent,Object [] args) 313 { 314 return new DRDAProtocolException(DRDA_Disconnect, 315 agent, 316 NO_CODPNT_ARG, 317 NO_ASSOC_ERRCD, 318 args); 319 320 } 321 322 protected static DRDAProtocolException newAgentError(DRDAConnThread agent, 323 int svrcod, String rdbnam, String srvdgn) 324 { 325 if ( SanityManager.DEBUG ) 326 agent.trace("agentError in " + agent); 327 Object [] oa = {new Integer (svrcod), rdbnam, srvdgn}; 328 return new DRDAProtocolException(DRDA_AgentError, 329 agent, 330 NO_CODPNT_ARG, 331 NO_ASSOC_ERRCD, 332 oa); 333 } 334 335 protected final boolean isDisconnectException() 336 { 337 return (errorCodePoint == 0); 338 } 339 340 347 348 protected void write(DDMWriter writer) 349 { 350 writer.createDssReply(); 352 writer.startDdm(errorCodePoint); 353 writer.writeScalar2Bytes(CodePoint.SVRCOD,svrcod); 354 if (exceptionInfo.sendsCodpntArg) 355 writer.writeScalar2Bytes(CodePoint.CODPNT,codpntArg); 356 if (exceptionInfo.errCdCodePoint != NO_ASSOC_ERRCD) 357 writer.writeScalar1Byte(exceptionInfo.errCdCodePoint, 358 errcd); 359 if (rdbnam != null && agent != null) 360 { 361 try { 362 agent.writeRDBNAM(rdbnam); 363 } catch (DRDAProtocolException e) {} } 365 if (errorCodePoint == CodePoint.MGRLVLRM) 367 { 368 writer.startDdm(CodePoint.MGRLVLLS); 369 for (int i = 0; i < messageArgs.length ; i += 2) 370 { 371 writer.writeNetworkShort(((Integer )messageArgs[i]).intValue()); 372 writer.writeNetworkShort(((Integer )messageArgs[i+1]).intValue()); 373 } 374 writer.endDdm(); 375 } 376 writer.endDdmAndDss(); 377 } 378 379 383 public String getMessage() 384 { 385 return msg; 386 } 387 } 388 389 390 391 392 393 394 | Popular Tags |