1 7 8 package com.sun.corba.se.impl.protocol.giopmsgheaders; 9 10 import java.io.IOException ; 11 import java.lang.Class ; 12 import java.lang.reflect.Constructor ; 13 import java.nio.ByteBuffer ; 14 import java.util.Iterator ; 15 16 import org.omg.CORBA.CompletionStatus ; 17 import org.omg.CORBA.INTERNAL ; 18 import org.omg.CORBA.MARSHAL ; 19 import org.omg.CORBA.Principal ; 20 import org.omg.CORBA.SystemException ; 21 import org.omg.IOP.TaggedProfile ; 22 23 import com.sun.corba.se.pept.transport.ByteBufferPool; 24 25 import com.sun.corba.se.spi.ior.ObjectKey; 26 import com.sun.corba.se.spi.ior.ObjectId; 27 import com.sun.corba.se.spi.ior.IOR; 28 import com.sun.corba.se.spi.ior.ObjectKeyFactory; 29 import com.sun.corba.se.spi.ior.iiop.IIOPProfile; 30 import com.sun.corba.se.spi.ior.iiop.IIOPFactories; 31 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; 32 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 33 import com.sun.corba.se.spi.ior.iiop.RequestPartitioningComponent; 34 import com.sun.corba.se.spi.logging.CORBALogDomains ; 35 import com.sun.corba.se.spi.orb.ORB; 36 import com.sun.corba.se.spi.transport.CorbaConnection; 37 import com.sun.corba.se.spi.transport.ReadTimeouts; 38 39 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 40 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo; 41 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0; 42 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 43 import com.sun.corba.se.impl.orbutil.ORBUtility; 44 import com.sun.corba.se.impl.orbutil.ORBConstants; 45 import com.sun.corba.se.impl.orbutil.ORBClassLoader; 46 import com.sun.corba.se.impl.protocol.AddressingDispositionException; 47 48 56 57 public abstract class MessageBase implements Message{ 58 59 public byte[] giopHeader; 62 private ByteBuffer byteBuffer; 63 private int threadPoolToUse; 64 65 byte encodingVersion = (byte) Message.CDR_ENC_VERSION; 68 69 private static ORBUtilSystemException wrapper = 70 ORBUtilSystemException.get( CORBALogDomains.RPC_PROTOCOL ) ; 71 72 74 public static String typeToString(int type) 75 { 76 return typeToString((byte)type); 77 } 78 79 public static String typeToString(byte type) 80 { 81 String result = type + "/"; 82 switch (type) { 83 case GIOPRequest : result += "GIOPRequest"; break; 84 case GIOPReply : result += "GIOPReply"; break; 85 case GIOPCancelRequest : result += "GIOPCancelRequest"; break; 86 case GIOPLocateRequest : result += "GIOPLocateRequest"; break; 87 case GIOPLocateReply : result += "GIOPLocateReply"; break; 88 case GIOPCloseConnection : result += "GIOPCloseConnection"; break; 89 case GIOPMessageError : result += "GIOPMessageError"; break; 90 case GIOPFragment : result += "GIOPFragment"; break; 91 default : result += "Unknown"; break; 92 } 93 return result; 94 } 95 96 public static MessageBase readGIOPMessage(ORB orb, CorbaConnection connection) 97 { 98 MessageBase msg = readGIOPHeader(orb, connection); 99 msg = (MessageBase)readGIOPBody(orb, connection, (Message)msg); 100 return msg; 101 } 102 103 public static MessageBase readGIOPHeader(ORB orb, CorbaConnection connection) 104 { 105 MessageBase msg = null; 106 ReadTimeouts readTimeouts = 107 orb.getORBData().getTransportTCPReadTimeouts(); 108 109 ByteBuffer buf = null; 110 111 try { 112 buf = connection.read(GIOPMessageHeaderLength, 113 0, GIOPMessageHeaderLength, 114 readTimeouts.get_max_giop_header_time_to_wait()); 115 } catch (IOException e) { 116 throw wrapper.ioexceptionWhenReadingConnection(e); 117 } 118 119 if (orb.giopDebugFlag) { 120 dprint(".readGIOPHeader: " + typeToString(buf.get(7))); 125 dprint(".readGIOPHeader: GIOP header is: "); 126 ByteBuffer viewBuffer = buf.asReadOnlyBuffer(); 127 viewBuffer.position(0).limit(GIOPMessageHeaderLength); 128 ByteBufferWithInfo bbwi = new ByteBufferWithInfo(orb,viewBuffer); 129 bbwi.buflen = GIOPMessageHeaderLength; 130 CDRInputStream_1_0.printBuffer(bbwi); 131 } 132 133 135 144 145 int b1, b2, b3, b4; 146 147 b1 = (buf.get(0) << 24) & 0xFF000000; 148 b2 = (buf.get(1) << 16) & 0x00FF0000; 149 b3 = (buf.get(2) << 8) & 0x0000FF00; 150 b4 = (buf.get(3) << 0) & 0x000000FF; 151 int magic = (b1 | b2 | b3 | b4); 152 153 if (magic != GIOPBigMagic) { 154 throw wrapper.giopMagicError( CompletionStatus.COMPLETED_MAYBE); 157 } 158 159 byte requestEncodingVersion = Message.CDR_ENC_VERSION; 163 if ((buf.get(4) == 0x0D) && 164 (buf.get(5) <= Message.JAVA_ENC_VERSION) && 165 (buf.get(5) > Message.CDR_ENC_VERSION) && 166 orb.getORBData().isJavaSerializationEnabled()) { 167 requestEncodingVersion = buf.get(5); 170 buf.put(4, (byte) 0x01); 171 buf.put(5, (byte) 0x02); 172 } 173 174 GIOPVersion orbVersion = orb.getORBData().getGIOPVersion(); 175 176 if (orb.giopDebugFlag) { 177 dprint(".readGIOPHeader: Message GIOP version: " 178 + buf.get(4) + '.' + buf.get(5)); 179 dprint(".readGIOPHeader: ORB Max GIOP Version: " 180 + orbVersion); 181 } 182 183 if ( (buf.get(4) > orbVersion.getMajor()) || 184 ( (buf.get(4) == orbVersion.getMajor()) && (buf.get(5) > orbVersion.getMinor()) ) 185 ) { 186 191 194 if ( buf.get(7) != GIOPMessageError ) { 197 throw wrapper.giopVersionError( CompletionStatus.COMPLETED_MAYBE); 198 } 199 } 200 201 AreFragmentsAllowed(buf.get(4), buf.get(5), buf.get(6), buf.get(7)); 202 203 205 switch (buf.get(7)) { 206 207 case GIOPRequest: 208 if (orb.giopDebugFlag) { 209 dprint(".readGIOPHeader: creating RequestMessage"); 210 } 211 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new RequestMessage_1_0(orb); 214 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new RequestMessage_1_1(orb); 216 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new RequestMessage_1_2(orb); 218 } else { 219 throw wrapper.giopVersionError( 220 CompletionStatus.COMPLETED_MAYBE); 221 } 222 break; 223 224 case GIOPLocateRequest: 225 if (orb.giopDebugFlag) { 226 dprint(".readGIOPHeader: creating LocateRequestMessage"); 227 } 228 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new LocateRequestMessage_1_0(orb); 231 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new LocateRequestMessage_1_1(orb); 233 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new LocateRequestMessage_1_2(orb); 235 } else { 236 throw wrapper.giopVersionError( 237 CompletionStatus.COMPLETED_MAYBE); 238 } 239 break; 240 241 case GIOPCancelRequest: 242 if (orb.giopDebugFlag) { 243 dprint(".readGIOPHeader: creating CancelRequestMessage"); 244 } 245 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new CancelRequestMessage_1_0(); 248 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new CancelRequestMessage_1_1(); 250 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new CancelRequestMessage_1_2(); 252 } else { 253 throw wrapper.giopVersionError( 254 CompletionStatus.COMPLETED_MAYBE); 255 } 256 break; 257 258 case GIOPReply: 259 if (orb.giopDebugFlag) { 260 dprint(".readGIOPHeader: creating ReplyMessage"); 261 } 262 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new ReplyMessage_1_0(orb); 265 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new ReplyMessage_1_1(orb); 267 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new ReplyMessage_1_2(orb); 269 } else { 270 throw wrapper.giopVersionError( 271 CompletionStatus.COMPLETED_MAYBE); 272 } 273 break; 274 275 case GIOPLocateReply: 276 if (orb.giopDebugFlag) { 277 dprint(".readGIOPHeader: creating LocateReplyMessage"); 278 } 279 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new LocateReplyMessage_1_0(orb); 282 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new LocateReplyMessage_1_1(orb); 284 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new LocateReplyMessage_1_2(orb); 286 } else { 287 throw wrapper.giopVersionError( 288 CompletionStatus.COMPLETED_MAYBE); 289 } 290 break; 291 292 case GIOPCloseConnection: 293 case GIOPMessageError: 294 if (orb.giopDebugFlag) { 295 dprint(".readGIOPHeader: creating Message for CloseConnection or MessageError"); 296 } 297 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { msg = new Message_1_0(); 304 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new Message_1_1(); 306 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new Message_1_1(); 308 } else { 309 throw wrapper.giopVersionError( 310 CompletionStatus.COMPLETED_MAYBE); 311 } 312 break; 313 314 case GIOPFragment: 315 if (orb.giopDebugFlag) { 316 dprint(".readGIOPHeader: creating FragmentMessage"); 317 } 318 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x01) ) { msg = new FragmentMessage_1_1(); 323 } else if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x02) ) { msg = new FragmentMessage_1_2(); 325 } else { 326 throw wrapper.giopVersionError( 327 CompletionStatus.COMPLETED_MAYBE); 328 } 329 break; 330 331 default: 332 if (orb.giopDebugFlag) 333 dprint(".readGIOPHeader: UNKNOWN MESSAGE TYPE: " 334 + buf.get(7)); 335 throw wrapper.giopVersionError( 338 CompletionStatus.COMPLETED_MAYBE); 339 } 340 341 345 if ( (buf.get(4) == 0x01) && (buf.get(5) == 0x00) ) { Message_1_0 msg10 = (Message_1_0) msg; 347 msg10.magic = magic; 348 msg10.GIOP_version = new GIOPVersion(buf.get(4), buf.get(5)); 349 msg10.byte_order = (buf.get(6) == LITTLE_ENDIAN_BIT); 350 msg.threadPoolToUse = 0; 353 msg10.message_type = buf.get(7); 354 msg10.message_size = readSize(buf.get(8), buf.get(9), buf.get(10), buf.get(11), 355 msg10.isLittleEndian()) + 356 GIOPMessageHeaderLength; 357 } else { Message_1_1 msg11 = (Message_1_1) msg; 359 msg11.magic = magic; 360 msg11.GIOP_version = new GIOPVersion(buf.get(4), buf.get(5)); 361 msg11.flags = (byte)(buf.get(6) & TRAILING_TWO_BIT_BYTE_MASK); 362 msg.threadPoolToUse = (buf.get(6) >>> 2) & THREAD_POOL_TO_USE_MASK; 372 msg11.message_type = buf.get(7); 373 msg11.message_size = 374 readSize(buf.get(8), buf.get(9), buf.get(10), buf.get(11), 375 msg11.isLittleEndian()) + GIOPMessageHeaderLength; 376 } 377 378 379 if (orb.giopDebugFlag) { 380 dprint(".readGIOPHeader: header construction complete."); 385 386 ByteBuffer viewBuf = buf.asReadOnlyBuffer(); 388 byte[] msgBuf = new byte[GIOPMessageHeaderLength]; 389 viewBuf.position(0).limit(GIOPMessageHeaderLength); 390 viewBuf.get(msgBuf,0,msgBuf.length); 391 ((MessageBase)msg).giopHeader = msgBuf; 393 } 394 395 msg.setByteBuffer(buf); 396 msg.setEncodingVersion(requestEncodingVersion); 397 398 return msg; 399 } 400 401 public static Message readGIOPBody(ORB orb, 402 CorbaConnection connection, 403 Message msg) 404 { 405 ReadTimeouts readTimeouts = 406 orb.getORBData().getTransportTCPReadTimeouts(); 407 ByteBuffer buf = msg.getByteBuffer(); 408 409 buf.position(MessageBase.GIOPMessageHeaderLength); 410 int msgSizeMinusHeader = 411 msg.getSize() - MessageBase.GIOPMessageHeaderLength; 412 try { 413 buf = connection.read(buf, 414 GIOPMessageHeaderLength, msgSizeMinusHeader, 415 readTimeouts.get_max_time_to_wait()); 416 } catch (IOException e) { 417 throw wrapper.ioexceptionWhenReadingConnection(e); 418 } 419 420 msg.setByteBuffer(buf); 421 422 if (orb.giopDebugFlag) { 423 dprint(".readGIOPBody: received message:"); 424 ByteBuffer viewBuffer = buf.asReadOnlyBuffer(); 425 viewBuffer.position(0).limit(msg.getSize()); 426 ByteBufferWithInfo bbwi = new ByteBufferWithInfo(orb, viewBuffer); 427 CDRInputStream_1_0.printBuffer(bbwi); 428 } 429 430 return msg; 431 } 432 433 private static RequestMessage createRequest( 434 ORB orb, GIOPVersion gv, byte encodingVersion, int request_id, 435 boolean response_expected, byte[] object_key, String operation, 436 ServiceContexts service_contexts, Principal requesting_principal) { 437 438 if (gv.equals(GIOPVersion.V1_0)) { return new RequestMessage_1_0(orb, service_contexts, request_id, 440 response_expected, object_key, 441 operation, requesting_principal); 442 } else if (gv.equals(GIOPVersion.V1_1)) { return new RequestMessage_1_1(orb, service_contexts, request_id, 444 response_expected, new byte[] { 0x00, 0x00, 0x00 }, 445 object_key, operation, requesting_principal); 446 } else if (gv.equals(GIOPVersion.V1_2)) { byte response_flags = 0x03; 451 if (response_expected) { 452 response_flags = 0x03; 453 } else { 454 response_flags = 0x00; 455 } 456 472 TargetAddress target = new TargetAddress(); 473 target.object_key(object_key); 474 RequestMessage msg = 475 new RequestMessage_1_2(orb, request_id, response_flags, 476 new byte[] { 0x00, 0x00, 0x00 }, 477 target, operation, service_contexts); 478 msg.setEncodingVersion(encodingVersion); 479 return msg; 480 } else { 481 throw wrapper.giopVersionError( 482 CompletionStatus.COMPLETED_MAYBE); 483 } 484 } 485 486 public static RequestMessage createRequest( 487 ORB orb, GIOPVersion gv, byte encodingVersion, int request_id, 488 boolean response_expected, IOR ior, 489 short addrDisp, String operation, 490 ServiceContexts service_contexts, Principal requesting_principal) { 491 492 RequestMessage requestMessage = null; 493 IIOPProfile profile = ior.getProfile(); 494 495 if (addrDisp == KeyAddr.value) { 496 profile = ior.getProfile(); 498 ObjectKey objKey = profile.getObjectKey(); 499 byte[] object_key = objKey.getBytes(orb); 500 requestMessage = 501 createRequest(orb, gv, encodingVersion, request_id, 502 response_expected, object_key, 503 operation, service_contexts, 504 requesting_principal); 505 } else { 506 507 if (!(gv.equals(GIOPVersion.V1_2))) { 508 throw wrapper.giopVersionError( 511 CompletionStatus.COMPLETED_MAYBE); 512 } 513 514 byte response_flags = 0x03; 518 if (response_expected) { 519 response_flags = 0x03; 520 } else { 521 response_flags = 0x00; 522 } 523 524 TargetAddress target = new TargetAddress(); 525 if (addrDisp == ProfileAddr.value) { profile = ior.getProfile(); 527 target.profile(profile.getIOPProfile()); 528 } else if (addrDisp == ReferenceAddr.value) { IORAddressingInfo iorInfo = 530 new IORAddressingInfo( 0, ior.getIOPIOR()); 532 target.ior(iorInfo); 533 } else { 534 throw wrapper.illegalTargetAddressDisposition( 536 CompletionStatus.COMPLETED_NO); 537 } 538 539 requestMessage = 540 new RequestMessage_1_2(orb, request_id, response_flags, 541 new byte[] { 0x00, 0x00, 0x00 }, target, 542 operation, service_contexts); 543 requestMessage.setEncodingVersion(encodingVersion); 544 } 545 546 if (gv.supportsIORIIOPProfileComponents()) { 547 int poolToUse = 0; IIOPProfileTemplate temp = 550 (IIOPProfileTemplate)profile.getTaggedProfileTemplate(); 551 Iterator iter = 552 temp.iteratorById(ORBConstants.TAG_REQUEST_PARTITIONING_ID); 553 if (iter.hasNext()) { 554 poolToUse = 555 ((RequestPartitioningComponent)iter.next()).getRequestPartitioningId(); 556 } 557 558 if (poolToUse < ORBConstants.REQUEST_PARTITIONING_MIN_THREAD_POOL_ID || 559 poolToUse > ORBConstants.REQUEST_PARTITIONING_MAX_THREAD_POOL_ID) { 560 throw wrapper.invalidRequestPartitioningId(new Integer (poolToUse), 561 new Integer (ORBConstants.REQUEST_PARTITIONING_MIN_THREAD_POOL_ID), 562 new Integer (ORBConstants.REQUEST_PARTITIONING_MAX_THREAD_POOL_ID)); 563 } 564 requestMessage.setThreadPoolToUse(poolToUse); 565 } 566 567 return requestMessage; 568 } 569 570 public static ReplyMessage createReply( 571 ORB orb, GIOPVersion gv, byte encodingVersion, int request_id, 572 int reply_status, ServiceContexts service_contexts, IOR ior) { 573 574 if (gv.equals(GIOPVersion.V1_0)) { return new ReplyMessage_1_0(orb, service_contexts, request_id, 576 reply_status, ior); 577 } else if (gv.equals(GIOPVersion.V1_1)) { return new ReplyMessage_1_1(orb, service_contexts, request_id, 579 reply_status, ior); 580 } else if (gv.equals(GIOPVersion.V1_2)) { ReplyMessage msg = 582 new ReplyMessage_1_2(orb, request_id, reply_status, 583 service_contexts, ior); 584 msg.setEncodingVersion(encodingVersion); 585 return msg; 586 } else { 587 throw wrapper.giopVersionError( 588 CompletionStatus.COMPLETED_MAYBE); 589 } 590 } 591 592 public static LocateRequestMessage createLocateRequest( 593 ORB orb, GIOPVersion gv, byte encodingVersion, 594 int request_id, byte[] object_key) { 595 596 if (gv.equals(GIOPVersion.V1_0)) { return new LocateRequestMessage_1_0(orb, request_id, object_key); 598 } else if (gv.equals(GIOPVersion.V1_1)) { return new LocateRequestMessage_1_1(orb, request_id, object_key); 600 } else if (gv.equals(GIOPVersion.V1_2)) { TargetAddress target = new TargetAddress(); 602 target.object_key(object_key); 603 LocateRequestMessage msg = 604 new LocateRequestMessage_1_2(orb, request_id, target); 605 msg.setEncodingVersion(encodingVersion); 606 return msg; 607 } else { 608 throw wrapper.giopVersionError( 609 CompletionStatus.COMPLETED_MAYBE); 610 } 611 } 612 613 public static LocateReplyMessage createLocateReply( 614 ORB orb, GIOPVersion gv, byte encodingVersion, 615 int request_id, int locate_status, IOR ior) { 616 617 if (gv.equals(GIOPVersion.V1_0)) { return new LocateReplyMessage_1_0(orb, request_id, 619 locate_status, ior); 620 } else if (gv.equals(GIOPVersion.V1_1)) { return new LocateReplyMessage_1_1(orb, request_id, 622 locate_status, ior); 623 } else if (gv.equals(GIOPVersion.V1_2)) { LocateReplyMessage msg = 625 new LocateReplyMessage_1_2(orb, request_id, 626 locate_status, ior); 627 msg.setEncodingVersion(encodingVersion); 628 return msg; 629 } else { 630 throw wrapper.giopVersionError( 631 CompletionStatus.COMPLETED_MAYBE); 632 } 633 } 634 635 public static CancelRequestMessage createCancelRequest( 636 GIOPVersion gv, int request_id) { 637 638 if (gv.equals(GIOPVersion.V1_0)) { return new CancelRequestMessage_1_0(request_id); 640 } else if (gv.equals(GIOPVersion.V1_1)) { return new CancelRequestMessage_1_1(request_id); 642 } else if (gv.equals(GIOPVersion.V1_2)) { return new CancelRequestMessage_1_2(request_id); 644 } else { 645 throw wrapper.giopVersionError( 646 CompletionStatus.COMPLETED_MAYBE); 647 } 648 } 649 650 public static Message createCloseConnection(GIOPVersion gv) { 651 if (gv.equals(GIOPVersion.V1_0)) { return new Message_1_0(Message.GIOPBigMagic, false, 653 Message.GIOPCloseConnection, 0); 654 } else if (gv.equals(GIOPVersion.V1_1)) { return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1, 656 FLAG_NO_FRAG_BIG_ENDIAN, 657 Message.GIOPCloseConnection, 0); 658 } else if (gv.equals(GIOPVersion.V1_2)) { return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2, 660 FLAG_NO_FRAG_BIG_ENDIAN, 661 Message.GIOPCloseConnection, 0); 662 } else { 663 throw wrapper.giopVersionError( 664 CompletionStatus.COMPLETED_MAYBE); 665 } 666 } 667 668 public static Message createMessageError(GIOPVersion gv) { 669 if (gv.equals(GIOPVersion.V1_0)) { return new Message_1_0(Message.GIOPBigMagic, false, 671 Message.GIOPMessageError, 0); 672 } else if (gv.equals(GIOPVersion.V1_1)) { return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1, 674 FLAG_NO_FRAG_BIG_ENDIAN, 675 Message.GIOPMessageError, 0); 676 } else if (gv.equals(GIOPVersion.V1_2)) { return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2, 678 FLAG_NO_FRAG_BIG_ENDIAN, 679 Message.GIOPMessageError, 0); 680 } else { 681 throw wrapper.giopVersionError( 682 CompletionStatus.COMPLETED_MAYBE); 683 } 684 } 685 686 public static FragmentMessage createFragmentMessage(GIOPVersion gv) { 687 return null; 692 } 693 694 public static int getRequestId(Message msg) { 695 switch (msg.getType()) { 696 case GIOPRequest : 697 return ((RequestMessage) msg).getRequestId(); 698 case GIOPReply : 699 return ((ReplyMessage) msg).getRequestId(); 700 case GIOPLocateRequest : 701 return ((LocateRequestMessage) msg).getRequestId(); 702 case GIOPLocateReply : 703 return ((LocateReplyMessage) msg).getRequestId(); 704 case GIOPCancelRequest : 705 return ((CancelRequestMessage) msg).getRequestId(); 706 case GIOPFragment : 707 return ((FragmentMessage) msg).getRequestId(); 708 } 709 710 throw wrapper.illegalGiopMsgType( 711 CompletionStatus.COMPLETED_MAYBE); 712 } 713 714 717 public static void setFlag(ByteBuffer byteBuffer, int flag) { 718 byte b = byteBuffer.get(6); 719 b |= flag; 720 byteBuffer.put(6,b); 721 } 722 723 726 public static void clearFlag(byte[] buf, int flag) { 727 buf[6] &= (0xFF ^ flag); 728 } 729 730 private static void AreFragmentsAllowed(byte major, byte minor, byte flag, 731 byte msgType) { 732 733 if ( (major == 0x01) && (minor == 0x00) ) { if (msgType == GIOPFragment) { 735 throw wrapper.fragmentationDisallowed( 736 CompletionStatus.COMPLETED_MAYBE); 737 } 738 } 739 740 if ( (flag & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT ) { 741 switch (msgType) { 742 case GIOPCancelRequest : 743 case GIOPCloseConnection : 744 case GIOPMessageError : 745 throw wrapper.fragmentationDisallowed( 746 CompletionStatus.COMPLETED_MAYBE); 747 case GIOPLocateRequest : 748 case GIOPLocateReply : 749 if ( (major == 0x01) && (minor == 0x01) ) { throw wrapper.fragmentationDisallowed( 751 CompletionStatus.COMPLETED_MAYBE); 752 } 753 break; 754 } 755 } 756 } 757 758 763 static ObjectKey extractObjectKey(byte[] objKey, ORB orb) { 764 765 try { 766 if (objKey != null) { 767 ObjectKey objectKey = 768 orb.getObjectKeyFactory().create(objKey); 769 if (objectKey != null) { 770 return objectKey; 771 } 772 } 773 } catch (Exception e) { 774 } 776 777 throw wrapper.invalidObjectKey(); 780 } 781 782 787 static ObjectKey extractObjectKey(TargetAddress target, ORB orb) { 788 789 short orbTargetAddrPref = orb.getORBData().getGIOPTargetAddressPreference(); 790 short reqAddrDisp = target.discriminator(); 791 792 switch (orbTargetAddrPref) { 793 case ORBConstants.ADDR_DISP_OBJKEY : 794 if (reqAddrDisp != KeyAddr.value) { 795 throw new AddressingDispositionException(KeyAddr.value); 796 } 797 break; 798 case ORBConstants.ADDR_DISP_PROFILE : 799 if (reqAddrDisp != ProfileAddr.value) { 800 throw new AddressingDispositionException(ProfileAddr.value); 801 } 802 break; 803 case ORBConstants.ADDR_DISP_IOR : 804 if (reqAddrDisp != ReferenceAddr.value) { 805 throw new AddressingDispositionException(ReferenceAddr.value); 806 } 807 break; 808 case ORBConstants.ADDR_DISP_HANDLE_ALL : 809 break; 810 default : 811 throw wrapper.orbTargetAddrPreferenceInExtractObjectkeyInvalid() ; 812 } 813 814 try { 815 switch (reqAddrDisp) { 816 case KeyAddr.value : 817 byte[] objKey = target.object_key(); 818 if (objKey != null) { ObjectKey objectKey = 820 orb.getObjectKeyFactory().create(objKey); 821 if (objectKey != null) { 822 return objectKey; 823 } 824 } 825 break; 826 case ProfileAddr.value : 827 IIOPProfile iiopProfile = null; 828 TaggedProfile profile = target.profile(); 829 if (profile != null) { iiopProfile = IIOPFactories.makeIIOPProfile(orb, profile); 831 ObjectKey objectKey = iiopProfile.getObjectKey(); 832 if (objectKey != null) { 833 return objectKey; 834 } 835 } 836 break; 837 case ReferenceAddr.value : 838 IORAddressingInfo iorInfo = target.ior(); 839 if (iorInfo != null) { profile = iorInfo.ior.profiles[iorInfo.selected_profile_index]; 841 iiopProfile = IIOPFactories.makeIIOPProfile(orb, profile); 842 ObjectKey objectKey = iiopProfile.getObjectKey(); 843 if (objectKey != null) { 844 return objectKey; 845 } 846 } 847 break; 848 default : break; 853 } 854 } catch (Exception e) {} 855 856 throw wrapper.invalidObjectKey() ; 860 } 861 862 private static int readSize(byte b1, byte b2, byte b3, byte b4, 863 boolean littleEndian) { 864 865 int a1, a2, a3, a4; 866 867 if (!littleEndian) { 868 a1 = (b1 << 24) & 0xFF000000; 869 a2 = (b2 << 16) & 0x00FF0000; 870 a3 = (b3 << 8) & 0x0000FF00; 871 a4 = (b4 << 0) & 0x000000FF; 872 } else { 873 a1 = (b4 << 24) & 0xFF000000; 874 a2 = (b3 << 16) & 0x00FF0000; 875 a3 = (b2 << 8) & 0x0000FF00; 876 a4 = (b1 << 0) & 0x000000FF; 877 } 878 879 return (a1 | a2 | a3 | a4); 880 } 881 882 static void nullCheck(Object obj) { 883 if (obj == null) { 884 throw wrapper.nullNotAllowed() ; 885 } 886 } 887 888 static SystemException getSystemException( 889 String exClassName, int minorCode, CompletionStatus completionStatus, 890 String message, ORBUtilSystemException wrapper) 891 { 892 SystemException sysEx = null; 893 894 try { 895 Class clazz = ORBClassLoader.loadClass(exClassName); 896 if (message == null) { 897 sysEx = (SystemException ) clazz.newInstance(); 898 } else { 899 Class [] types = { String .class }; 900 Constructor constructor = clazz.getConstructor(types); 901 Object [] args = { message }; 902 sysEx = (SystemException )constructor.newInstance(args); 903 } 904 } catch (Exception someEx) { 905 throw wrapper.badSystemExceptionInReply( 906 CompletionStatus.COMPLETED_MAYBE, someEx ); 907 } 908 909 sysEx.minor = minorCode; 910 sysEx.completed = completionStatus; 911 912 return sysEx; 913 } 914 915 public void callback(MessageHandler handler) 916 throws java.io.IOException 917 { 918 handler.handleInput(this); 919 } 920 921 public ByteBuffer getByteBuffer() 922 { 923 return byteBuffer; 924 } 925 926 public void setByteBuffer(ByteBuffer byteBuffer) 927 { 928 this.byteBuffer = byteBuffer; 929 } 930 931 public int getThreadPoolToUse() 932 { 933 return threadPoolToUse; 934 } 935 936 public byte getEncodingVersion() { 937 return this.encodingVersion; 938 } 939 940 public void setEncodingVersion(byte version) { 941 this.encodingVersion = version; 942 } 943 944 private static void dprint(String msg) 945 { 946 ORBUtility.dprint("MessageBase", msg); 947 } 948 } 949 | Popular Tags |