1. /*
  2. * @(#)RequestMessage_1_2.java 1.18 04/06/21
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.protocol.giopmsgheaders;
  8. import org.omg.CORBA.Principal;
  9. import com.sun.corba.se.spi.servicecontext.ServiceContexts;
  10. import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  11. import com.sun.corba.se.spi.orb.ORB;
  12. import com.sun.corba.se.spi.ior.ObjectKey;
  13. import com.sun.corba.se.impl.encoding.CDRInputStream;
  14. import com.sun.corba.se.impl.encoding.CDROutputStream;
  15. import com.sun.corba.se.impl.orbutil.ORBConstants;
  16. import com.sun.corba.se.impl.encoding.CDRInputStream_1_2;
  17. import com.sun.corba.se.impl.encoding.CDROutputStream_1_2;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  19. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  20. /**
  21. * This implements the GIOP 1.2 Request header.
  22. *
  23. * @author Ram Jeyaraman 05/14/2000
  24. * @version 1.0
  25. */
  26. public final class RequestMessage_1_2 extends Message_1_2
  27. implements RequestMessage {
  28. // Instance variables
  29. private ORB orb = null;
  30. private ORBUtilSystemException wrapper = null ;
  31. private byte response_flags = (byte) 0;
  32. private byte reserved[] = null;
  33. private TargetAddress target = null;
  34. private String operation = null;
  35. private ServiceContexts service_contexts = null;
  36. private ObjectKey objectKey = null;
  37. // Constructors
  38. RequestMessage_1_2(ORB orb) {
  39. this.orb = orb;
  40. this.wrapper = ORBUtilSystemException.get( orb,
  41. CORBALogDomains.RPC_PROTOCOL ) ;
  42. }
  43. RequestMessage_1_2(ORB orb, int _request_id, byte _response_flags,
  44. byte[] _reserved, TargetAddress _target,
  45. String _operation, ServiceContexts _service_contexts) {
  46. super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
  47. Message.GIOPRequest, 0);
  48. this.orb = orb;
  49. this.wrapper = ORBUtilSystemException.get( orb,
  50. CORBALogDomains.RPC_PROTOCOL ) ;
  51. request_id = _request_id;
  52. response_flags = _response_flags;
  53. reserved = _reserved;
  54. target = _target;
  55. operation = _operation;
  56. service_contexts = _service_contexts;
  57. }
  58. // Accessor methods (RequestMessage interface)
  59. public int getRequestId() {
  60. return this.request_id;
  61. }
  62. public boolean isResponseExpected() {
  63. /*
  64. case 1: LSBit[1] == 1
  65. not a oneway call (DII flag INV_NO_RESPONSE is false) // Ox03
  66. LSBit[0] must be 1.
  67. case 2: LSBit[1] == 0
  68. if (LSB[0] == 0) // Ox00
  69. oneway call
  70. else if (LSB[0] == 1) // 0x01
  71. oneway call; but server may provide
  72. a location forward response or system exception response.
  73. */
  74. if ( (this.response_flags & RESPONSE_EXPECTED_BIT) == RESPONSE_EXPECTED_BIT ) {
  75. return true;
  76. }
  77. return false;
  78. }
  79. public byte[] getReserved() {
  80. return this.reserved;
  81. }
  82. public ObjectKey getObjectKey() {
  83. if (this.objectKey == null) {
  84. // this will raise a MARSHAL exception upon errors.
  85. this.objectKey = MessageBase.extractObjectKey(target, orb);
  86. }
  87. return this.objectKey;
  88. }
  89. public String getOperation() {
  90. return this.operation;
  91. }
  92. public Principal getPrincipal() {
  93. // REVISIT Should we throw an exception or return null ?
  94. return null;
  95. }
  96. public ServiceContexts getServiceContexts() {
  97. return this.service_contexts;
  98. }
  99. // IO methods
  100. public void read(org.omg.CORBA.portable.InputStream istream) {
  101. super.read(istream);
  102. this.request_id = istream.read_ulong();
  103. this.response_flags = istream.read_octet();
  104. this.reserved = new byte[3];
  105. for (int _o0 = 0;_o0 < (3); ++_o0) {
  106. this.reserved[_o0] = istream.read_octet();
  107. }
  108. this.target = TargetAddressHelper.read(istream);
  109. getObjectKey(); // this does AddressingDisposition check
  110. this.operation = istream.read_string();
  111. this.service_contexts
  112. = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
  113. // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
  114. // aligned on an 8 octet boundary.
  115. // Ensures that the first read operation called from the stub code,
  116. // during body deconstruction, would skip the header padding, that was
  117. // inserted to ensure that the body was aligned on an 8-octet boundary.
  118. ((CDRInputStream)istream).setHeaderPadding(true);
  119. }
  120. public void write(org.omg.CORBA.portable.OutputStream ostream) {
  121. super.write(ostream);
  122. ostream.write_ulong(this.request_id);
  123. ostream.write_octet(this.response_flags);
  124. nullCheck(this.reserved);
  125. if (this.reserved.length != (3)) {
  126. throw wrapper.badReservedLength(
  127. org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
  128. }
  129. for (int _i0 = 0;_i0 < (3); ++_i0) {
  130. ostream.write_octet(this.reserved[_i0]);
  131. }
  132. nullCheck(this.target);
  133. TargetAddressHelper.write(ostream, this.target);
  134. ostream.write_string(this.operation);
  135. if (this.service_contexts != null) {
  136. service_contexts.write(
  137. (org.omg.CORBA_2_3.portable.OutputStream) ostream,
  138. GIOPVersion.V1_2);
  139. } else {
  140. ServiceContexts.writeNullServiceContext(
  141. (org.omg.CORBA_2_3.portable.OutputStream) ostream);
  142. }
  143. // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
  144. // aligned on an 8 octet boundary.
  145. // Ensures that the first write operation called from the stub code,
  146. // during body construction, would insert a header padding, such that
  147. // the body is aligned on an 8-octet boundary.
  148. ((CDROutputStream)ostream).setHeaderPadding(true);
  149. }
  150. public void callback(MessageHandler handler)
  151. throws java.io.IOException
  152. {
  153. handler.handleInput(this);
  154. }
  155. } // class RequestMessage_1_2